Move most int fluid values to FluidValue.

This has been done to make it easier in the future to move to a new fluid system.
Some work is still needed (in recipes mainly) to move away fully away from mb. This should work identically to the old system for now.
This commit is contained in:
modmuss50 2019-12-12 12:42:33 +00:00
parent 2fe94ddbf0
commit 5e5e997b93
19 changed files with 125 additions and 130 deletions

View file

@ -32,6 +32,7 @@ import org.apache.commons.lang3.Validate;
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;
@ -62,7 +63,7 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
*/
double pendingWithdraw = 0.0;
public BaseFluidGeneratorBlockEntity(BlockEntityType<?> blockEntityType, EFluidGenerator type, String blockEntityName, int tankCapacity, int euTick) {
public BaseFluidGeneratorBlockEntity(BlockEntityType<?> blockEntityType, EFluidGenerator type, String blockEntityName, FluidValue tankCapacity, int euTick) {
super(blockEntityType);
recipes = GeneratorRecipeHelper.getFluidRecipesForGenerator(type);
Validate.notNull(recipes, "null recipe list for " + type.getRecipeID());
@ -85,7 +86,7 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
if (ticksSinceLastChange >= 10) {
ItemStack inputStack = inventory.getInvStack(0);
if (!inputStack.isEmpty()) {
if (FluidUtils.isContainerEmpty(inputStack) && tank.getFluidAmount() > 0) {
if (FluidUtils.isContainerEmpty(inputStack) && !tank.getFluidAmount().isEmpty()) {
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluid());
}
else if (inputStack.getItem() instanceof ItemFluidInfo && getRecipes().getRecipeForFluid(((ItemFluidInfo) inputStack.getItem()).getFluid(inputStack)).isPresent()) {
@ -96,19 +97,19 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
ticksSinceLastChange = 0;
}
if (tank.getFluidAmount() > 0) {
if (!tank.getFluidAmount().isEmpty()) {
if (currentRecipe == null || !FluidUtils.fluidEquals(currentRecipe.getFluid(), tank.getFluid()))
currentRecipe = getRecipes().getRecipeForFluid(tank.getFluid()).orElse(null);
if (currentRecipe != null) {
final Integer euPerBucket = currentRecipe.getEnergyPerMb() * 1000;
final int euPerBucket = currentRecipe.getEnergyPerBucket();
final float millibucketsPerTick = euTick * 1000 / (float) euPerBucket;
if (tryAddingEnergy(euTick)) {
pendingWithdraw += millibucketsPerTick;
final int currentWithdraw = (int) pendingWithdraw;
pendingWithdraw -= currentWithdraw;
tank.getFluidInstance().subtractAmount(currentWithdraw);
tank.getFluidInstance().subtractAmount(FluidValue.fromRaw(currentWithdraw));
lastOutput = world.getTime();
}
}
@ -205,11 +206,11 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
this.ticksSinceLastChange = ticksSinceLastChange;
}
public int getTankAmount(){
public FluidValue getTankAmount(){
return tank.getFluidAmount();
}
public void setTankAmount(int amount){
public void setTankAmount(FluidValue amount){
tank.setFluidAmount(amount);
}

View file

@ -29,6 +29,7 @@ import net.minecraft.item.ItemStack;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import techreborn.api.generator.EFluidGenerator;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
@ -37,7 +38,7 @@ import techreborn.init.TRContent;
public class PlasmaGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
public PlasmaGeneratorBlockEntity() {
super(TRBlockEntities.PLASMA_GENERATOR, EFluidGenerator.PLASMA, "PlasmaGeneratorBlockEntity", TechRebornConfig.plasmaGeneratorTankCapacity, TechRebornConfig.plasmaGeneratorEnergyPerTick);
super(TRBlockEntities.PLASMA_GENERATOR, EFluidGenerator.PLASMA, "PlasmaGeneratorBlockEntity", FluidValue.BUCKET.multiply(10), TechRebornConfig.plasmaGeneratorEnergyPerTick);
}
@Override

View file

@ -29,6 +29,7 @@ import net.minecraft.item.ItemStack;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import techreborn.api.generator.EFluidGenerator;
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
import techreborn.config.TechRebornConfig;
@ -38,7 +39,7 @@ import techreborn.init.TRContent;
public class DieselGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
public DieselGeneratorBlockEntity() {
super(TRBlockEntities.DIESEL_GENERATOR, EFluidGenerator.DIESEL, "DieselGeneratorBlockEntity", TechRebornConfig.dieselGeneratorTankCapacity, TechRebornConfig.dieselGeneratorEnergyPerTick);
super(TRBlockEntities.DIESEL_GENERATOR, EFluidGenerator.DIESEL, "DieselGeneratorBlockEntity", FluidValue.BUCKET.multiply(10), TechRebornConfig.dieselGeneratorEnergyPerTick);
}
@Override

View file

@ -29,6 +29,7 @@ import net.minecraft.item.ItemStack;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import techreborn.api.generator.EFluidGenerator;
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
import techreborn.config.TechRebornConfig;
@ -38,7 +39,7 @@ import techreborn.init.TRContent;
public class GasTurbineBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
public GasTurbineBlockEntity() {
super(TRBlockEntities.GAS_TURBINE, EFluidGenerator.GAS, "GasTurbineBlockEntity", TechRebornConfig.gasTurbineTankCapacity, TechRebornConfig.gasTurbineEnergyPerTick);
super(TRBlockEntities.GAS_TURBINE, EFluidGenerator.GAS, "GasTurbineBlockEntity", FluidValue.BUCKET.multiply(10), TechRebornConfig.gasTurbineEnergyPerTick);
}
@Override

View file

@ -29,6 +29,7 @@ import net.minecraft.item.ItemStack;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import techreborn.api.generator.EFluidGenerator;
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
import techreborn.config.TechRebornConfig;
@ -38,7 +39,7 @@ import techreborn.init.TRContent;
public class SemiFluidGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
public SemiFluidGeneratorBlockEntity() {
super(TRBlockEntities.SEMI_FLUID_GENERATOR, EFluidGenerator.SEMIFLUID, "SemiFluidGeneratorBlockEntity", TechRebornConfig.semiFluidGeneratorTankCapacity, TechRebornConfig.semiFluidGeneratorEnergyPerTick);
super(TRBlockEntities.SEMI_FLUID_GENERATOR, EFluidGenerator.SEMIFLUID, "SemiFluidGeneratorBlockEntity", FluidValue.BUCKET.multiply(10), TechRebornConfig.semiFluidGeneratorEnergyPerTick);
}
@Override

View file

@ -29,6 +29,7 @@ import net.minecraft.item.ItemStack;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import techreborn.api.generator.EFluidGenerator;
import techreborn.blockentity.generator.BaseFluidGeneratorBlockEntity;
import techreborn.config.TechRebornConfig;
@ -38,7 +39,7 @@ import techreborn.init.TRContent;
public class ThermalGeneratorBlockEntity extends BaseFluidGeneratorBlockEntity implements IContainerProvider {
public ThermalGeneratorBlockEntity() {
super(TRBlockEntities.THERMAL_GEN, EFluidGenerator.THERMAL, "ThermalGeneratorBlockEntity", TechRebornConfig.thermalGeneratorTankCapacity, TechRebornConfig.thermalGeneratorEnergyPerTick);
super(TRBlockEntities.THERMAL_GEN, EFluidGenerator.THERMAL, "ThermalGeneratorBlockEntity", FluidValue.BUCKET.multiply(10), TechRebornConfig.thermalGeneratorEnergyPerTick);
}
@Override

View file

@ -30,6 +30,7 @@ import net.minecraft.util.math.BlockPos;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.IInventoryAccess;
import reborncore.common.util.RebornInventory;
@ -50,7 +51,7 @@ import javax.annotation.Nullable;
public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
public MultiblockChecker multiblockChecker;
public static final int TANK_CAPACITY = 16_000;
public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16);
public Tank tank;
int ticksSinceLastChange;

View file

@ -34,6 +34,7 @@ import net.minecraft.util.math.Direction;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.Tank;
@ -48,7 +49,7 @@ import javax.annotation.Nullable;
public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity implements IContainerProvider{
public static final int TANK_CAPACITY = 16_000;
public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16);
public Tank tank;
public MultiblockChecker multiblockChecker;
int ticksSinceLastChange;

View file

@ -34,6 +34,7 @@ import net.minecraft.util.math.Direction;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.fluid.FluidValue;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.Tank;
@ -48,7 +49,7 @@ import javax.annotation.Nullable;
public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
public static final int TANK_CAPACITY = 16_000;
public static final FluidValue TANK_CAPACITY = FluidValue.BUCKET.multiply(16);
public Tank tank;
public MultiblockChecker multiblockChecker;
int ticksSinceLastChange;

View file

@ -24,6 +24,7 @@
package techreborn.blockentity.machine.tier3;
import reborncore.common.fluid.FluidValue;
import techreborn.init.TRBlockEntities;
public class CreativeQuantumTankBlockEntity extends QuantumTankBlockEntity {
@ -36,7 +37,7 @@ public class CreativeQuantumTankBlockEntity extends QuantumTankBlockEntity {
public void tick() {
super.tick();
if (!tank.isEmpty() && !tank.isFull()) {
tank.setFluidAmount(Integer.MAX_VALUE);
tank.setFluidAmount(FluidValue.INFINITE);
}
}

View file

@ -37,6 +37,7 @@ import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.fluid.FluidValue;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.Tank;
import techreborn.config.TechRebornConfig;
@ -50,7 +51,7 @@ import java.util.List;
public class QuantumTankBlockEntity extends MachineBaseBlockEntity
implements InventoryProvider, IToolDrop, IListInfoProvider, IContainerProvider {
public Tank tank = new Tank("QuantumTankBlockEntity", TechRebornConfig.quantumTankMaxStorage, this);
public Tank tank = new Tank("QuantumTankBlockEntity", FluidValue.INFINITE, this);
public RebornInventory<QuantumTankBlockEntity> inventory = new RebornInventory<>(3, "QuantumTankBlockEntity", 64, this);
public QuantumTankBlockEntity(){
@ -132,7 +133,7 @@ public class QuantumTankBlockEntity extends MachineBaseBlockEntity
info.add(new LiteralText("Empty"));
}
}
info.add(new LiteralText("Capacity " + this.tank.getCapacity() + " mb"));
info.add(new LiteralText("Capacity " + this.tank.getCapacity()));
}
// IContainerProvider