diff --git a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java index c804c6c4c03..9b7d848d2ac 100644 --- a/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java +++ b/src/main/java/tconstruct/smeltery/gui/SmelteryGui.java @@ -28,12 +28,14 @@ public class SmelteryGui extends ActiveContainerGui private int prevSlotPos = 0; private final int columns; + private final int smelterySize; public static final int maxRows = 8; 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; @@ -52,13 +54,20 @@ public void initGui () @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 complicated. + if(logic.getBlockCapacity() != smelterySize) + { + mc.thePlayer.closeScreen(); + return; + } + super.drawScreen(mouseX, mouseY, par3); updateScrollbar(mouseX, mouseY, par3); } protected void updateScrollbar (int mouseX, int mouseY, float par3) { - if (logic.getBlockCapacity() > columns * maxRows) + if (smelterySize > columns * maxRows) { boolean mouseDown = Mouse.isButtonDown(0); int lefto = this.guiLeft; @@ -217,13 +226,13 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) // Side inventory int xleft = 46; xleft += 22 * (columns - 3); // we have to shift the whole thing to the left if we have more than 3 columns - int h = logic.getBlockCapacity() / columns; - if (logic.getBlockCapacity() % columns != 0) + int h = smelterySize / columns; + if (smelterySize % columns != 0) h++; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(backgroundSide); - if (logic.getBlockCapacity() > 0) + if (smelterySize > 0) { if (h >= 8) { @@ -269,11 +278,11 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY) xleft -= 8; // Temperature - int slotSize = logic.getBlockCapacity(); + int slotSize = smelterySize; if (slotSize > columns * maxRows) slotSize = columns * maxRows; int iter; - for (iter = 0; iter < slotSize && iter + slotPos * columns < logic.getBlockCapacity(); iter++) + for (iter = 0; iter < slotSize && iter + slotPos * columns < smelterySize; iter++) { int slotTemp = logic.getTempForSlot(iter + slotPos * columns) - 20; int maxTemp = logic.getMeltingPointForSlot(iter + slotPos * columns) - 20; diff --git a/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java b/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java index 3bce0146cd8..e26fec83c53 100644 --- a/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java +++ b/src/main/java/tconstruct/smeltery/inventory/SmelteryContainer.java @@ -15,6 +15,7 @@ public class SmelteryContainer extends ActiveContainer public int fuel = 0; private int slotRow; public int columns; + public final int smelterySize; public SmelteryContainer(InventoryPlayer inventoryplayer, SmelteryLogic smeltery) { @@ -22,6 +23,7 @@ public SmelteryContainer(InventoryPlayer inventoryplayer, SmelteryLogic smeltery playerInv = inventoryplayer; slotRow = 0; columns = smeltery.getBlocksPerLayer() >= 16 ? 4 : 3; + smelterySize = smeltery.getBlockCapacity(); /* Smeltery inventory */ @@ -96,7 +98,9 @@ public int scrollTo (float scrollPos) @Override public void detectAndSendChanges () // TODO: Sync with this { - super.detectAndSendChanges(); + // we only update if the size is the same, since the screen is getting closed on sizechange and would cause a crash otherwise + if(smelterySize == this.inventorySlots.size()) + super.detectAndSendChanges(); /* * for (int i = 0; i < crafters.size(); i++) { ICrafting icrafting = * (ICrafting)crafters.get(i); if (progress != logic.progress) { @@ -145,14 +149,14 @@ public ItemStack transferStackInSlot (EntityPlayer player, int slotID) ItemStack slotStack = slot.getStack(); stack = slotStack.copy(); - if (slotID < logic.getSizeInventory()) + if (slotID < smelterySize) { if (!this.mergeItemStack(slotStack, logic.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } - else if (!this.mergeItemStack(slotStack, 0, logic.getSizeInventory(), false)) + else if (!this.mergeItemStack(slotStack, 0, smelterySize, false)) { return null; }