diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/extrautils2/IMachineRecipeMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/extrautils2/IMachineRecipeMixin.java new file mode 100644 index 00000000..2528605e --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/extrautils2/IMachineRecipeMixin.java @@ -0,0 +1,43 @@ +package com.nomiceu.nomilabs.mixin.extrautils2; + +import java.util.Map; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +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.CallbackInfoReturnable; + +import com.google.common.collect.ImmutableMap; +import com.rwtema.extrautils2.api.machine.IMachineRecipe; +import com.rwtema.extrautils2.api.machine.MachineSlotFluid; +import com.rwtema.extrautils2.api.machine.MachineSlotItem; +import com.rwtema.extrautils2.machine.TileMachine; + +/** + * Fixes XU2 Machine Recipes not consuming GT Tools Correctly, especially evident in the Enchanter. + *

+ * This causes a dupe bug of GT Tools. + */ +@Mixin(value = IMachineRecipe.class, remap = false) +public interface IMachineRecipeMixin { + + /** + * Overrides (most) XU2 Machine Recipes to return a empty map instead of a map of collections of items, populated + * via {@link net.minecraftforge.common.ForgeHooks#getContainerItem(ItemStack)}. + *

+ * This is because ItemGTTool overrides that method, in order to damage, instead of consume, GT Tools in Crafting + * Recipes. + *

+ * See {@link TileMachine#consumeInputs()} for why this works. Essentially, if there is no container item map for + * the specified slot, an Empty ItemStack is used instead. + */ + @Inject(method = "getContainerItems", at = @At("HEAD"), cancellable = true) + default void getEmptyStacks(Map inputItems, + Map inputFluids, + CallbackInfoReturnable> cir) { + cir.setReturnValue(ImmutableMap.of()); + } +} diff --git a/src/main/resources/mixins.nomilabs.extrautils2.json b/src/main/resources/mixins.nomilabs.extrautils2.json index 853adc07..5efa558d 100644 --- a/src/main/resources/mixins.nomilabs.extrautils2.json +++ b/src/main/resources/mixins.nomilabs.extrautils2.json @@ -5,6 +5,7 @@ "minVersion": "0.8", "compatibilityLevel": "JAVA_8", "mixins": [ + "IMachineRecipeMixin", "ItemIngredientsMixin", "ResonatorMixin" ],