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:
parent
99e77a0678
commit
85638d2e42
1 changed files with 17 additions and 2 deletions
|
@ -83,7 +83,22 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
||||||
dropStack.getOrCreateNbt().put("blockEntity", blockEntity);
|
dropStack.getOrCreateNbt().put("blockEntity", blockEntity);
|
||||||
return dropStack;
|
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
|
// MachineBaseBlockEntity
|
||||||
@Override
|
@Override
|
||||||
public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) {
|
public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) {
|
||||||
|
@ -93,7 +108,7 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FluidUtils.drainContainers(tank, inventory, 0, 1)
|
if ((canDrainTransfer() && FluidUtils.drainContainers(tank, inventory, 0, 1))
|
||||||
|| FluidUtils.fillContainers(tank, inventory, 0, 1)) {
|
|| FluidUtils.fillContainers(tank, inventory, 0, 1)) {
|
||||||
|
|
||||||
if (type == TRContent.TankUnit.CREATIVE) {
|
if (type == TRContent.TankUnit.CREATIVE) {
|
||||||
|
|
Loading…
Reference in a new issue