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;
|
package techreborn.blockentity.generator;
|
||||||
|
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import reborncore.api.IToolDrop;
|
import reborncore.api.IToolDrop;
|
||||||
import reborncore.api.blockentity.InventoryProvider;
|
import reborncore.api.blockentity.InventoryProvider;
|
||||||
import reborncore.common.blocks.BlockMachineBase;
|
import reborncore.common.blocks.BlockMachineBase;
|
||||||
|
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||||
import reborncore.common.util.RebornInventory;
|
import reborncore.common.util.RebornInventory;
|
||||||
import reborncore.common.util.Tank;
|
import reborncore.common.util.Tank;
|
||||||
|
@ -80,12 +82,16 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check cells input slot 2 time per second
|
// Check cells input slot 2 time per second
|
||||||
// Please, keep ticks counting on client also to report progress to GUI
|
|
||||||
if (ticksSinceLastChange >= 10) {
|
if (ticksSinceLastChange >= 10) {
|
||||||
if (!inventory.getInvStack(0).isEmpty()) {
|
ItemStack inputStack = inventory.getInvStack(0);
|
||||||
FluidUtils.drainContainers(tank, inventory, 0, 1);
|
if (!inputStack.isEmpty()) {
|
||||||
|
if (FluidUtils.isContainerEmpty(inputStack) && tank.getFluidAmount() > 0) {
|
||||||
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid());
|
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;
|
ticksSinceLastChange = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,16 +58,10 @@ public class FluidUtils {
|
||||||
ItemStack inputStack = inventory.getInvStack(inputSlot);
|
ItemStack inputStack = inventory.getInvStack(inputSlot);
|
||||||
ItemStack outputStack = inventory.getInvStack(outputSlot);
|
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 (outputStack.getCount() >= outputStack.getMaxCount()) return false;
|
||||||
|
if (FluidUtils.isContainerEmpty(inputStack)) return false;
|
||||||
|
|
||||||
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
||||||
|
|
||||||
if(itemFluidInfo.getFluid(inputStack) == Fluids.EMPTY) return false;
|
|
||||||
|
|
||||||
FluidInstance targetFluidInstance = target.getFluidInstance(null);
|
FluidInstance targetFluidInstance = target.getFluidInstance(null);
|
||||||
Fluid currentFluid = targetFluidInstance.getFluid();
|
Fluid currentFluid = targetFluidInstance.getFluid();
|
||||||
|
|
||||||
|
@ -100,13 +94,9 @@ public class FluidUtils {
|
||||||
ItemStack inputStack = inventory.getInvStack(inputSlot);
|
ItemStack inputStack = inventory.getInvStack(inputSlot);
|
||||||
ItemStack outputStack = inventory.getInvStack(outputSlot);
|
ItemStack outputStack = inventory.getInvStack(outputSlot);
|
||||||
|
|
||||||
if (inputStack.isEmpty()) return false;
|
if (!FluidUtils.isContainerEmpty(inputStack)) return false;
|
||||||
|
|
||||||
if(!(inputStack.getItem() instanceof ItemFluidInfo)) return false;
|
|
||||||
|
|
||||||
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
||||||
if(itemFluidInfo.getFluid(inputStack) != Fluids.EMPTY) return false;
|
|
||||||
|
|
||||||
FluidInstance sourceFluid = source.getFluidInstance(null);
|
FluidInstance sourceFluid = source.getFluidInstance(null);
|
||||||
|
|
||||||
if(sourceFluid.getFluid() == Fluids.EMPTY || sourceFluid.getAmount() < 1000){
|
if(sourceFluid.getFluid() == Fluids.EMPTY || sourceFluid.getAmount() < 1000){
|
||||||
|
@ -145,4 +135,15 @@ public class FluidUtils {
|
||||||
public static FluidInstance getFluidStackInContainer(@NonNull ItemStack invStack) {
|
public static FluidInstance getFluidStackInContainer(@NonNull ItemStack invStack) {
|
||||||
return null;
|
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