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 <skoch02@students.uni-mainz.de>
This commit is contained in:
AngelBottomless 2022-05-01 17:10:28 +09:00 committed by GitHub
parent 99e77a0678
commit 85638d2e42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,6 +84,21 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
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) {