diff options
author | Richard Hendricks <richardhendricks@pobox.com> | 2018-05-30 02:05:45 -0500 |
---|---|---|
committer | Richard Hendricks <richardhendricks@pobox.com> | 2018-05-30 02:05:45 -0500 |
commit | 715cd53f69a7940996c7c7c9e99539fa023d4615 (patch) | |
tree | d988c50d8e5bcd5e0b76177e4b9d7461f123ffbd /src/main/java/gregtech/common/tileentities/automation | |
parent | 032a77dac00ca4ec98a7af3f16d7f99191727d60 (diff) | |
download | GT5-Unofficial-715cd53f69a7940996c7c7c9e99539fa023d4615.tar.gz GT5-Unofficial-715cd53f69a7940996c7c7c9e99539fa023d4615.tar.bz2 GT5-Unofficial-715cd53f69a7940996c7c7c9e99539fa023d4615.zip |
Some fixes. Only update if inventory actually changes. Sort inventory first, then bubble out nulls after.
Diffstat (limited to 'src/main/java/gregtech/common/tileentities/automation')
-rw-r--r-- | src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java index 7385bb31b1..2450b392d2 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java @@ -49,19 +49,41 @@ public class GT_MetaTileEntity_ChestBuffer } protected void moveItems(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - fillStacksIntoFirstSlots(); + if(aBaseMetaTileEntity.hasInventoryBeenModified()) + { + fillStacksIntoFirstSlots(); + } super.moveItems(aBaseMetaTileEntity, aTimer); - fillStacksIntoFirstSlots(); + if(mSuccess == 50) { + fillStacksIntoFirstSlots(); + } } protected void fillStacksIntoFirstSlots() { for (int i = 0; i < this.mInventory.length - 1; i++) { for (int j = i + 1; j < this.mInventory.length - 1; j++) { - if ((this.mInventory[j] != null) && ((this.mInventory[i] == null) || (GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j])))) { +// if ((this.mInventory[j] != null) && ((this.mInventory[i] == null) || (GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j])))) { + if ((this.mInventory[j] != null) && ((GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j])))) { GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); } } } + // Find first non-null item from the tail + int lastValid; + for( lastValid = this.mInventory.length-1; lastValid >0; lastValid-- ) { + if(this.mInventory[lastValid] == null) { + continue; + } + break; + } + // Go back to the start of the array, swapping any nulls with the last valid item and move last valid item down 1 + for (int i = lastValid; i >= 0; i-- ) { + if(this.mInventory[i] == null) { + //Swap the current null with the last valid item + GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), lastValid, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + lastValid --; + } + } } public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { |