From 45f5e1892652bb4692f6bd84e3783cadaf43e88c Mon Sep 17 00:00:00 2001 From: BluSunrize Date: Sat, 30 Mar 2024 11:56:40 +0100 Subject: [PATCH] Change assembler to handle buckets in recipes better, see #5864 --- changelog.md | 1 + .../common/IEContent.java | 42 ++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/changelog.md b/changelog.md index 2c5aa433a6..c1e11077ce 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,7 @@ - Add the plated shield to the "forge:tools/shields" tag (BluSunrize) - Change turrets to accept generic entity terms like "Villager" for their black/whitelist (BluSunrize) - Change text rendering in GUIs to be more readable (BluSunrize) +- Change assembler to handle buckets in recipes better (BluSunrize) - Fix issues with multiblocks being accessed before being full formed (Malte) - Fix items with obj renders breaking in the AE2 inscriber - Fix drill overlay highlighting too many blocks (Malte) diff --git a/src/main/java/blusunrize/immersiveengineering/common/IEContent.java b/src/main/java/blusunrize/immersiveengineering/common/IEContent.java index 6e3b156c9a..41a6e1b1cb 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/IEContent.java +++ b/src/main/java/blusunrize/immersiveengineering/common/IEContent.java @@ -90,7 +90,8 @@ import net.minecraftforge.registries.NewRegistryEvent; import java.io.IOException; -import java.util.function.Consumer; +import java.util.Arrays; +import java.util.Optional; import static blusunrize.immersiveengineering.ImmersiveEngineering.MODID; import static blusunrize.immersiveengineering.api.tool.assembler.AssemblerHandler.defaultAdapter; @@ -196,8 +197,7 @@ public static void commonSetup(ParallelDispatchEvent ev) /*ASSEMBLER RECIPE ADAPTERS*/ //Fluid Ingredients - AssemblerHandler.registerSpecialIngredientConverter((o, remain) -> - { + AssemblerHandler.registerSpecialIngredientConverter((o, remain) -> { if(o instanceof IngredientFluidStack) return new FluidTagRecipeQuery(((IngredientFluidStack)o).getFluidTagInput()); else @@ -206,33 +206,37 @@ public static void commonSetup(ParallelDispatchEvent ev) // Buckets // TODO add "duplicates" of the fluid-aware recipes that only use buckets, so that other mods using similar // code don't need explicit compat? - AssemblerHandler.registerSpecialIngredientConverter((o, remain) -> - { - final ItemStack[] matching = o.getItems(); - if(!o.isVanilla()||matching.length!=1) - return null; - final Item potentialBucket = matching[0].getItem(); - if(!(potentialBucket instanceof BucketItem)) + AssemblerHandler.registerSpecialIngredientConverter((o, remain) -> { + // Must be a vanilla ingredient, which returns an empty bucket + if(!o.isVanilla()||remain.getItem()!=Items.BUCKET) return null; - // bucket was consumed in recipe - if(remain.getItem()!=Items.BUCKET) + // Find bucket out of available items + Optional potentialBucket = Arrays.stream(o.getItems()) + .filter(stack -> stack.getItem() instanceof BucketItem) + .findFirst(); + if(potentialBucket.isEmpty()) return null; + final Item bucketItem = potentialBucket.get().getItem(); //Explicitly check for vanilla-style non-dynamic container items //noinspection deprecation - if(!potentialBucket.hasCraftingRemainingItem()||potentialBucket.getCraftingRemainingItem()!=Items.BUCKET) + if(!bucketItem.hasCraftingRemainingItem()||bucketItem.getCraftingRemainingItem()!=Items.BUCKET) return null; - final Fluid contained = ((BucketItem)potentialBucket).getFluid(); + final Fluid contained = ((BucketItem)bucketItem).getFluid(); return new FluidStackRecipeQuery(new FluidStack(contained, FluidType.BUCKET_VOLUME)); }); // Milk is a weird special case AssemblerHandler.registerSpecialIngredientConverter((o, remain) -> { - final ItemStack[] matching = o.getItems(); - if(!o.isVanilla()||matching.length!=1) + // Only works when the milk fluid is enabled + if(!ForgeMod.MILK.isPresent()) return null; - if(matching[0].getItem()!=Items.MILK_BUCKET||!ForgeMod.MILK.isPresent()) + // Must be a vanilla ingredient, which returns an empty bucket + if(!o.isVanilla()||remain.getItem()!=Items.BUCKET) return null; - // bucket was consumed in recipe - if(remain.getItem()!=Items.BUCKET) + // Find milk bucket out of available items + Optional potentialBucket = Arrays.stream(o.getItems()) + .filter(stack -> stack.getItem()==Items.MILK_BUCKET) + .findFirst(); + if(potentialBucket.isEmpty()) return null; return new FluidStackRecipeQuery(new FluidStack(ForgeMod.MILK.get(), FluidType.BUCKET_VOLUME)); });