aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java17
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java41
2 files changed, 47 insertions, 11 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java
index 6c46600f94..fd83f6899b 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java
@@ -131,17 +131,12 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch
IFluidHandler tTileEntity = aBaseMetaTileEntity
.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing());
if (tTileEntity != null) {
- FluidStack tDrained = aBaseMetaTileEntity
- .drain(aBaseMetaTileEntity.getFrontFacing(), Math.max(1, mFluid.amount), false);
- if (tDrained != null) {
- int tFilledAmount = tTileEntity.fill(aBaseMetaTileEntity.getBackFacing(), tDrained, false);
- if (tFilledAmount > 0) {
- tTileEntity.fill(
- aBaseMetaTileEntity.getBackFacing(),
- aBaseMetaTileEntity.drain(aBaseMetaTileEntity.getFrontFacing(), tFilledAmount, true),
- true);
- }
- }
+ GT_Utility.moveFluid(
+ aBaseMetaTileEntity,
+ tTileEntity,
+ aBaseMetaTileEntity.getFrontFacing(),
+ Math.max(1, mFluid.amount),
+ null);
}
}
}
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 75451d9fdf..d41e2a3b04 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -45,6 +45,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.IntFunction;
+import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
@@ -1682,6 +1683,46 @@ public class GT_Utility {
true);
}
+ /**
+ * Move up to maxAmount amount of fluid from source to dest, with optional filtering via allowMove. note that this
+ * filter cannot bypass filtering done by IFluidHandlers themselves.
+ *
+ * this overload will assume the fill side is the opposite of drainSide
+ *
+ * @param source tank to drain from. method become noop if this is null
+ * @param dest tank to fill to. method become noop if this is null
+ * @param drainSide side used during draining operation
+ * @param maxAmount max amount of fluid to transfer. method become noop if this is not a positive integer
+ * @param allowMove filter. can be null to signal all fluids are accepted
+ */
+ public static void moveFluid(IFluidHandler source, IFluidHandler dest, ForgeDirection drainSide, int maxAmount,
+ @Nullable Predicate<FluidStack> allowMove) {
+ moveFluid(source, dest, drainSide, drainSide.getOpposite(), maxAmount, allowMove);
+ }
+
+ /**
+ * Move up to maxAmount amount of fluid from source to dest, with optional filtering via allowMove. note that this
+ * filter cannot bypass filtering done by IFluidHandlers themselves.
+ *
+ * @param source tank to drain from. method become noop if this is null
+ * @param dest tank to fill to. method become noop if this is null
+ * @param drainSide side used during draining operation
+ * @param fillSide side used during filling operation
+ * @param maxAmount max amount of fluid to transfer. method become noop if this is not a positive integer
+ * @param allowMove filter. can be null to signal all fluids are accepted
+ */
+ public static void moveFluid(IFluidHandler source, IFluidHandler dest, ForgeDirection drainSide,
+ ForgeDirection fillSide, int maxAmount, @Nullable Predicate<FluidStack> allowMove) {
+ if (source == null || dest == null || maxAmount <= 0) return;
+ FluidStack liquid = source.drain(drainSide, maxAmount, false);
+ if (liquid == null) return;
+ liquid = liquid.copy();
+ liquid.amount = dest.fill(fillSide, liquid, false);
+ if (liquid.amount > 0 && (allowMove == null || allowMove.test(liquid))) {
+ dest.fill(fillSide, source.drain(drainSide, liquid.amount, true), true);
+ }
+ }
+
public static boolean listContainsItem(Collection<ItemStack> aList, ItemStack aStack, boolean aTIfListEmpty,
boolean aInvertFilter) {
if (aStack == null || aStack.stackSize < 1) return false;