Merge remote-tracking branch 'origin/fix/smeltery-total-fuel-gauge' into dev

This commit is contained in:
Martin Robertz committed 2026-04-19 15:33:24 +02:00
commit 2c101ac824
3 files changed
+60 -46

No files matched your search

@@ -39,24 +39,17 @@ public class SmelteryGui extends ActiveContainerGui {
private final int columns;
private final int smelterySize;
public static final int maxRows = 8;
private int fuelDisplayTick = 0;
public SmelteryGui(InventoryPlayer inventoryplayer, SmelteryLogic smeltery, World world, int x, int y, int z) {
super((ActiveContainer) smeltery.getGuiContainer(inventoryplayer, world, x, y, z));
logic = smeltery;
smelterySize = smeltery.getBlockCapacity();
smeltery.updateFuelDisplay();
columns = ((SmelteryContainer) this.inventorySlots).columns;
xSize = 254 + (columns - 3) * 22; // Adjust for column count
}
@Override
public void initGui() {
super.initGui();
if (logic != null) logic.updateFuelDisplay();
}
@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
// the smeltery changed. we close the screen because updating the changes in all containers would be way too
@@ -66,11 +59,13 @@ public class SmelteryGui extends ActiveContainerGui {
return;
}
if (fuelDisplayTick++ % 5 == 0) logic.updateFuelDisplay();
updateScrollbar(mouseX, mouseY);
super.drawScreen(mouseX, mouseY, par3);
updateScrollbar(mouseX, mouseY, par3);
}
protected void updateScrollbar(int mouseX, int mouseY, float par3) {
protected void updateScrollbar(int mouseX, int mouseY) {
if (smelterySize > columns * maxRows) {
boolean mouseDown = Mouse.isButtonDown(0);
int lefto = this.guiLeft;
@@ -144,13 +139,12 @@ public class SmelteryGui extends ActiveContainerGui {
}
// lava/fuel
if (logic.fuelGague > 0) {
int fuel = logic.getScaledFuelGague(52);
if (fuel > 0) {
int leftX = cornerX + 117;
int topY = (cornerY + 68) - logic.getScaledFuelGague(52);
int sizeX = 12;
int sizeY = logic.getScaledFuelGague(52);
if (mouseX >= leftX && mouseX <= leftX + sizeX && mouseY >= topY && mouseY < topY + sizeY) {
drawFluidStackTooltip(getFuelTooltip(logic.getFuel()), mouseX - cornerX + 36, mouseY - cornerY);
int topY = (cornerY + 68) - fuel;
if (mouseX >= leftX && mouseX <= leftX + 12 && mouseY >= topY && mouseY < topY + fuel) {
drawFluidStackTooltip(getFuelTooltip(), mouseX - cornerX + 36, mouseY - cornerY);
}
}
}
@@ -170,11 +164,11 @@ public class SmelteryGui extends ActiveContainerGui {
// Fuel - Lava
this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
if (logic.fuelGague > 0) {
int fuel = logic.getScaledFuelGague(52);
if (fuel > 0) {
FluidStack fuelStack = logic.getFuel();
IIcon lavaIcon = fuelStack.getFluid().getStillIcon();
if (lavaIcon == null) lavaIcon = Blocks.lava.getIcon(0, 0);
int fuel = logic.getScaledFuelGague(52);
int count = 0;
while (fuel > 0) {
int size = Math.min(fuel, 16);
@@ -346,10 +340,10 @@ public class SmelteryGui extends ActiveContainerGui {
this.zLevel = 0;
}
private List<String> getFuelTooltip(FluidStack liquid) {
private List<String> getFuelTooltip() {
ArrayList<String> list = new ArrayList<>();
list.add("\u00A7f" + StatCollector.translateToLocal("gui.smeltery.fuel"));
list.add("mB: " + liquid.amount);
list.add(logic.fuelAmount + "/" + logic.fuelCapacity + " mB");
return list;
}
@@ -29,7 +29,7 @@ public class LavaTankLogic extends MultiServantLogic implements IFluidHandler {
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
int amount = tank.fill(resource, doFill);
if (amount > 0 && doFill) {
renderOffset += resource.amount;
renderOffset += amount;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, this.getBlockType());
}
@@ -41,7 +41,7 @@ public class LavaTankLogic extends MultiServantLogic implements IFluidHandler {
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
FluidStack amount = tank.drain(maxDrain, doDrain);
if (amount != null && doDrain) {
renderOffset = -maxDrain;
renderOffset = -amount.amount;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, this.getBlockType());
}
@@ -75,6 +75,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
public int useTime;
public int fuelGague;
public int fuelAmount;
public int fuelCapacity;
protected boolean inUse;
protected ArrayList<CoordTuple> lavaTanks;
@@ -262,8 +263,9 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
}
public int getScaledFuelGague(int scale) {
int ret = (fuelGague * scale) / 52;
if (ret < 1) ret = 1;
if (fuelCapacity <= 0) return 0;
int ret = (int) ((float) fuelAmount * (float) scale / (float) fuelCapacity);
if (ret < 1 && fuelAmount > 0) ret = 1;
return ret;
}
@@ -502,22 +504,27 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
}
public void updateFuelDisplay() {
// ensure our active tank is valid
verifyFuelTank();
if (activeLavaTank == null) {
fuelAmount = 0;
fuelGague = 0;
return;
int totalAmount = 0;
int totalCapacity = 0;
for (CoordTuple coord : new ArrayList<>(lavaTanks)) {
if (!worldObj.blockExists(coord.x, coord.y, coord.z)) continue;
TileEntity te = worldObj.getTileEntity(coord.x, coord.y, coord.z);
if (!(te instanceof IFluidHandler)) continue;
FluidTankInfo[] info = ((IFluidHandler) te).getTankInfo(ForgeDirection.DOWN);
if (info.length <= 0) continue;
totalCapacity += info[0].capacity;
if (info[0].fluid != null && info[0].fluid.amount > 0) {
totalAmount += info[0].fluid.amount;
}
}
// checks are all done before in verifyFuelTank. Don't do this without checks!
IFluidHandler tankContainer = (IFluidHandler) worldObj
.getTileEntity(activeLavaTank.x, activeLavaTank.y, activeLavaTank.z);
FluidTankInfo[] info = tankContainer.getTankInfo(ForgeDirection.DOWN);
int capacity = info[0].capacity;
fuelAmount = info[0].fluid.amount;
fuelGague = (int) ((float) fuelAmount * 52f / (float) capacity);
fuelAmount = totalAmount;
fuelCapacity = totalCapacity;
}
// actually is updateFuel.
@@ -592,15 +599,28 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
@SideOnly(Side.CLIENT)
public FluidStack getFuel() {
if (activeLavaTank == null)
// sane default
FluidStack combined = null;
for (CoordTuple coord : new ArrayList<>(lavaTanks)) {
if (!worldObj.blockExists(coord.x, coord.y, coord.z)) continue;
TileEntity te = worldObj.getTileEntity(coord.x, coord.y, coord.z);
if (!(te instanceof IFluidHandler)) continue;
FluidTankInfo[] info = ((IFluidHandler) te).getTankInfo(ForgeDirection.DOWN);
if (info.length <= 0 || info[0].fluid == null || info[0].fluid.amount <= 0) continue;
if (combined == null) {
combined = info[0].fluid.copy();
} else if (combined.isFluidEqual(info[0].fluid)) {
combined.amount += info[0].fluid.amount;
}
}
if (combined == null) {
return new FluidStack(FluidRegistry.LAVA, 0);
TileEntity tankContainer = worldObj.getTileEntity(activeLavaTank.x, activeLavaTank.y, activeLavaTank.z);
if (tankContainer instanceof IFluidHandler)
return ((IFluidHandler) tankContainer).getTankInfo(ForgeDirection.DOWN)[0].fluid;
return new FluidStack(FluidRegistry.LAVA, 0);
}
return combined;
}
public FluidStack getResultFor(ItemStack stack) {