From 64b2c61389b7dfde052b18d6c88fc0b286855242 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 15 Dec 2020 23:13:22 +0100 Subject: [PATCH] Bug fixes - Fixed spout creating potions from any fluid - Fixed pipes not actually transferring the type of fluid selected by layer II flow propagation - Fixed some fluid handlers erasing nbt data of extracted fluidstacks - Fix sidedness issues in Config packets --- .../contraptions/fluids/FluidNetwork.java | 41 +++++++++++++++---- .../fluids/actors/GenericItemFilling.java | 26 ++++++++---- .../command/ConfigureConfigPacket.java | 35 +++++++++------- .../foundation/fluid/CombinedTankWrapper.java | 3 +- 4 files changed, 73 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java index 8a3305e74..a0e0ac8cc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java @@ -13,6 +13,7 @@ import java.util.function.Supplier; import javax.annotation.Nullable; import com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow; +import com.simibubi.create.foundation.fluid.FluidHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Iterate; @@ -29,7 +30,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; public class FluidNetwork { private static int CYCLES_PER_TICK = 16; - + World world; BlockFace start; @@ -41,6 +42,7 @@ public class FluidNetwork { List queued; Set> frontier; Set visited; + FluidStack fluid; List>> targets; Map> cache; @@ -49,6 +51,7 @@ public class FluidNetwork { this.start = location; this.sourceSupplier = sourceSupplier; this.source = LazyOptional.empty(); + this.fluid = FluidStack.EMPTY; this.frontier = new HashSet<>(); this.visited = new HashSet<>(); this.targets = new ArrayList<>(); @@ -62,7 +65,7 @@ public class FluidNetwork { pauseBeforePropagation--; return; } - + for (int cycle = 0; cycle < CYCLES_PER_TICK; cycle++) { boolean shouldContinue = false; for (Iterator iterator = queued.iterator(); iterator.hasNext();) { @@ -77,17 +80,22 @@ public class FluidNetwork { } iterator.remove(); } - + // drawDebugOutlines(); - + for (Iterator> iterator = frontier.iterator(); iterator.hasNext();) { Pair pair = iterator.next(); BlockFace blockFace = pair.getFirst(); PipeConnection pipeConnection = pair.getSecond(); - + if (!pipeConnection.hasFlow()) continue; + Flow flow = pipeConnection.flow.get(); + if (!fluid.isEmpty() && !flow.fluid.isFluidEqual(fluid)) { + iterator.remove(); + continue; + } if (!flow.inbound) { if (pipeConnection.comparePressure() >= 0) iterator.remove(); @@ -96,6 +104,9 @@ public class FluidNetwork { if (!flow.complete) continue; + if (fluid.isEmpty()) + fluid = flow.fluid; + boolean canRemove = true; for (Direction side : Iterate.directions) { if (side == blockFace.getFace()) @@ -120,14 +131,14 @@ public class FluidNetwork { canRemove = false; continue; } - + if (adjacent.source.isPresent() && adjacent.source.get() .isEndpoint()) { targets.add(Pair.of(adjacentLocation, adjacent.source.get() .provideHandler())); continue; } - + if (visited.add(adjacentLocation.getConnectedPos())) { queued.add(adjacentLocation.getOpposite()); shouldContinue = true; @@ -139,7 +150,7 @@ public class FluidNetwork { if (!shouldContinue) break; } - + // drawDebugOutlines(); if (!source.isPresent()) @@ -168,7 +179,18 @@ public class FluidNetwork { IFluidHandler handler = source.orElse(null); if (handler == null) return; - FluidStack transfer = handler.drain(flowSpeed, action); + + FluidStack transfer = FluidStack.EMPTY; + for (int i = 0; i < handler.getTanks(); i++) { + FluidStack contained = handler.getFluidInTank(i); + if (contained.isEmpty()) + continue; + if (!contained.isFluidEqual(fluid)) + continue; + FluidStack toExtract = FluidHelper.copyStackWithAmount(contained, flowSpeed); + transfer = handler.drain(toExtract, action); + } + if (transfer.isEmpty()) return; @@ -229,6 +251,7 @@ public class FluidNetwork { visited.clear(); targets.clear(); queued.clear(); + fluid = FluidStack.EMPTY; queued.add(start); pauseBeforePropagation = 2; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java index a18ffc858..4f6ebb553 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java @@ -1,8 +1,10 @@ package com.simibubi.create.content.contraptions.fluids.actors; +import com.simibubi.create.AllFluids; import com.simibubi.create.content.contraptions.fluids.potion.PotionFluidHandler; import com.simibubi.create.foundation.fluid.FluidHelper; +import net.minecraft.fluid.Fluids; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -19,7 +21,7 @@ import net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper; public class GenericItemFilling { public static boolean canItemBeFilled(World world, ItemStack stack) { - if (stack.getItem() == Items.GLASS_BOTTLE) + if (stack.getItem() == Items.GLASS_BOTTLE) return true; LazyOptional capability = @@ -34,9 +36,9 @@ public class GenericItemFilling { } return false; } - + public static int getRequiredAmountForItem(World world, ItemStack stack, FluidStack availableFluid) { - if (stack.getItem() == Items.GLASS_BOTTLE) + if (stack.getItem() == Items.GLASS_BOTTLE && canFillGlassBottleInternally(availableFluid)) return PotionFluidHandler.getRequiredAmountForFilledBottle(stack, availableFluid); LazyOptional capability = @@ -45,7 +47,8 @@ public class GenericItemFilling { if (tank == null) return -1; if (tank instanceof FluidBucketWrapper) { - Item filledBucket = availableFluid.getFluid().getFilledBucket(); + Item filledBucket = availableFluid.getFluid() + .getFilledBucket(); if (filledBucket == null || filledBucket == Items.AIR) return -1; return 1000; @@ -54,13 +57,20 @@ public class GenericItemFilling { int filled = tank.fill(availableFluid, FluidAction.SIMULATE); return filled == 0 ? -1 : filled; } - + + private static boolean canFillGlassBottleInternally(FluidStack availableFluid) { + return availableFluid.getFluid() + .isEquivalentTo(Fluids.WATER) + || availableFluid.getFluid() + .isEquivalentTo(AllFluids.POTION.get()); + } + public static ItemStack fillItem(World world, int requiredAmount, ItemStack stack, FluidStack availableFluid) { FluidStack toFill = availableFluid.copy(); toFill.setAmount(requiredAmount); availableFluid.shrink(requiredAmount); - - if (stack.getItem() == Items.GLASS_BOTTLE) { + + if (stack.getItem() == Items.GLASS_BOTTLE && canFillGlassBottleInternally(availableFluid)) { ItemStack fillBottle = ItemStack.EMPTY; if (FluidHelper.isWater(toFill.getFluid())) fillBottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER); @@ -83,5 +93,5 @@ public class GenericItemFilling { stack.shrink(1); return container; } - + } diff --git a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java index 908b83d85..b6790ab4b 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java @@ -57,35 +57,42 @@ public class ConfigureConfigPacket extends SimplePacketBase { } enum Actions { - rainbowDebug((value) -> { - AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value)); - }), - overlayScreen(Actions::overlayScreenAction), - fixLighting(Actions::experimentalLightingAction), - overlayReset((value) -> { - AllConfigs.CLIENT.overlayOffsetX.set(0); - AllConfigs.CLIENT.overlayOffsetY.set(0); - }), + rainbowDebug(() -> Actions::rainbowDebug), + overlayScreen(() -> Actions::overlayScreen), + fixLighting(() -> Actions::experimentalLighting), + overlayReset(() -> Actions::overlayReset), ; - private final Consumer consumer; + private final Supplier> consumer; - Actions(Consumer action) { + Actions(Supplier> action) { this.consumer = action; } void performAction(String value) { - consumer.accept(value); + consumer.get() + .accept(value); } @OnlyIn(Dist.CLIENT) - private static void overlayScreenAction(String value) { + private static void rainbowDebug(String value) { + AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value)); + } + + @OnlyIn(Dist.CLIENT) + private static void overlayReset(String value) { + AllConfigs.CLIENT.overlayOffsetX.set(0); + AllConfigs.CLIENT.overlayOffsetY.set(0); + } + + @OnlyIn(Dist.CLIENT) + private static void overlayScreen(String value) { ScreenOpener.open(new GoggleConfigScreen()); } @OnlyIn(Dist.CLIENT) - private static void experimentalLightingAction(String value) { + private static void experimentalLighting(String value) { ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.set(true); Minecraft.getInstance().worldRenderer.loadRenderers(); } diff --git a/src/main/java/com/simibubi/create/foundation/fluid/CombinedTankWrapper.java b/src/main/java/com/simibubi/create/foundation/fluid/CombinedTankWrapper.java index 7429764d7..8a25aa0fe 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/CombinedTankWrapper.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/CombinedTankWrapper.java @@ -108,7 +108,8 @@ public class CombinedTankWrapper implements IFluidHandler { resource.shrink(amount); if (!drainedFromCurrent.isEmpty() && (drained.isEmpty() || drainedFromCurrent.isFluidEqual(drained))) - drained = new FluidStack(drainedFromCurrent.getFluid(), amount + drained.getAmount(), drained.getTag()); + drained = new FluidStack(drainedFromCurrent.getFluid(), amount + drained.getAmount(), + drainedFromCurrent.getTag()); if (resource.isEmpty()) break; }