Creative tank will void excessive fluid. Closes #2205
This commit is contained in:
parent
7c4da6e306
commit
1360187f16
6 changed files with 43 additions and 28 deletions
|
@ -30,11 +30,11 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
|
@ -45,8 +45,6 @@ import techreborn.api.generator.FluidGeneratorRecipeList;
|
|||
import techreborn.api.generator.GeneratorRecipeHelper;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider {
|
||||
|
||||
private final FluidGeneratorRecipeList recipes;
|
||||
|
@ -74,9 +72,15 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
|
|||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ticksSinceLastChange++;
|
||||
|
||||
if (world.isClient) {
|
||||
|
@ -88,7 +92,7 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
|
|||
ItemStack inputStack = inventory.getStack(0);
|
||||
if (!inputStack.isEmpty()) {
|
||||
if (FluidUtils.isContainerEmpty(inputStack) && !tank.getFluidAmount().isEmpty()) {
|
||||
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid());
|
||||
FluidUtils.fillContainers(tank, inventory, 0, 1);
|
||||
} else if (inputStack.getItem() instanceof ItemFluidInfo && getRecipes().getRecipeForFluid(((ItemFluidInfo) inputStack.getItem()).getFluid(inputStack)).isPresent()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 0, 1);
|
||||
}
|
||||
|
@ -141,15 +145,6 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean acceptFluid() {
|
||||
if (!inventory.getStack(0).isEmpty()) {
|
||||
FluidInstance stack = FluidUtils.getFluidStackInContainer(inventory.getStack(0));
|
||||
if (stack != null)
|
||||
return recipes.getRecipeForFluid(stack.getFluid()).isPresent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public FluidGeneratorRecipeList getRecipes() {
|
||||
return recipes;
|
||||
}
|
||||
|
|
|
@ -72,17 +72,19 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
|
|||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world == null){
|
||||
return;
|
||||
}
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getStack(1).isEmpty()) {
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 2, tank.getFluid());
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 2);
|
||||
}
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
super.tick();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,12 +76,15 @@ public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity impl
|
|||
// TilePowerAcceptor
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world == null){
|
||||
return;
|
||||
}
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getStack(1).isEmpty()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 1, 6);
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 6, tank.getFluid());
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 6);
|
||||
}
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
|
|
@ -76,12 +76,15 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl
|
|||
// TileGenericMachine
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
ticksSinceLastChange++;
|
||||
// Check cells input slot 2 time per second
|
||||
if (!world.isClient && ticksSinceLastChange >= 10) {
|
||||
if (!inventory.getStack(1).isEmpty()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 1, 5);
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 5, tank.getFluidInstance().getFluid());
|
||||
FluidUtils.fillContainers(tank, inventory, 1, 5);
|
||||
}
|
||||
ticksSinceLastChange = 0;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import net.minecraft.text.Text;
|
|||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import reborncore.api.IListInfoProvider;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.blockentity.InventoryProvider;
|
||||
|
@ -48,7 +49,6 @@ import techreborn.init.TRBlockEntities;
|
|||
import techreborn.init.TRContent;
|
||||
import techreborn.utils.FluidUtils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
|
||||
|
@ -75,12 +75,16 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (world == null){
|
||||
return;
|
||||
}
|
||||
|
||||
if (world.isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (FluidUtils.drainContainers(tank, inventory, 0, 1)
|
||||
|| FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid())) {
|
||||
|| FluidUtils.fillContainers(tank, inventory, 0, 1)) {
|
||||
|
||||
if (type == TRContent.TankUnit.CREATIVE) {
|
||||
if (!tank.isEmpty() && !tank.isFull()) {
|
||||
|
@ -89,6 +93,11 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
}
|
||||
syncWithAll();
|
||||
}
|
||||
|
||||
// Void excessive fluid in creative tank (#2205)
|
||||
if (type == TRContent.TankUnit.CREATIVE && tank.isFull()) {
|
||||
FluidUtils.drainContainers(tank, inventory, 0, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -129,7 +138,9 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
return this.inventory;
|
||||
}
|
||||
|
||||
|
||||
// IListInfoProvider
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
|
||||
if (isReal || hasData) {
|
||||
|
|
|
@ -56,6 +56,10 @@ public class FluidUtils {
|
|||
}
|
||||
|
||||
public static boolean drainContainers(GenericFluidContainer<Direction> target, Inventory inventory, int inputSlot, int outputSlot) {
|
||||
return drainContainers(target, inventory, inputSlot, outputSlot, false);
|
||||
}
|
||||
|
||||
public static boolean drainContainers(GenericFluidContainer<Direction> target, Inventory inventory, int inputSlot, int outputSlot, boolean voidFluid) {
|
||||
ItemStack inputStack = inventory.getStack(inputSlot);
|
||||
ItemStack outputStack = inventory.getStack(outputSlot);
|
||||
|
||||
|
@ -76,11 +80,12 @@ public class FluidUtils {
|
|||
}
|
||||
}
|
||||
|
||||
if (freeSpace.equalOrMoreThan(FluidValue.BUCKET)) {
|
||||
if (freeSpace.equalOrMoreThan(FluidValue.BUCKET) || voidFluid) {
|
||||
inputStack.decrement(1);
|
||||
targetFluidInstance.setFluid(itemFluidInfo.getFluid(inputStack));
|
||||
targetFluidInstance.addAmount(FluidValue.BUCKET);
|
||||
|
||||
if (!voidFluid) {
|
||||
targetFluidInstance.setFluid(itemFluidInfo.getFluid(inputStack));
|
||||
targetFluidInstance.addAmount(FluidValue.BUCKET);
|
||||
}
|
||||
if (outputStack.isEmpty()) {
|
||||
inventory.setStack(outputSlot, itemFluidInfo.getEmpty());
|
||||
} else {
|
||||
|
@ -92,7 +97,7 @@ public class FluidUtils {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean fillContainers(GenericFluidContainer<Direction> source, Inventory inventory, int inputSlot, int outputSlot, Fluid fluidToFill) {
|
||||
public static boolean fillContainers(GenericFluidContainer<Direction> source, Inventory inventory, int inputSlot, int outputSlot) {
|
||||
ItemStack inputStack = inventory.getStack(inputSlot);
|
||||
ItemStack outputStack = inventory.getStack(outputSlot);
|
||||
|
||||
|
@ -137,10 +142,6 @@ public class FluidUtils {
|
|||
return fluid == fluid1;
|
||||
}
|
||||
|
||||
public static FluidInstance getFluidStackInContainer(@NotNull ItemStack invStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isContainerEmpty(ItemStack inputStack) {
|
||||
if (inputStack.isEmpty())
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue