Skip to content

Commit

Permalink
Change assembler to handle buckets in recipes better, see #5864
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSunrize committed Mar 30, 2024
1 parent 0f57b0e commit 45f5e18
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 23 additions & 19 deletions src/main/java/blusunrize/immersiveengineering/common/IEContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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<ItemStack> 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<ItemStack> 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));
});
Expand Down

0 comments on commit 45f5e18

Please sign in to comment.