aboutsummaryrefslogtreecommitdiff
path: root/fabric/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2024-03-03 21:05:37 +0900
committershedaniel <daniel@shedaniel.me>2024-03-03 21:05:37 +0900
commitaebe0f1c05e5b8240b5136f3ab4f1e4a84039d96 (patch)
tree3547eeeb7add6c6c7160bd4a91cb049b19ca3e97 /fabric/src/main/java
parent52a6bf840ed665a2086ed37bbe0f99907d160350 (diff)
downloadRoughlyEnoughItems-aebe0f1c05e5b8240b5136f3ab4f1e4a84039d96.tar.gz
RoughlyEnoughItems-aebe0f1c05e5b8240b5136f3ab4f1e4a84039d96.tar.bz2
RoughlyEnoughItems-aebe0f1c05e5b8240b5136f3ab4f1e4a84039d96.zip
Update to Fabric Transfer API
Diffstat (limited to 'fabric/src/main/java')
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java2
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java61
2 files changed, 62 insertions, 1 deletions
diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
index 8f694ebbb..3561c9da5 100644
--- a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
+++ b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
@@ -127,7 +127,7 @@ public class PluginDetectorImpl implements PluginDetector {
public void detectServerPlugins() {
loadPlugin(REIServerPlugin.class, ((PluginView<REIServerPlugin>) PluginManager.getServerInstance())::registerPlugin);
try {
- // TODO 24w09a: PluginView.getServerInstance().registerPlugin((REIServerPlugin) Class.forName("me.shedaniel.rei.impl.common.compat.FabricFluidAPISupportPlugin").getConstructor().newInstance());
+ PluginView.getServerInstance().registerPlugin((REIServerPlugin) Class.forName("me.shedaniel.rei.impl.common.compat.FabricFluidAPISupportPlugin").getConstructor().newInstance());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java b/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java
new file mode 100644
index 000000000..4fbd24e27
--- /dev/null
+++ b/fabric/src/main/java/me/shedaniel/rei/impl/common/compat/FabricFluidAPISupportPlugin.java
@@ -0,0 +1,61 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.common.compat;
+
+import dev.architectury.event.CompoundEventResult;
+import dev.architectury.fluid.FluidStack;
+import dev.architectury.hooks.fluid.fabric.FluidStackHooksFabric;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.fluid.FluidSupportProvider;
+import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
+import me.shedaniel.rei.api.common.util.EntryStacks;
+import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
+import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
+import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
+import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
+import net.minecraft.world.item.ItemStack;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+public class FabricFluidAPISupportPlugin implements REIServerPlugin {
+ @Override
+ public void registerFluidSupport(FluidSupportProvider support) {
+ support.register(entry -> {
+ ItemStack stack = entry.getValue().copy();
+ Storage<FluidVariant> storage = FluidStorage.ITEM.find(stack, ContainerItemContext.withConstant(stack));
+ if (storage != null) {
+ List<EntryStack<FluidStack>> result = StreamSupport.stream(storage.spliterator(), false)
+ .filter(view -> !view.isResourceBlank())
+ .map(view -> EntryStacks.of(FluidStackHooksFabric.fromFabric(view.getResource(), view.getAmount())))
+ .collect(Collectors.toList());
+ if (!result.isEmpty()) {
+ return CompoundEventResult.interruptTrue(result.stream());
+ }
+ }
+ return CompoundEventResult.pass();
+ });
+ }
+}