From 6e71ae58170b8ca9cea7caa0ec92edf2ffab1235 Mon Sep 17 00:00:00 2001 From: ramidzkh Date: Sun, 5 Nov 2023 22:34:00 +1100 Subject: [PATCH] Make ChemicalIngredientConverter check the ingredient class (#48) --- .../ae2/GenericStackChemicalStorage.java | 2 +- .../stack/MekanismStackExportStrategy.java | 1 - .../mekae2/integration/jei/AMJEIPlugin.java | 1 - .../jei}/ChemicalIngredientConverter.java | 5 +- .../me/ramidzkh/mekae2/qio/QioSupport.java | 60 +++++++++---------- .../ramidzkh/mekae2/util/ChemicalBridge.java | 4 +- 6 files changed, 35 insertions(+), 38 deletions(-) rename src/main/java/me/ramidzkh/mekae2/{ae2 => integration/jei}/ChemicalIngredientConverter.java (83%) diff --git a/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java b/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java index fb4e36f..ea9cf60 100644 --- a/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java +++ b/src/main/java/me/ramidzkh/mekae2/ae2/GenericStackChemicalStorage.java @@ -83,7 +83,7 @@ public S insertChemical(int tank, S stack, Action action) { @Override public S extractChemical(int tank, long amount, Action action) { - if (!(inv.getKey(tank) instanceof MekanismKey what) || what.getForm() != form) { + if (!(inv.getKey(tank) instanceof MekanismKey what && what.getForm() == form)) { return getEmptyStack(); } diff --git a/src/main/java/me/ramidzkh/mekae2/ae2/stack/MekanismStackExportStrategy.java b/src/main/java/me/ramidzkh/mekae2/ae2/stack/MekanismStackExportStrategy.java index 01190bf..c45e757 100644 --- a/src/main/java/me/ramidzkh/mekae2/ae2/stack/MekanismStackExportStrategy.java +++ b/src/main/java/me/ramidzkh/mekae2/ae2/stack/MekanismStackExportStrategy.java @@ -99,6 +99,5 @@ public long push(AEKey what, long amount, Actionable mode) { return amount - storage.insertChemical(mekanismKey.withAmount(amount), Action.fromFluidAction(mode.getFluidAction())).getAmount(); - } } diff --git a/src/main/java/me/ramidzkh/mekae2/integration/jei/AMJEIPlugin.java b/src/main/java/me/ramidzkh/mekae2/integration/jei/AMJEIPlugin.java index 69b3675..966b805 100644 --- a/src/main/java/me/ramidzkh/mekae2/integration/jei/AMJEIPlugin.java +++ b/src/main/java/me/ramidzkh/mekae2/integration/jei/AMJEIPlugin.java @@ -3,7 +3,6 @@ import net.minecraft.resources.ResourceLocation; import me.ramidzkh.mekae2.AppliedMekanistics; -import me.ramidzkh.mekae2.ae2.ChemicalIngredientConverter; import mekanism.api.IMekanismAccess; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; diff --git a/src/main/java/me/ramidzkh/mekae2/ae2/ChemicalIngredientConverter.java b/src/main/java/me/ramidzkh/mekae2/integration/jei/ChemicalIngredientConverter.java similarity index 83% rename from src/main/java/me/ramidzkh/mekae2/ae2/ChemicalIngredientConverter.java rename to src/main/java/me/ramidzkh/mekae2/integration/jei/ChemicalIngredientConverter.java index 51e11b9..661c8a0 100644 --- a/src/main/java/me/ramidzkh/mekae2/ae2/ChemicalIngredientConverter.java +++ b/src/main/java/me/ramidzkh/mekae2/integration/jei/ChemicalIngredientConverter.java @@ -1,7 +1,8 @@ -package me.ramidzkh.mekae2.ae2; +package me.ramidzkh.mekae2.integration.jei; import org.jetbrains.annotations.Nullable; +import me.ramidzkh.mekae2.ae2.MekanismKey; import mekanism.api.chemical.ChemicalStack; import mezz.jei.api.ingredients.IIngredientType; @@ -20,7 +21,7 @@ public IIngredientType getIngredientType() { @Nullable @Override public S getIngredientFromStack(GenericStack stack) { - if (stack.what() instanceof MekanismKey key) { + if (stack.what() instanceof MekanismKey key && type.getIngredientClass().isInstance(key.getStack())) { return (S) key.withAmount(Math.max(1, stack.amount())); } else { return null; diff --git a/src/main/java/me/ramidzkh/mekae2/qio/QioSupport.java b/src/main/java/me/ramidzkh/mekae2/qio/QioSupport.java index 9137985..0fa8f43 100644 --- a/src/main/java/me/ramidzkh/mekae2/qio/QioSupport.java +++ b/src/main/java/me/ramidzkh/mekae2/qio/QioSupport.java @@ -34,45 +34,43 @@ public static void initialize() { public static void onBlockEntityCapability(AttachCapabilitiesEvent event) { var object = event.getObject(); - if (object instanceof IQIOComponent) { - if (DASHBOARD.equals(ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(object.getType()))) { - event.addCapability(AppliedMekanistics.id("qio_storage_monitorable"), new ICapabilityProvider() { - @NotNull - @Override - public LazyOptional getCapability(@NotNull Capability capability, - @Nullable Direction arg) { - out: if (capability == STORAGE && arg != null) { - // guess the source... - // if you're trying to qio across a compact machine wall or something, sorry! - var host = GridHelper.getNodeHost(object.getLevel(), object.getBlockPos().relative(arg)); + if (object instanceof IQIOComponent + && DASHBOARD.equals(ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(object.getType()))) { + event.addCapability(AppliedMekanistics.id("qio_storage_monitorable"), new ICapabilityProvider() { + @NotNull + @Override + public LazyOptional getCapability(@NotNull Capability capability, @Nullable Direction arg) { + out: if (capability == STORAGE && arg != null) { + // guess the source... + // if you're trying to qio across a compact machine wall or something, sorry! + var host = GridHelper.getNodeHost(object.getLevel(), object.getBlockPos().relative(arg)); - if (host == null) { - break out; - } + if (host == null) { + break out; + } - var source = host.getGridNode(arg.getOpposite()); + var source = host.getGridNode(arg.getOpposite()); - // I don't know of any full-block nodes which query inventories, but we'll see - if (source == null) { - source = host.getGridNode(null); - } + // I don't know of any full-block nodes which query inventories, but we'll see + if (source == null) { + source = host.getGridNode(null); + } - if (source == null) { - break out; - } + if (source == null) { + break out; + } - var adapter = new QioStorageAdapter<>((BlockEntity & IQIOComponent) object, arg, - source.getOwningPlayerProfileId()); + var adapter = new QioStorageAdapter<>((BlockEntity & IQIOComponent) object, arg, + source.getOwningPlayerProfileId()); - if (adapter.getFrequency() != null) { - return LazyOptional.of(() -> adapter).cast(); - } + if (adapter.getFrequency() != null) { + return LazyOptional.of(() -> adapter).cast(); } - - return LazyOptional.empty(); } - }); - } + + return LazyOptional.empty(); + } + }); } } } diff --git a/src/main/java/me/ramidzkh/mekae2/util/ChemicalBridge.java b/src/main/java/me/ramidzkh/mekae2/util/ChemicalBridge.java index c198822..1c85482 100644 --- a/src/main/java/me/ramidzkh/mekae2/util/ChemicalBridge.java +++ b/src/main/java/me/ramidzkh/mekae2/util/ChemicalBridge.java @@ -5,8 +5,8 @@ public interface ChemicalBridge { static > S withAmount(S stack, long amount) { - var copy = stack.copy(); + var copy = (S) stack.copy(); copy.setAmount(amount); - return (S) copy; + return copy; } }