Filter fluids input for fluid generators.
This commit is contained in:
parent
8f94d3484b
commit
6282e1f714
2 changed files with 24 additions and 17 deletions
|
@ -25,12 +25,14 @@
|
|||
package techreborn.blockentity.generator;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
|
@ -80,11 +82,15 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
|
|||
}
|
||||
|
||||
// Check cells input slot 2 time per second
|
||||
// Please, keep ticks counting on client also to report progress to GUI
|
||||
if (ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getInvStack(0).isEmpty()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 0, 1);
|
||||
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid());
|
||||
ItemStack inputStack = inventory.getInvStack(0);
|
||||
if (!inputStack.isEmpty()) {
|
||||
if (FluidUtils.isContainerEmpty(inputStack) && tank.getFluidAmount() > 0) {
|
||||
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid());
|
||||
}
|
||||
else if (getRecipes().getRecipeForFluid(((ItemFluidInfo) inputStack.getItem()).getFluid(inputStack)).isPresent()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
ticksSinceLastChange = 0;
|
||||
|
|
|
@ -58,16 +58,10 @@ public class FluidUtils {
|
|||
ItemStack inputStack = inventory.getInvStack(inputSlot);
|
||||
ItemStack outputStack = inventory.getInvStack(outputSlot);
|
||||
|
||||
if (inputStack.isEmpty()) return false;
|
||||
|
||||
if(!(inputStack.getItem() instanceof ItemFluidInfo)) return false;
|
||||
|
||||
if (outputStack.getCount() >= outputStack.getMaxCount()) return false;
|
||||
if (FluidUtils.isContainerEmpty(inputStack)) return false;
|
||||
|
||||
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
||||
|
||||
if(itemFluidInfo.getFluid(inputStack) == Fluids.EMPTY) return false;
|
||||
|
||||
FluidInstance targetFluidInstance = target.getFluidInstance(null);
|
||||
Fluid currentFluid = targetFluidInstance.getFluid();
|
||||
|
||||
|
@ -99,14 +93,10 @@ public class FluidUtils {
|
|||
public static boolean fillContainers(GenericFluidContainer<Direction> source, Inventory inventory, int inputSlot, int outputSlot, Fluid fluidToFill) {
|
||||
ItemStack inputStack = inventory.getInvStack(inputSlot);
|
||||
ItemStack outputStack = inventory.getInvStack(outputSlot);
|
||||
|
||||
if (inputStack.isEmpty()) return false;
|
||||
|
||||
if(!(inputStack.getItem() instanceof ItemFluidInfo)) return false;
|
||||
|
||||
if (!FluidUtils.isContainerEmpty(inputStack)) return false;
|
||||
|
||||
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
||||
if(itemFluidInfo.getFluid(inputStack) != Fluids.EMPTY) return false;
|
||||
|
||||
FluidInstance sourceFluid = source.getFluidInstance(null);
|
||||
|
||||
if(sourceFluid.getFluid() == Fluids.EMPTY || sourceFluid.getAmount() < 1000){
|
||||
|
@ -145,4 +135,15 @@ public class FluidUtils {
|
|||
public static FluidInstance getFluidStackInContainer(@NonNull ItemStack invStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isContainerEmpty(ItemStack inputStack) {
|
||||
if (inputStack.isEmpty())
|
||||
return false;
|
||||
if (!(inputStack.getItem() instanceof ItemFluidInfo))
|
||||
return false;
|
||||
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
||||
if (itemFluidInfo.getFluid(inputStack) != Fluids.EMPTY)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue