From 5d700650bf3452f066768794363ece9c257dd02e Mon Sep 17 00:00:00 2001 From: NotMyWing Date: Fri, 24 May 2024 18:18:34 +1100 Subject: [PATCH] Generalize Encoded Pattern transformers Fixes transformations done by Programming Circuit Card (and future cards) not being saved --- .../java/co/neeve/nae2/NAE2MixinPlugin.java | 3 + .../patterntransform/PatternTransform.java | 36 ++++++ .../PatternTransformWrapper.java | 118 ++++++++++++++++++ .../GregTechCircuitPatternTransformer.java | 57 +++++++++ .../transformers/IPatternTransformer.java | 19 +++ .../GregCircuitCraftingDetailsWrapper.java | 56 --------- .../registration/definitions/Upgrades.java | 4 + .../MixinCraftingCPUCluster.java | 118 ++++++++++++++++++ .../patterntransform/MixinCraftingGrid.java | 24 ++++ .../gregcircuit/MixinDualityInterface.java | 39 +++--- src/main/resources/mixins.nae2.json | 5 +- 11 files changed, 399 insertions(+), 80 deletions(-) create mode 100644 src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransform.java create mode 100644 src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransformWrapper.java create mode 100644 src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/GregTechCircuitPatternTransformer.java create mode 100644 src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/IPatternTransformer.java delete mode 100644 src/main/java/co/neeve/nae2/common/helpers/GregCircuitCraftingDetailsWrapper.java create mode 100644 src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingCPUCluster.java create mode 100644 src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingGrid.java diff --git a/src/main/java/co/neeve/nae2/NAE2MixinPlugin.java b/src/main/java/co/neeve/nae2/NAE2MixinPlugin.java index be2ec0c..c18a005 100644 --- a/src/main/java/co/neeve/nae2/NAE2MixinPlugin.java +++ b/src/main/java/co/neeve/nae2/NAE2MixinPlugin.java @@ -51,6 +51,9 @@ public List getMixinConfigs() { var mixins = new ArrayList(); + // Core. + mixins.add("mixins.nae2.json"); + for (var feature : Features.values()) { if (!feature.isEnabled()) continue; diff --git a/src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransform.java b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransform.java new file mode 100644 index 0000000..7c351ee --- /dev/null +++ b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransform.java @@ -0,0 +1,36 @@ +package co.neeve.nae2.common.crafting.patterntransform; + +import appeng.api.networking.crafting.ICraftingMedium; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import co.neeve.nae2.common.crafting.patterntransform.transformers.IPatternTransformer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class PatternTransform { + protected final static List transformers = new ArrayList<>(); + + public static void registerTransformer(IPatternTransformer transformer) { + transformers.add(transformer); + } + + public static ICraftingPatternDetails transform(ICraftingMedium medium, ICraftingPatternDetails pattern) { + final var originalInputs = pattern.getInputs(); + final var originalOutputs = pattern.getOutputs(); + var inputs = originalInputs; + var outputs = originalOutputs; + + for (var transformer : transformers) { + if (!transformer.shouldTransform(medium, pattern)) continue; + + inputs = transformer.transformInputs(medium, pattern, inputs); + outputs = transformer.transformOutputs(medium, pattern, outputs); + } + + if (!Arrays.equals(inputs, originalInputs) || !Arrays.equals(outputs, originalOutputs)) { + return new PatternTransformWrapper(pattern, inputs, outputs); + } + return pattern; + } +} diff --git a/src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransformWrapper.java b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransformWrapper.java new file mode 100644 index 0000000..9bf61cd --- /dev/null +++ b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransformWrapper.java @@ -0,0 +1,118 @@ +package co.neeve.nae2.common.crafting.patterntransform; + +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.data.IAEItemStack; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; + +public class PatternTransformWrapper implements ICraftingPatternDetails { + private final IAEItemStack[] condensedInputs; + private final IAEItemStack[] condensedOutputs; + private final ICraftingPatternDetails delegate; + private final IAEItemStack[] inputs; + private final IAEItemStack[] outputs; + + public PatternTransformWrapper(ICraftingPatternDetails delegate, IAEItemStack[] inputs, IAEItemStack[] outputs) { + this.delegate = delegate; + this.inputs = inputs; + this.outputs = outputs; + + this.condensedInputs = new IAEItemStack[inputs.length]; + var offset = 0; + + IAEItemStack io; + Iterator iterator; + for (iterator = Arrays.stream(inputs).iterator(); iterator.hasNext(); ++offset) { + io = iterator.next(); + this.condensedInputs[offset] = io; + } + + offset = 0; + this.condensedOutputs = new IAEItemStack[outputs.length]; + + for (iterator = Arrays.stream(outputs).iterator(); iterator.hasNext(); ++offset) { + io = iterator.next(); + this.condensedOutputs[offset] = io; + } + } + + @Override + public ItemStack getPattern() {return this.delegate.getPattern();} + + @Override + public boolean isValidItemForSlot(int i, ItemStack itemStack, World world) { + return this.delegate.isValidItemForSlot(i, + itemStack, + world); + } + + @Override + public boolean isCraftable() {return this.delegate.isCraftable();} + + @Override + public boolean canSubstitute() {return this.delegate.canSubstitute();} + + @Override + public List getSubstituteInputs(int slot) {return this.delegate.getSubstituteInputs(slot);} + + @Override + public ItemStack getOutput(InventoryCrafting inventoryCrafting, World world) { + return this.delegate.getOutput(inventoryCrafting, + world); + } + + @Override + public int getPriority() {return this.delegate.getPriority();} + + @Override + public void setPriority(int i) {this.delegate.setPriority(i);} + + @Override + public IAEItemStack[] getCondensedInputs() { + return this.condensedInputs; + } + + @Override + public IAEItemStack[] getInputs() { + return this.inputs; + } + + @Override + public IAEItemStack[] getCondensedOutputs() { + return this.condensedOutputs; + } + + @Override + public IAEItemStack[] getOutputs() { + return this.outputs; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof PatternTransformWrapper that)) return false; + return Arrays.equals(this.condensedInputs, that.condensedInputs) && Arrays.equals(this.condensedOutputs, + that.condensedOutputs) && Objects.equals(this.delegate, that.delegate) && Arrays.equals(this.inputs, + that.inputs) && Arrays.equals(this.outputs, that.outputs); + } + + @Override + public int hashCode() { + var result = Objects.hash(this.delegate); + result = 31 * result + Arrays.hashCode(this.condensedInputs); + result = 31 * result + Arrays.hashCode(this.condensedOutputs); + result = 31 * result + Arrays.hashCode(this.inputs); + result = 31 * result + Arrays.hashCode(this.outputs); + return result; + } + + public ICraftingPatternDetails getDelegate() { + return this.delegate; + } +} diff --git a/src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/GregTechCircuitPatternTransformer.java b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/GregTechCircuitPatternTransformer.java new file mode 100644 index 0000000..19d1cbc --- /dev/null +++ b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/GregTechCircuitPatternTransformer.java @@ -0,0 +1,57 @@ +package co.neeve.nae2.common.crafting.patterntransform.transformers; + +import appeng.api.implementations.IUpgradeableHost; +import appeng.api.networking.crafting.ICraftingMedium; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.data.IAEItemStack; +import co.neeve.nae2.common.interfaces.IExtendedUpgradeInventory; +import co.neeve.nae2.common.registration.definitions.Upgrades; +import gregtech.api.recipes.ingredients.IntCircuitIngredient; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.Objects; +import java.util.Optional; + +public class GregTechCircuitPatternTransformer implements IPatternTransformer { + public static Optional getCircuitValueFromDetails(ICraftingPatternDetails details) { + var optCircuit = Arrays.stream(details.getInputs()) + .filter(Objects::nonNull) + .filter(ais -> IntCircuitIngredient.isIntegratedCircuit(ais.createItemStack())) + .findFirst(); + + if (!optCircuit.isPresent()) return Optional.empty(); + + var circuit = optCircuit.get(); + var config = IntCircuitIngredient.getCircuitConfiguration(circuit.createItemStack()); + return Optional.of(config); + } + + @NotNull + protected static IAEItemStack[] filterCircuitsOut(IAEItemStack[] inputs) { + if (inputs == null) return null; + + return Arrays.stream(inputs) + .filter(Objects::nonNull) + .filter(x -> !IntCircuitIngredient.isIntegratedCircuit(x.createItemStack())) + .toArray(IAEItemStack[]::new); + } + + @Override + public boolean shouldTransform(ICraftingMedium medium, ICraftingPatternDetails details) { + if (details.isCraftable()) return false; + + var optCircuit = getCircuitValueFromDetails(details); + if (!optCircuit.isPresent()) return false; + + return medium instanceof IUpgradeableHost upgradeableHost + && upgradeableHost.getInventoryByName("upgrades") instanceof IExtendedUpgradeInventory naeUpgrades + && naeUpgrades.getInstalledUpgrades(Upgrades.UpgradeType.GREGTECH_CIRCUIT) > 0; + } + + @Override + public IAEItemStack[] transformInputs(ICraftingMedium medium, ICraftingPatternDetails details, + IAEItemStack[] inputs) { + return filterCircuitsOut(inputs); + } +} diff --git a/src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/IPatternTransformer.java b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/IPatternTransformer.java new file mode 100644 index 0000000..9b024eb --- /dev/null +++ b/src/main/java/co/neeve/nae2/common/crafting/patterntransform/transformers/IPatternTransformer.java @@ -0,0 +1,19 @@ +package co.neeve.nae2.common.crafting.patterntransform.transformers; + +import appeng.api.networking.crafting.ICraftingMedium; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.data.IAEItemStack; + +public interface IPatternTransformer { + default IAEItemStack[] transformInputs(ICraftingMedium medium, ICraftingPatternDetails details, + IAEItemStack[] inputs) { + return inputs; + } + + default IAEItemStack[] transformOutputs(ICraftingMedium medium, ICraftingPatternDetails details, + IAEItemStack[] outputs) { + return outputs; + } + + boolean shouldTransform(ICraftingMedium medium, ICraftingPatternDetails details); +} diff --git a/src/main/java/co/neeve/nae2/common/helpers/GregCircuitCraftingDetailsWrapper.java b/src/main/java/co/neeve/nae2/common/helpers/GregCircuitCraftingDetailsWrapper.java deleted file mode 100644 index 02b1cb1..0000000 --- a/src/main/java/co/neeve/nae2/common/helpers/GregCircuitCraftingDetailsWrapper.java +++ /dev/null @@ -1,56 +0,0 @@ -package co.neeve.nae2.common.helpers; - -import appeng.api.networking.crafting.ICraftingPatternDetails; -import appeng.api.storage.data.IAEItemStack; -import gregtech.api.recipes.ingredients.IntCircuitIngredient; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Objects; - -public class GregCircuitCraftingDetailsWrapper extends CraftingDetailsWrapper { - protected final int config; - protected IAEItemStack[] oldInputs; - protected IAEItemStack[] oldCondInputs; - protected IAEItemStack[] cachedInputs; - protected IAEItemStack[] cachecCondInputs; - - public GregCircuitCraftingDetailsWrapper(ICraftingPatternDetails delegate, int config) { - super(delegate); - this.config = config; - } - - @NotNull - protected static IAEItemStack[] filterCircuitsOut(IAEItemStack[] inputs) { - if (inputs == null) return null; - - return Arrays.stream(inputs) - .filter(Objects::nonNull) - .filter(x -> !IntCircuitIngredient.isIntegratedCircuit(x.createItemStack())) - .toArray(IAEItemStack[]::new); - } - - public int getConfig() { - return this.config; - } - - @Override - public IAEItemStack[] getInputs() { - var inputs = super.getInputs(); - if (inputs != this.oldInputs) { - this.oldInputs = inputs; - this.cachedInputs = filterCircuitsOut(inputs); - } - return this.cachedInputs; - } - - @Override - public IAEItemStack[] getCondensedInputs() { - var inputs = super.getCondensedInputs(); - if (inputs != this.oldCondInputs) { - this.oldCondInputs = inputs; - this.cachecCondInputs = filterCircuitsOut(inputs); - } - return this.cachecCondInputs; - } -} diff --git a/src/main/java/co/neeve/nae2/common/registration/definitions/Upgrades.java b/src/main/java/co/neeve/nae2/common/registration/definitions/Upgrades.java index d4ad160..7beb4b1 100644 --- a/src/main/java/co/neeve/nae2/common/registration/definitions/Upgrades.java +++ b/src/main/java/co/neeve/nae2/common/registration/definitions/Upgrades.java @@ -8,6 +8,8 @@ import appeng.core.features.DamagedItemDefinition; import appeng.core.features.IStackSrc; import co.neeve.nae2.Tags; +import co.neeve.nae2.common.crafting.patterntransform.PatternTransform; +import co.neeve.nae2.common.crafting.patterntransform.transformers.GregTechCircuitPatternTransformer; import co.neeve.nae2.common.features.IFeature; import co.neeve.nae2.common.features.subfeatures.UpgradeFeatures; import co.neeve.nae2.common.items.NAEBaseItemUpgrade; @@ -68,6 +70,8 @@ public Upgrades(Registry registry) { this.gregtechCircuit = this.createUpgrade(this.upgrade, UpgradeType.GREGTECH_CIRCUIT); if (this.gregtechCircuit.isEnabled()) { + PatternTransform.registerTransformer(new GregTechCircuitPatternTransformer()); + registry.addBootstrapComponent((IPostInitComponent) r -> { var definitions = Api.INSTANCE.definitions(); final IBlocks blocks = definitions.blocks(); diff --git a/src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingCPUCluster.java b/src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingCPUCluster.java new file mode 100644 index 0000000..f4a5a27 --- /dev/null +++ b/src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingCPUCluster.java @@ -0,0 +1,118 @@ +package co.neeve.nae2.mixin.crafting.patterntransform; + +import appeng.api.networking.crafting.ICraftingMedium; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.storage.data.IAEItemStack; +import appeng.me.cluster.implementations.CraftingCPUCluster; +import appeng.util.item.AEItemStack; +import co.neeve.nae2.common.crafting.patterntransform.PatternTransformWrapper; +import com.google.common.collect.ImmutableMap; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.ArrayList; +import java.util.Map; + +@Mixin(value = CraftingCPUCluster.class, remap = false) +public class MixinCraftingCPUCluster { + @WrapOperation( + method = "executeCrafting", at = @At( + value = "INVOKE", + target = "Lappeng/api/networking/crafting/ICraftingMedium;pushPattern" + + "(Lappeng/api/networking/crafting/ICraftingPatternDetails;Lnet/minecraft/inventory/InventoryCrafting;)Z" + )) + private boolean unwrapPatternWrapper(ICraftingMedium self, ICraftingPatternDetails details, + InventoryCrafting inventory, + Operation operation) { + final ICraftingPatternDetails newDetails; + if (details instanceof PatternTransformWrapper wrapper) { + newDetails = wrapper.getDelegate(); + } else { + newDetails = details; + } + + return operation.call(self, newDetails, inventory); + } + + @Inject( + method = "writeToNBT", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/nbt/NBTTagList;appendTag(Lnet/minecraft/nbt/NBTBase;)V", + remap = true + ) + ) + private void writeTransforms(CallbackInfo info, + @Local(name = "item") NBTTagCompound item, + @Local Map.Entry e) { + if (e.getKey() instanceof PatternTransformWrapper wrapper) { + var transforms = new NBTTagCompound(); + var toWrite = ImmutableMap.of( + "inputs", wrapper.getInputs(), + "outputs", wrapper.getOutputs() + ); + + for (var entry : toWrite.entrySet()) { + var list = new NBTTagList(); + for (var iaeItemStack : entry.getValue()) { + var aeItemStackNBT = new NBTTagCompound(); + iaeItemStack.writeToNBT(aeItemStackNBT); + list.appendTag(aeItemStackNBT); + } + + transforms.setTag(entry.getKey(), list); + } + + item.setTag("nae2$transforms", transforms); + } + } + + @ModifyExpressionValue(method = "readFromNBT", + at = @At( + value = "INVOKE", + target = "Lappeng/api/implementations/ICraftingPatternItem;getPatternForItem" + + "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;)" + + "Lappeng/api/networking/crafting/ICraftingPatternDetails;" + ) + ) + private ICraftingPatternDetails readFromNBT(ICraftingPatternDetails details, + @Local(name = "item") NBTTagCompound item) { + if (item.hasKey("nae2$transforms")) { + var transforms = item.getCompoundTag("nae2$transforms"); + var toRead = ImmutableMap.of( + "inputs", transforms.getTagList("inputs", 10), + "outputs", transforms.getTagList("outputs", 10) + ); + + var read = ImmutableMap.of( + "inputs", new ArrayList(), + "outputs", new ArrayList() + ); + + for (var entry : toRead.entrySet()) { + var list = entry.getValue(); + for (var serializedAEStack : list) { + var aeItemStack = AEItemStack.fromNBT((NBTTagCompound) serializedAEStack); + if (aeItemStack != null) { + read.get(entry.getKey()).add(aeItemStack); + } + } + } + + return new PatternTransformWrapper(details, + read.get("inputs").stream().toArray(IAEItemStack[]::new), + read.get("outputs").stream().toArray(IAEItemStack[]::new)); + } + + return details; + } +} diff --git a/src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingGrid.java b/src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingGrid.java new file mode 100644 index 0000000..337c0d1 --- /dev/null +++ b/src/main/java/co/neeve/nae2/mixin/crafting/patterntransform/MixinCraftingGrid.java @@ -0,0 +1,24 @@ +package co.neeve.nae2.mixin.crafting.patterntransform; + +import appeng.api.networking.crafting.ICraftingMedium; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.me.cache.CraftingGridCache; +import co.neeve.nae2.common.crafting.patterntransform.PatternTransform; +import co.neeve.nae2.common.crafting.patterntransform.PatternTransformWrapper; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = CraftingGridCache.class, remap = false) +public class MixinCraftingGrid { + @Inject(method = "addCraftingOption", at = @At("HEAD")) + private void addCraftingOption(ICraftingMedium medium, ICraftingPatternDetails api, CallbackInfo ci, + @Local LocalRef detailsLocalRef) { + if (PatternTransform.transform(medium, api) instanceof PatternTransformWrapper wrapper) { + detailsLocalRef.set(wrapper); + } + } +} diff --git a/src/main/java/co/neeve/nae2/mixin/upgrades/gregcircuit/MixinDualityInterface.java b/src/main/java/co/neeve/nae2/mixin/upgrades/gregcircuit/MixinDualityInterface.java index 737398c..f96110c 100644 --- a/src/main/java/co/neeve/nae2/mixin/upgrades/gregcircuit/MixinDualityInterface.java +++ b/src/main/java/co/neeve/nae2/mixin/upgrades/gregcircuit/MixinDualityInterface.java @@ -4,7 +4,7 @@ import appeng.helpers.DualityInterface; import appeng.parts.automation.UpgradeInventory; import appeng.util.inv.InvOperation; -import co.neeve.nae2.common.helpers.GregCircuitCraftingDetailsWrapper; +import co.neeve.nae2.common.crafting.patterntransform.transformers.GregTechCircuitPatternTransformer; import co.neeve.nae2.common.interfaces.IExtendedUpgradeInventory; import co.neeve.nae2.common.items.NAEBaseItemUpgrade; import co.neeve.nae2.common.registration.definitions.Upgrades; @@ -12,7 +12,7 @@ import com.llamalad7.mixinextras.sugar.ref.LocalRef; import gregtech.api.capability.IGhostSlotConfigurable; import gregtech.api.metatileentity.MetaTileEntityHolder; -import gregtech.api.recipes.ingredients.IntCircuitIngredient; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -20,16 +20,18 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.Arrays; -import java.util.Objects; - @Mixin(value = DualityInterface.class, remap = false) public abstract class MixinDualityInterface { + @Unique + private final Object2IntOpenHashMap nae2$cachedCircuitValues = + new Object2IntOpenHashMap<>(); + @Shadow @Final private UpgradeInventory upgrades; @@ -56,14 +58,8 @@ private void injectCircuitChange(ICraftingPatternDetails patternDetails, Invento var mte = metaTileEntityHolder.getMetaTileEntity(); if (mte instanceof IGhostSlotConfigurable slotConfigurable && slotConfigurable.hasGhostCircuitInventory()) { - final int config; - if (patternDetails instanceof GregCircuitCraftingDetailsWrapper greg) { - config = greg.getConfig(); - } else { - config = 0; - } - - slotConfigurable.setGhostCircuitConfig(config); + slotConfigurable.setGhostCircuitConfig( + this.nae2$cachedCircuitValues.getOrDefault(patternDetails, 0)); } } } @@ -78,6 +74,11 @@ private void injectInventoryChange(IItemHandler inv, int slot, InvOperation mc, } } + @Inject(method = "updateCraftingList", at = @At("HEAD")) + private void injectUpdateCraftingList(CallbackInfo ci) { + this.nae2$cachedCircuitValues.clear(); + } + @Inject( method = "addToCraftingList", at = @At( @@ -92,17 +93,9 @@ private void injectCraftingList(ItemStack is, CallbackInfo ci, && extendedUpgradeInventory.getInstalledUpgrades(Upgrades.UpgradeType.GREGTECH_CIRCUIT) > 0) { var details = detailsRef.get(); if (details != null && details.getInputs() != null) { - var optCircuit = Arrays.stream(details.getInputs()) - .filter(Objects::nonNull) - .filter(ais -> IntCircuitIngredient.isIntegratedCircuit(ais.createItemStack())) - .findFirst(); - - if (optCircuit.isPresent()) { - var circuit = optCircuit.get(); - var config = IntCircuitIngredient.getCircuitConfiguration(circuit.createItemStack()); + var optCircuit = GregTechCircuitPatternTransformer.getCircuitValueFromDetails(details); - detailsRef.set(new GregCircuitCraftingDetailsWrapper(details, config)); - } + optCircuit.ifPresent(integer -> this.nae2$cachedCircuitValues.put(details, integer.intValue())); } } } diff --git a/src/main/resources/mixins.nae2.json b/src/main/resources/mixins.nae2.json index 1d0a30b..2486db8 100644 --- a/src/main/resources/mixins.nae2.json +++ b/src/main/resources/mixins.nae2.json @@ -4,7 +4,10 @@ "target": "@env(DEFAULT)", "minVersion": "0.8", "compatibilityLevel": "JAVA_8", - "mixins": [], + "mixins": [ + "crafting.patterntransform.MixinCraftingCPUCluster", + "crafting.patterntransform.MixinCraftingGrid" + ], "client": [], "server": [] }