From 91bc678ab401869426ddf3a4c4f0e7ebed075ab3 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Fri, 18 Jun 2021 18:48:12 +0200 Subject: [PATCH] Finding bugs explaining things - The portable fluid interface now waits until extracting pipes have completed their flow before disengaging --- .../actors/PortableFluidInterfaceTileEntity.java | 14 +++++++++----- .../content/contraptions/fluids/FluidNetwork.java | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java index 4c27df6f1..1559bd22d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableFluidInterfaceTileEntity.java @@ -51,7 +51,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi return super.getCapability(cap, side); } - class InterfaceFluidHandler implements IFluidHandler { + public class InterfaceFluidHandler implements IFluidHandler { private IFluidHandler wrapped; @@ -85,7 +85,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi return 0; int fill = wrapped.fill(resource, action); if (fill > 0 && action.execute()) - onContentTransferred(); + keepAlive(); return fill; } @@ -95,7 +95,7 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi return FluidStack.EMPTY; FluidStack drain = wrapped.drain(resource, action); if (!drain.isEmpty() && action.execute()) - onContentTransferred(); + keepAlive(); return drain; } @@ -104,10 +104,14 @@ public class PortableFluidInterfaceTileEntity extends PortableStorageInterfaceTi if (!canTransfer()) return FluidStack.EMPTY; FluidStack drain = wrapped.drain(maxDrain, action); - if (!drain.isEmpty() && (action.execute() || drain.getAmount() == 1)) - onContentTransferred(); + if (!drain.isEmpty() && action.execute()) + keepAlive(); return drain; } + + public void keepAlive() { + onContentTransferred(); + } } 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 364b7cf29..f6b08b2e8 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 @@ -12,6 +12,7 @@ import java.util.function.Supplier; import javax.annotation.Nullable; +import com.simibubi.create.content.contraptions.components.actors.PortableFluidInterfaceTileEntity.InterfaceFluidHandler; import com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow; import com.simibubi.create.foundation.fluid.FluidHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -157,6 +158,9 @@ public class FluidNetwork { source = sourceSupplier.get(); if (!source.isPresent()) return; + + keepPortableFluidInterfaceEngaged(); + if (targets.isEmpty()) return; for (Pair> pair : targets) { @@ -252,6 +256,15 @@ public class FluidNetwork { // .colored(0xfaaa33); // } + private void keepPortableFluidInterfaceEngaged() { + IFluidHandler handler = source.orElse(null); + if (!(handler instanceof InterfaceFluidHandler)) + return; + if (frontier.isEmpty()) + return; + ((InterfaceFluidHandler) handler).keepAlive(); + } + public void reset() { frontier.clear(); visited.clear();