From 85638d2e424d705a84f993ac8390736625245dcc Mon Sep 17 00:00:00 2001 From: AngelBottomless <35677394+aria1th@users.noreply.github.com> Date: Sun, 1 May 2022 17:10:28 +0900 Subject: [PATCH] Fix Fluid Tanks generating static lag from trying to pull /push fluid from Items.AIR (#2935) * Did you know this? Tank units can just generate lags by existence * add Valid inventory check Very modded extension can declare RebornInventory with size 0 to only process fluids without items, for that case * separate as function and more condition check to reduce extra lag * Parentheses Co-authored-by: Ayutac --- .../fluid/TankUnitBaseBlockEntity.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/techreborn/blockentity/storage/fluid/TankUnitBaseBlockEntity.java b/src/main/java/techreborn/blockentity/storage/fluid/TankUnitBaseBlockEntity.java index af99dd52b..190ec2a09 100644 --- a/src/main/java/techreborn/blockentity/storage/fluid/TankUnitBaseBlockEntity.java +++ b/src/main/java/techreborn/blockentity/storage/fluid/TankUnitBaseBlockEntity.java @@ -83,7 +83,22 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I dropStack.getOrCreateNbt().put("blockEntity", blockEntity); return dropStack; } - + + protected boolean canDrainTransfer(){ + if (inventory == null || inventory.size() < 2){ + return false; + } + ItemStack firstStack = inventory.getStack(0); + if (firstStack.isEmpty()){ + return false; + } + ItemStack secondStack = inventory.getStack(1); + if (secondStack.getCount() >= secondStack.getMaxCount()){ + return false; + } + return true; + } + // MachineBaseBlockEntity @Override public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) { @@ -93,7 +108,7 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I return; } - if (FluidUtils.drainContainers(tank, inventory, 0, 1) + if ((canDrainTransfer() && FluidUtils.drainContainers(tank, inventory, 0, 1)) || FluidUtils.fillContainers(tank, inventory, 0, 1)) { if (type == TRContent.TankUnit.CREATIVE) {