From 6cf36e47bffebe7dc6b45b03c85d4a97e7dd3e73 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Mon, 31 Aug 2020 15:26:07 +0200 Subject: [PATCH] Fix Build Issues --- .../fluids/FluidNetworkEndpoint.java | 121 +----------------- .../fluids/InterPumpEndpoint.java | 108 ++++++++++++++++ .../contraptions/fluids/PumpEndpoint.java | 26 ++++ 3 files changed, 135 insertions(+), 120 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/fluids/InterPumpEndpoint.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/fluids/PumpEndpoint.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetworkEndpoint.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetworkEndpoint.java index 0dc2b25c2..e37e0b35c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetworkEndpoint.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetworkEndpoint.java @@ -1,11 +1,6 @@ package com.simibubi.create.content.contraptions.fluids; -import java.lang.ref.WeakReference; - import com.simibubi.create.foundation.utility.BlockFace; -import com.simibubi.create.foundation.utility.Couple; -import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.Pair; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IWorld; @@ -15,7 +10,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; -class FluidNetworkEndpoint { +public class FluidNetworkEndpoint { BlockFace location; protected LazyOptional handler; @@ -52,117 +47,3 @@ class FluidNetworkEndpoint { } } - -class PumpEndpoint extends FluidNetworkEndpoint { - - PumpTileEntity pumpTE; - - public PumpEndpoint(BlockFace location, PumpTileEntity pumpTE) { - super(pumpTE.getWorld(), location, LazyOptional.empty()); - this.pumpTE = pumpTE; - } - - @Override - protected void onHandlerInvalidated(IWorld world) {} - - @Override - public FluidStack provideFluid() { - return pumpTE.providedFluid; - } - -} - -class InterPumpEndpoint extends FluidNetworkEndpoint { - - Couple>> pumps; - - private InterPumpEndpoint(IWorld world, BlockFace location, LazyOptional handler) { - super(world, location, handler); - } - - public InterPumpEndpoint(IWorld world, BlockFace location, PumpTileEntity source, PumpTileEntity interfaced, - BlockFace sourcePos, BlockFace interfacedPos) { - this(world, location, LazyOptional.empty()); - handler = LazyOptional.of(() -> new InterPumpFluidHandler(this)); - pumps = Couple.create(Pair.of(sourcePos, new WeakReference<>(source)), - Pair.of(interfacedPos, new WeakReference<>(interfaced))); - } - - public InterPumpEndpoint opposite(IWorld world) { - InterPumpEndpoint interPumpEndpoint = new InterPumpEndpoint(world, this.location.getOpposite(), handler); - interPumpEndpoint.pumps = pumps.copy(); - return interPumpEndpoint; - } - - public Couple>> getPumps() { - return pumps; - } - - public boolean isPulling(boolean first) { - Pair> pair = getPumps().get(first); - PumpTileEntity pumpTileEntity = pair.getSecond() - .get(); - if (pumpTileEntity == null || pumpTileEntity.isRemoved()) - return false; - return pumpTileEntity.isPullingOnSide(pumpTileEntity.isFront(pair.getFirst() - .getFace())); - } - - public int getTransferSpeed(boolean first) { - PumpTileEntity pumpTileEntity = getPumps().get(first) - .getSecond() - .get(); - if (pumpTileEntity == null || pumpTileEntity.isRemoved()) - return 0; - return pumpTileEntity.getFluidTransferSpeed(); - } - - @Override - public LazyOptional provideHandler() { - if (isPulling(true) == isPulling(false)) - return LazyOptional.empty(); - if (getTransferSpeed(true) > getTransferSpeed(false)) - return LazyOptional.empty(); - return super.provideHandler(); - } - - @Override - public FluidStack provideFluid() { - if (!provideHandler().isPresent()) - return FluidStack.EMPTY; - - Couple>> pumps = getPumps(); - for (boolean current : Iterate.trueAndFalse) { - if (isPulling(current)) - continue; - - Pair> pair = pumps.get(current); - BlockFace blockFace = pair.getFirst(); - PumpTileEntity pumpTileEntity = pair.getSecond() - .get(); - if (pumpTileEntity == null) - continue; - if (pumpTileEntity.networks == null) - continue; - FluidNetwork fluidNetwork = pumpTileEntity.networks.get(pumpTileEntity.isFront(blockFace.getFace())); - for (FluidNetworkFlow fluidNetworkFlow : fluidNetwork.flows) { - for (FluidNetworkEndpoint fne : fluidNetworkFlow.outputEndpoints) { - if (!(fne instanceof InterPumpEndpoint)) - continue; - InterPumpEndpoint ipe = (InterPumpEndpoint) fne; - if (!ipe.location.isEquivalent(location)) - continue; - - FluidStack heldFluid = fluidNetworkFlow.fluidStack; - if (heldFluid.isEmpty()) - return heldFluid; - FluidStack copy = heldFluid.copy(); - copy.setAmount(1); - return heldFluid; - } - } - } - return FluidStack.EMPTY; - } - -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/InterPumpEndpoint.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/InterPumpEndpoint.java new file mode 100644 index 000000000..62904f74b --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/InterPumpEndpoint.java @@ -0,0 +1,108 @@ +package com.simibubi.create.content.contraptions.fluids; + +import java.lang.ref.WeakReference; + +import com.simibubi.create.foundation.utility.BlockFace; +import com.simibubi.create.foundation.utility.Couple; +import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.Pair; + +import net.minecraft.world.IWorld; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; + +public class InterPumpEndpoint extends FluidNetworkEndpoint { + + Couple>> pumps; + + private InterPumpEndpoint(IWorld world, BlockFace location, LazyOptional handler) { + super(world, location, handler); + } + + public InterPumpEndpoint(IWorld world, BlockFace location, PumpTileEntity source, PumpTileEntity interfaced, + BlockFace sourcePos, BlockFace interfacedPos) { + this(world, location, LazyOptional.empty()); + handler = LazyOptional.of(() -> new InterPumpFluidHandler(this)); + pumps = Couple.create(Pair.of(sourcePos, new WeakReference<>(source)), + Pair.of(interfacedPos, new WeakReference<>(interfaced))); + } + + public InterPumpEndpoint opposite(IWorld world) { + InterPumpEndpoint interPumpEndpoint = new InterPumpEndpoint(world, this.location.getOpposite(), handler); + interPumpEndpoint.pumps = pumps.copy(); + return interPumpEndpoint; + } + + public Couple>> getPumps() { + return pumps; + } + + public boolean isPulling(boolean first) { + Pair> pair = getPumps().get(first); + PumpTileEntity pumpTileEntity = pair.getSecond() + .get(); + if (pumpTileEntity == null || pumpTileEntity.isRemoved()) + return false; + return pumpTileEntity.isPullingOnSide(pumpTileEntity.isFront(pair.getFirst() + .getFace())); + } + + public int getTransferSpeed(boolean first) { + PumpTileEntity pumpTileEntity = getPumps().get(first) + .getSecond() + .get(); + if (pumpTileEntity == null || pumpTileEntity.isRemoved()) + return 0; + return pumpTileEntity.getFluidTransferSpeed(); + } + + @Override + public LazyOptional provideHandler() { + if (isPulling(true) == isPulling(false)) + return LazyOptional.empty(); + if (getTransferSpeed(true) > getTransferSpeed(false)) + return LazyOptional.empty(); + return super.provideHandler(); + } + + @Override + public FluidStack provideFluid() { + if (!provideHandler().isPresent()) + return FluidStack.EMPTY; + + Couple>> pumps = getPumps(); + for (boolean current : Iterate.trueAndFalse) { + if (isPulling(current)) + continue; + + Pair> pair = pumps.get(current); + BlockFace blockFace = pair.getFirst(); + PumpTileEntity pumpTileEntity = pair.getSecond() + .get(); + if (pumpTileEntity == null) + continue; + if (pumpTileEntity.networks == null) + continue; + FluidNetwork fluidNetwork = pumpTileEntity.networks.get(pumpTileEntity.isFront(blockFace.getFace())); + for (FluidNetworkFlow fluidNetworkFlow : fluidNetwork.flows) { + for (FluidNetworkEndpoint fne : fluidNetworkFlow.outputEndpoints) { + if (!(fne instanceof InterPumpEndpoint)) + continue; + InterPumpEndpoint ipe = (InterPumpEndpoint) fne; + if (!ipe.location.isEquivalent(location)) + continue; + + FluidStack heldFluid = fluidNetworkFlow.fluidStack; + if (heldFluid.isEmpty()) + return heldFluid; + FluidStack copy = heldFluid.copy(); + copy.setAmount(1); + return heldFluid; + } + } + } + return FluidStack.EMPTY; + } + +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpEndpoint.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpEndpoint.java new file mode 100644 index 000000000..eb0d0f18c --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpEndpoint.java @@ -0,0 +1,26 @@ +package com.simibubi.create.content.contraptions.fluids; + +import com.simibubi.create.foundation.utility.BlockFace; + +import net.minecraft.world.IWorld; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.FluidStack; + +public class PumpEndpoint extends FluidNetworkEndpoint { + + PumpTileEntity pumpTE; + + public PumpEndpoint(BlockFace location, PumpTileEntity pumpTE) { + super(pumpTE.getWorld(), location, LazyOptional.empty()); + this.pumpTE = pumpTE; + } + + @Override + protected void onHandlerInvalidated(IWorld world) {} + + @Override + public FluidStack provideFluid() { + return pumpTE.providedFluid; + } + +} \ No newline at end of file