Creative tank will void excessive fluid. Closes #2205

This commit is contained in:
drcrazy 2020-09-10 16:19:39 +03:00
parent 7c4da6e306
commit 1360187f16
6 changed files with 43 additions and 28 deletions

View file

@ -30,11 +30,11 @@ 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 org.jetbrains.annotations.Nullable;
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.FluidValue; import reborncore.common.fluid.FluidValue;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.fluid.container.ItemFluidInfo; 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;
@ -45,8 +45,6 @@ import techreborn.api.generator.FluidGeneratorRecipeList;
import techreborn.api.generator.GeneratorRecipeHelper; import techreborn.api.generator.GeneratorRecipeHelper;
import techreborn.utils.FluidUtils; import techreborn.utils.FluidUtils;
import org.jetbrains.annotations.Nullable;
public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider { public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEntity implements IToolDrop, InventoryProvider {
private final FluidGeneratorRecipeList recipes; private final FluidGeneratorRecipeList recipes;
@ -74,9 +72,15 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
this.ticksSinceLastChange = 0; this.ticksSinceLastChange = 0;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
if (world == null) {
return;
}
ticksSinceLastChange++; ticksSinceLastChange++;
if (world.isClient) { if (world.isClient) {
@ -88,7 +92,7 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
ItemStack inputStack = inventory.getStack(0); ItemStack inputStack = inventory.getStack(0);
if (!inputStack.isEmpty()) { if (!inputStack.isEmpty()) {
if (FluidUtils.isContainerEmpty(inputStack) && !tank.getFluidAmount().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()) { } else if (inputStack.getItem() instanceof ItemFluidInfo && getRecipes().getRecipeForFluid(((ItemFluidInfo) inputStack.getItem()).getFluid(inputStack)).isPresent()) {
FluidUtils.drainContainers(tank, inventory, 0, 1); FluidUtils.drainContainers(tank, inventory, 0, 1);
} }
@ -141,15 +145,6 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
return false; 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() { public FluidGeneratorRecipeList getRecipes() {
return recipes; return recipes;
} }

View file

@ -72,17 +72,19 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
// TileGenericMachine // TileGenericMachine
@Override @Override
public void tick() { public void tick() {
if (world == null){
return;
}
ticksSinceLastChange++; ticksSinceLastChange++;
// Check cells input slot 2 time per second // Check cells input slot 2 time per second
if (!world.isClient && ticksSinceLastChange >= 10) { if (!world.isClient && ticksSinceLastChange >= 10) {
if (!inventory.getStack(1).isEmpty()) { if (!inventory.getStack(1).isEmpty()) {
FluidUtils.fillContainers(tank, inventory, 1, 2, tank.getFluid()); FluidUtils.fillContainers(tank, inventory, 1, 2);
} }
ticksSinceLastChange = 0; ticksSinceLastChange = 0;
} }
super.tick(); super.tick();
} }
@Override @Override

View file

@ -76,12 +76,15 @@ public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity impl
// TilePowerAcceptor // TilePowerAcceptor
@Override @Override
public void tick() { public void tick() {
if (world == null){
return;
}
ticksSinceLastChange++; ticksSinceLastChange++;
// Check cells input slot 2 time per second // Check cells input slot 2 time per second
if (!world.isClient && ticksSinceLastChange >= 10) { if (!world.isClient && ticksSinceLastChange >= 10) {
if (!inventory.getStack(1).isEmpty()) { if (!inventory.getStack(1).isEmpty()) {
FluidUtils.drainContainers(tank, inventory, 1, 6); FluidUtils.drainContainers(tank, inventory, 1, 6);
FluidUtils.fillContainers(tank, inventory, 1, 6, tank.getFluid()); FluidUtils.fillContainers(tank, inventory, 1, 6);
} }
ticksSinceLastChange = 0; ticksSinceLastChange = 0;
} }

View file

@ -76,12 +76,15 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl
// TileGenericMachine // TileGenericMachine
@Override @Override
public void tick() { public void tick() {
if (world == null) {
return;
}
ticksSinceLastChange++; ticksSinceLastChange++;
// Check cells input slot 2 time per second // Check cells input slot 2 time per second
if (!world.isClient && ticksSinceLastChange >= 10) { if (!world.isClient && ticksSinceLastChange >= 10) {
if (!inventory.getStack(1).isEmpty()) { if (!inventory.getStack(1).isEmpty()) {
FluidUtils.drainContainers(tank, inventory, 1, 5); FluidUtils.drainContainers(tank, inventory, 1, 5);
FluidUtils.fillContainers(tank, inventory, 1, 5, tank.getFluidInstance().getFluid()); FluidUtils.fillContainers(tank, inventory, 1, 5);
} }
ticksSinceLastChange = 0; ticksSinceLastChange = 0;
} }

View file

@ -33,6 +33,7 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.WordUtils;
import org.jetbrains.annotations.NotNull;
import reborncore.api.IListInfoProvider; import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop; import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider; import reborncore.api.blockentity.InventoryProvider;
@ -48,7 +49,6 @@ import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import techreborn.utils.FluidUtils; import techreborn.utils.FluidUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider { public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
@ -75,12 +75,16 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
public void tick() { public void tick() {
super.tick(); super.tick();
if (world == null){
return;
}
if (world.isClient()) { if (world.isClient()) {
return; return;
} }
if (FluidUtils.drainContainers(tank, inventory, 0, 1) 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 (type == TRContent.TankUnit.CREATIVE) {
if (!tank.isEmpty() && !tank.isFull()) { if (!tank.isEmpty() && !tank.isFull()) {
@ -89,6 +93,11 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
} }
syncWithAll(); syncWithAll();
} }
// Void excessive fluid in creative tank (#2205)
if (type == TRContent.TankUnit.CREATIVE && tank.isFull()) {
FluidUtils.drainContainers(tank, inventory, 0, 1, true);
}
} }
@Override @Override
@ -129,7 +138,9 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
return this.inventory; return this.inventory;
} }
// IListInfoProvider // IListInfoProvider
@SuppressWarnings("deprecation")
@Override @Override
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) { public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
if (isReal || hasData) { if (isReal || hasData) {

View file

@ -56,6 +56,10 @@ public class FluidUtils {
} }
public static boolean drainContainers(GenericFluidContainer<Direction> target, Inventory inventory, int inputSlot, int outputSlot) { 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 inputStack = inventory.getStack(inputSlot);
ItemStack outputStack = inventory.getStack(outputSlot); 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); inputStack.decrement(1);
targetFluidInstance.setFluid(itemFluidInfo.getFluid(inputStack)); if (!voidFluid) {
targetFluidInstance.addAmount(FluidValue.BUCKET); targetFluidInstance.setFluid(itemFluidInfo.getFluid(inputStack));
targetFluidInstance.addAmount(FluidValue.BUCKET);
}
if (outputStack.isEmpty()) { if (outputStack.isEmpty()) {
inventory.setStack(outputSlot, itemFluidInfo.getEmpty()); inventory.setStack(outputSlot, itemFluidInfo.getEmpty());
} else { } else {
@ -92,7 +97,7 @@ public class FluidUtils {
return true; 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 inputStack = inventory.getStack(inputSlot);
ItemStack outputStack = inventory.getStack(outputSlot); ItemStack outputStack = inventory.getStack(outputSlot);
@ -137,10 +142,6 @@ public class FluidUtils {
return fluid == fluid1; return fluid == fluid1;
} }
public static FluidInstance getFluidStackInContainer(@NotNull ItemStack invStack) {
return null;
}
public static boolean isContainerEmpty(ItemStack inputStack) { public static boolean isContainerEmpty(ItemStack inputStack) {
if (inputStack.isEmpty()) if (inputStack.isEmpty())
return false; return false;