From d5b3499a520436cfe83447a642d103489fff3518 Mon Sep 17 00:00:00 2001 From: Eldrinn-Elantey <46845681+Eldrinn-Elantey@users.noreply.github.com> Date: Sun, 19 Apr 2026 02:38:33 +0400 Subject: [PATCH 1/3] Aggregate lava tanks and fix fuel display Sum lava across all connected tanks and fix fuel rendering/tooltip. SmelteryLogic: add fuelCapacity, track total fuelAmount and capacity from all lavaTanks, compute fuelGague from totals, and combine tank fluids in getFuel(). LavaTankLogic: use actual filled/drained amounts when adjusting renderOffset. SmelteryGui: call updateFuelDisplay each frame, simplify scrollbar method signature, use getScaledFuelGague(...) for rendering and tooltip bounds, and show current mB / capacity in the fuel tooltip. These changes address incorrect gauge values and rendering when multiple lava tanks are present and correct render offset updates. --- .../tconstruct/smeltery/gui/SmelteryGui.java | 29 +++----- .../smeltery/logic/LavaTankLogic.java | 4 +- .../smeltery/logic/SmelteryLogic.java | 72 +++++++++++++------ 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java index c2019fa3..948a3f1c 100644 --- a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java +++ b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java @@ -44,19 +44,11 @@ public class SmelteryGui extends ActiveContainerGui { 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 +58,13 @@ public class SmelteryGui extends ActiveContainerGui { return; } + 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,12 +138,11 @@ 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) { + int topY = (cornerY + 68) - fuel; + if (mouseX >= leftX && mouseX <= leftX + 12 && mouseY >= topY && mouseY < topY + fuel) { drawFluidStackTooltip(getFuelTooltip(logic.getFuel()), mouseX - cornerX + 36, mouseY - cornerY); } } @@ -170,11 +163,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); @@ -349,7 +342,7 @@ public class SmelteryGui extends ActiveContainerGui { private List getFuelTooltip(FluidStack liquid) { ArrayList list = new ArrayList<>(); list.add("\u00A7f" + StatCollector.translateToLocal("gui.smeltery.fuel")); - list.add("mB: " + liquid.amount); + list.add("mB: " + liquid.amount + " / " + logic.fuelCapacity); return list; } diff --git a/src/main/java/tconstruct/smeltery/logic/LavaTankLogic.java b/src/main/java/tconstruct/smeltery/logic/LavaTankLogic.java index 758b6369..475c8a81 100644 --- a/src/main/java/tconstruct/smeltery/logic/LavaTankLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/LavaTankLogic.java @@ -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()); } diff --git a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java index 5b338e7c..693427b0 100644 --- a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java @@ -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 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,33 @@ 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 : 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); + fuelAmount = totalAmount; + fuelCapacity = totalCapacity; - int capacity = info[0].capacity; - fuelAmount = info[0].fluid.amount; - fuelGague = (int) ((float) fuelAmount * 52f / (float) capacity); + if (totalCapacity > 0) { + fuelGague = (int) ((float) totalAmount * 52f / (float) totalCapacity); + } else { + fuelGague = 0; + } } // actually is updateFuel. @@ -592,15 +605,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 : 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) { From 329fe9b80be4d1c749925540bf5705420760dd07 Mon Sep 17 00:00:00 2001 From: Eldrinn-Elantey <46845681+Eldrinn-Elantey@users.noreply.github.com> Date: Sun, 19 Apr 2026 12:04:07 +0400 Subject: [PATCH 2/3] Throttle fuel updates and prevent CMEs GUI: Add a fuelDisplayTick and only call logic.updateFuelDisplay() every 5 ticks; simplify fuel tooltip to use logic.fuelAmount / logic.fuelCapacity instead of passing a FluidStack. Logic: Iterate over a defensive copy of lavaTanks (new ArrayList<>(lavaTanks)) in updateFuel()/getFuel() to avoid ConcurrentModificationException when the tank list changes during iteration; remove the fuelGague calculation (now using cached fuelAmount/fuelCapacity). These changes reduce update overhead from the GUI and fix crashes related to concurrent modification of the lavaTanks collection. --- src/main/java/tconstruct/smeltery/gui/SmelteryGui.java | 9 +++++---- .../java/tconstruct/smeltery/logic/SmelteryLogic.java | 10 ++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java index 948a3f1c..1e8259db 100644 --- a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java +++ b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java @@ -39,6 +39,7 @@ 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)); @@ -58,7 +59,7 @@ public class SmelteryGui extends ActiveContainerGui { return; } - logic.updateFuelDisplay(); + if (fuelDisplayTick++ % 5 == 0) logic.updateFuelDisplay(); updateScrollbar(mouseX, mouseY); super.drawScreen(mouseX, mouseY, par3); @@ -143,7 +144,7 @@ public class SmelteryGui extends ActiveContainerGui { int leftX = cornerX + 117; int topY = (cornerY + 68) - fuel; if (mouseX >= leftX && mouseX <= leftX + 12 && mouseY >= topY && mouseY < topY + fuel) { - drawFluidStackTooltip(getFuelTooltip(logic.getFuel()), mouseX - cornerX + 36, mouseY - cornerY); + drawFluidStackTooltip(getFuelTooltip(), mouseX - cornerX + 36, mouseY - cornerY); } } } @@ -339,10 +340,10 @@ public class SmelteryGui extends ActiveContainerGui { this.zLevel = 0; } - private List getFuelTooltip(FluidStack liquid) { + private List getFuelTooltip() { ArrayList list = new ArrayList<>(); list.add("\u00A7f" + StatCollector.translateToLocal("gui.smeltery.fuel")); - list.add("mB: " + liquid.amount + " / " + logic.fuelCapacity); + list.add("mB: " + logic.fuelAmount + " / " + logic.fuelCapacity); return list; } diff --git a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java index 693427b0..e1788207 100644 --- a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java @@ -507,7 +507,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci int totalAmount = 0; int totalCapacity = 0; - for (CoordTuple coord : lavaTanks) { + 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); @@ -525,12 +525,6 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci fuelAmount = totalAmount; fuelCapacity = totalCapacity; - - if (totalCapacity > 0) { - fuelGague = (int) ((float) totalAmount * 52f / (float) totalCapacity); - } else { - fuelGague = 0; - } } // actually is updateFuel. @@ -607,7 +601,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci public FluidStack getFuel() { FluidStack combined = null; - for (CoordTuple coord : lavaTanks) { + 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); From 43ab1da6dc5daf00092566c8241f759d458100e1 Mon Sep 17 00:00:00 2001 From: Eldrinn-Elantey <46845681+Eldrinn-Elantey@users.noreply.github.com> Date: Sun, 19 Apr 2026 12:24:52 +0400 Subject: [PATCH 3/3] Format smeltery fuel tooltip Update SmelteryGui.getFuelTooltip to display fuel as "current/capacity mB" instead of "mB: current / capacity" for a more compact and readable tooltip. --- src/main/java/tconstruct/smeltery/gui/SmelteryGui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java index 1e8259db..1d1a1d38 100644 --- a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java +++ b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java @@ -343,7 +343,7 @@ public class SmelteryGui extends ActiveContainerGui { private List getFuelTooltip() { ArrayList list = new ArrayList<>(); list.add("\u00A7f" + StatCollector.translateToLocal("gui.smeltery.fuel")); - list.add("mB: " + logic.fuelAmount + " / " + logic.fuelCapacity); + list.add(logic.fuelAmount + "/" + logic.fuelCapacity + " mB"); return list; }