Skip to content

Commit

Permalink
Fix dupe bug with increasing smeltery size while gui is open. #1218 A…
Browse files Browse the repository at this point in the history
…dditionally GUI now closes on smeltery size change, to prevent a crash when it's made smaller. And for consistency.
  • Loading branch information
bonii-xx committed Dec 7, 2014
1 parent 6e3f6e1 commit fcb4b1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 15 additions & 6 deletions src/main/java/tconstruct/smeltery/gui/SmelteryGui.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -15,13 +15,15 @@ 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)
{
logic = smeltery;
playerInv = inventoryplayer;
slotRow = 0;
columns = smeltery.getBlocksPerLayer() >= 16 ? 4 : 3;
smelterySize = smeltery.getBlockCapacity();

/* Smeltery inventory */

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit fcb4b1f

Please sign in to comment.