Skip to content

Commit

Permalink
Optimize spout recipe generation by avoiding filling non-empty items
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Jan 10, 2025
1 parent d48a504 commit b8e3ff3
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ public static void consumeRecipes(Consumer<FillingRecipe> consumer, IIngredientM
if (!capability.isPresent())
continue;

var existingFluidHandler = capability.orElse(null);
int numTanks = existingFluidHandler.getTanks();
FluidStack existingFluid = numTanks == 1 ? existingFluidHandler.getFluidInTank(0) : FluidStack.EMPTY;

for (FluidStack fluidStack : fluidStacks) {
// Hoist the fluid equality check to avoid the work of copying the stack + populating capabilities
// when most fluids will not match
if (numTanks == 1 && (!existingFluid.isEmpty() && !existingFluid.isFluidEqual(fluidStack))) {
continue;
}
ItemStack copy = stack.copy();
copy.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM)
.ifPresent(fhi -> {
Expand Down

0 comments on commit b8e3ff3

Please sign in to comment.