From 484acd8d25f58d424a5b3869e1deae04bf8b609d Mon Sep 17 00:00:00 2001 From: KnightMiner Date: Sun, 4 Apr 2021 16:49:08 -0400 Subject: [PATCH] Hide flowing fluids in the fluid ingredient display --- .../mantle/recipe/FluidIngredient.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/slimeknights/mantle/recipe/FluidIngredient.java b/src/main/java/slimeknights/mantle/recipe/FluidIngredient.java index a8a141a..5d47265 100644 --- a/src/main/java/slimeknights/mantle/recipe/FluidIngredient.java +++ b/src/main/java/slimeknights/mantle/recipe/FluidIngredient.java @@ -31,6 +31,9 @@ public abstract class FluidIngredient { /** Empty fluid ingredient, matches nothing */ public static final FluidIngredient EMPTY = new Empty(); + /** Cached list of display fluids */ + private List displayFluids; + /** * Checks if the given fluid matches this ingredient * @param fluid Fluid to check @@ -59,7 +62,21 @@ public abstract class FluidIngredient { * Gets a list of fluid stacks contained in this ingredient for display * @return List of fluid stacks for this ingredient */ - public abstract List getFluids(); + public List getFluids() { + if (displayFluids == null) { + displayFluids = getAllFluids().stream().filter(stack -> { + Fluid fluid = stack.getFluid(); + return fluid.isSource(fluid.getDefaultState()); + }).collect(Collectors.toList()); + } + return displayFluids; + } + + /** + * Gets a list of fluid stacks contained in this ingredient for display, may include flowing fluids + * @return List of fluid stacks for this ingredient + */ + protected abstract List getAllFluids(); /** * Serializes the Fluid Ingredient into JSON @@ -72,7 +89,7 @@ public abstract class FluidIngredient { * @param buffer Packet buffer instance */ public void write(PacketBuffer buffer) { - Collection fluids = getFluids(); + Collection fluids = getAllFluids(); buffer.writeInt(fluids.size()); for (FluidStack stack : fluids) { buffer.writeString(Objects.requireNonNull(stack.getFluid().getRegistryName()).toString()); @@ -239,7 +256,7 @@ public abstract class FluidIngredient { } @Override - public List getFluids() { + public List getAllFluids() { return Collections.emptyList(); } @@ -268,7 +285,7 @@ public abstract class FluidIngredient { } @Override - public List getFluids() { + public List getAllFluids() { return Collections.singletonList(new FluidStack(fluid, amount)); } @@ -324,7 +341,7 @@ public abstract class FluidIngredient { } @Override - public List getFluids() { + public List getAllFluids() { return tag.getAllElements().stream().map((fluid) -> new FluidStack(fluid, amount)).collect(Collectors.toList()); } @@ -381,7 +398,7 @@ public abstract class FluidIngredient { } @Override - public List getFluids() { + public List getAllFluids() { return ingredients.stream() .flatMap(ingredient -> ingredient.getFluids().stream()) .collect(Collectors.toList());