Initial move to the fabric fluid API (#2465)
This commit is contained in:
parent
482fe4f01f
commit
fd9d776b43
23 changed files with 239 additions and 211 deletions
|
@ -46,6 +46,7 @@ import reborncore.common.blockentity.MachineBaseBlockEntity;
|
|||
import reborncore.common.fluid.FluidUtil;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.util.FluidTextHelper;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
@ -56,7 +57,7 @@ import java.util.List;
|
|||
|
||||
public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
|
||||
protected Tank tank;
|
||||
private int serverMaxCapacity = -1;
|
||||
private long serverMaxCapacity = -1;
|
||||
|
||||
protected RebornInventory<TankUnitBaseBlockEntity> inventory = new RebornInventory<>(2, "TankInventory", 64, this);
|
||||
|
||||
|
@ -169,7 +170,7 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
info.add(
|
||||
new TranslatableText("techreborn.tooltip.unit.capacity")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(new LiteralText(String.valueOf(this.tank.getCapacity()))
|
||||
.append(new LiteralText(String.valueOf(this.tank.getFluidValueCapacity()))
|
||||
.formatted(Formatting.GOLD))
|
||||
);
|
||||
}
|
||||
|
@ -186,11 +187,11 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
}
|
||||
|
||||
// Sync between server/client if configs are mis-matched.
|
||||
public int getMaxCapacity() {
|
||||
return this.tank.getCapacity().getRawValue();
|
||||
public long getMaxCapacity() {
|
||||
return this.tank.getFluidValueCapacity().getRawValue();
|
||||
}
|
||||
|
||||
public void setMaxCapacity(int maxCapacity) {
|
||||
public void setMaxCapacity(long maxCapacity) {
|
||||
FluidInstance instance = tank.getFluidInstance();
|
||||
this.tank = new Tank("TankStorage", FluidValue.fromRaw(maxCapacity), this);
|
||||
this.tank.setFluidInstance(instance);
|
||||
|
@ -202,9 +203,4 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
public Tank getTank() {
|
||||
return tank;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setTank(Tank tank) {
|
||||
this.tank.setFluid(null, tank.getFluidInstance());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public class TankUnitBlock extends BlockMachineBase {
|
|||
if(amountInTank.equalOrMoreThan(FluidValue.BUCKET)){
|
||||
|
||||
// Amount to transfer is whatever is lower (stack count or tank level)
|
||||
int amountTransferBuckets = Math.min(amountInTank.getRawValue() / FluidValue.BUCKET.getRawValue(), stackInHand.getCount());
|
||||
int amountTransferBuckets = (int) Math.min(amountInTank.getRawValue() / FluidValue.BUCKET.getRawValue(), stackInHand.getCount());
|
||||
|
||||
// Remove items from player
|
||||
stackInHand.decrement(amountTransferBuckets);
|
||||
|
|
|
@ -60,7 +60,7 @@ public class GuiDieselGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
builder.drawMultiEnergyBar(matrixStack, this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
|
|||
super.drawForeground(matrixStack, mouseX, mouseY);
|
||||
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
|
||||
|
||||
builder.drawTank(matrixStack, this, 99, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 99, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
|
||||
|
|
|
@ -57,7 +57,7 @@ public class GuiGasTurbine extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
builder.drawMultiEnergyBar(matrixStack, this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
|
|||
final Layer layer = Layer.FOREGROUND;
|
||||
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
|
||||
} else {
|
||||
|
|
|
@ -71,7 +71,7 @@ public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
|
|||
final Layer layer = Layer.FOREGROUND;
|
||||
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(100), 100, 105, 47, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 53, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
addHologramButton(6, 4, 212, layer).clickHandler(this::onClick);
|
||||
} else {
|
||||
|
|
|
@ -63,7 +63,7 @@ public class GuiPlasmaGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
builder.drawMultiEnergyBar(matrixStack, this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class GuiSemifluidGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
builder.drawMultiEnergyBar(matrixStack, this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public class GuiTankUnit extends GuiBase<BuiltScreenHandler> {
|
|||
textRenderer.draw(matrixStack, new TranslatableText("gui.techreborn.tank.amount"), 10, 50, 4210752);
|
||||
textRenderer.draw(matrixStack, fluid.getAmount().toString(), 10, 60, 4210752);
|
||||
|
||||
String percentFilled = String.valueOf((int) ((double) fluid.getAmount().getRawValue() / (double) tankEntity.getTank().getCapacity().getRawValue() * 100));
|
||||
String percentFilled = String.valueOf((int) ((double) fluid.getAmount().getRawValue() / (double) tankEntity.getTank().getFluidValueCapacity().getRawValue() * 100));
|
||||
|
||||
textRenderer.draw(matrixStack, new TranslatableText("gui.techreborn.unit.used").append(percentFilled + "%"), 10, 70, 4210752);
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class GuiThermalGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
builder.drawProgressBar(matrixStack, this, blockEntity.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
|
||||
builder.drawMultiEnergyBar(matrixStack, this, 130, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
builder.drawTank(matrixStack, this, 44, 25, mouseX, mouseY, blockEntity.tank.getFluidInstance(), blockEntity.tank.getFluidValueCapacity(), blockEntity.tank.isEmpty(), layer);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,13 +29,12 @@ import net.minecraft.fluid.Fluid;
|
|||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.fluid.container.GenericFluidContainer;
|
||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||
import reborncore.common.util.Tank;
|
||||
import reborncore.mixin.common.AccessorFluidBlock;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -55,11 +54,11 @@ public class FluidUtils {
|
|||
return Registry.FLUID.stream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static boolean drainContainers(GenericFluidContainer<Direction> tank, Inventory inventory, int inputSlot, int outputSlot) {
|
||||
public static boolean drainContainers(Tank tank, Inventory inventory, int inputSlot, int outputSlot) {
|
||||
return drainContainers(tank, inventory, inputSlot, outputSlot, false);
|
||||
}
|
||||
|
||||
public static boolean drainContainers(GenericFluidContainer<Direction> tank, Inventory inventory, int inputSlot, int outputSlot, boolean voidFluid) {
|
||||
public static boolean drainContainers(Tank tank, Inventory inventory, int inputSlot, int outputSlot, boolean voidFluid) {
|
||||
ItemStack inputStack = inventory.getStack(inputSlot);
|
||||
ItemStack outputStack = inventory.getStack(outputSlot);
|
||||
|
||||
|
@ -71,11 +70,11 @@ public class FluidUtils {
|
|||
|
||||
if (!outputStack.isEmpty() && !outputStack.isItemEqual(itemFluidInfo.getEmpty())) return false;
|
||||
|
||||
FluidInstance tankFluidInstance = tank.getFluidInstance(null);
|
||||
FluidInstance tankFluidInstance = tank.getFluidInstance();
|
||||
Fluid tankFluid = tankFluidInstance.getFluid();
|
||||
|
||||
if (tankFluidInstance.isEmpty() || tankFluid == itemFluidInfo.getFluid(inputStack)) {
|
||||
FluidValue freeSpace = tank.getCapacity(null).subtract(tankFluidInstance.getAmount());
|
||||
FluidValue freeSpace = tank.getFluidValueCapacity().subtract(tankFluidInstance.getAmount());
|
||||
|
||||
if (freeSpace.equalOrMoreThan(FluidValue.BUCKET) || voidFluid) {
|
||||
inputStack.decrement(1);
|
||||
|
@ -94,13 +93,13 @@ public class FluidUtils {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean fillContainers(GenericFluidContainer<Direction> source, Inventory inventory, int inputSlot, int outputSlot) {
|
||||
public static boolean fillContainers(Tank source, Inventory inventory, int inputSlot, int outputSlot) {
|
||||
ItemStack inputStack = inventory.getStack(inputSlot);
|
||||
ItemStack outputStack = inventory.getStack(outputSlot);
|
||||
|
||||
if (!FluidUtils.isContainerEmpty(inputStack)) return false;
|
||||
ItemFluidInfo itemFluidInfo = (ItemFluidInfo) inputStack.getItem();
|
||||
FluidInstance sourceFluid = source.getFluidInstance(null);
|
||||
FluidInstance sourceFluid = source.getFluidInstance();
|
||||
|
||||
if (sourceFluid.getFluid() == Fluids.EMPTY || sourceFluid.getAmount().lessThan(FluidValue.BUCKET)) {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue