diff options
author | Martin Robertz <dream-master@gmx.net> | 2021-04-03 07:26:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-03 07:26:25 +0200 |
commit | 6a67f90960ef64c53eadf0344603c4b9f911692f (patch) | |
tree | 7f1df9882c130f3fc89c5850d80b0637127d1073 /src | |
parent | 6981d6370945d1e53c96508ddf541c6234383028 (diff) | |
parent | ef3af39da75bb4d4be0d858eea04cd0280603dca (diff) | |
download | GT5-Unofficial-6a67f90960ef64c53eadf0344603c4b9f911692f.tar.gz GT5-Unofficial-6a67f90960ef64c53eadf0344603c4b9f911692f.tar.bz2 GT5-Unofficial-6a67f90960ef64c53eadf0344603c4b9f911692f.zip |
Merge pull request #490 from johnch18/bufferFix
Added sorting of buffer inventories
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java index 7c57076ae9..d462e8adb9 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java @@ -20,7 +20,7 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM private static final int ARROW_UP_INDEX = 4; private static final int FRONT_INDEX = 5; - public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bStockingMode = false; + public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bStockingMode = false, bSortStacks = false; public int mSuccess = 0, mTargetStackSize = 0; public GT_MetaTileEntity_Buffer(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount, String aDescription) { @@ -213,6 +213,7 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM aNBT.setBoolean("bRedstoneIfFull", bRedstoneIfFull); aNBT.setBoolean("bStockingMode", bStockingMode); aNBT.setInteger("mTargetStackSize", mTargetStackSize); + aNBT.setBoolean("bSortStacks", bSortStacks); } @Override @@ -220,9 +221,13 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM bInvert = aNBT.getBoolean("bInvert"); bOutput = aNBT.getBoolean("bOutput"); bRedstoneIfFull = aNBT.getBoolean("bRedstoneIfFull"); + bSortStacks = aNBT.getBoolean("bSortStacks"); if (aNBT.hasKey("bStockingMode")) { // Adding new key to existing NBT, need to protect if it is not there. bStockingMode = aNBT.getBoolean("bStockingMode"); } + if (aNBT.hasKey("bSortStacks")) { + bSortStacks = aNBT.getBoolean("bSortStacks"); + } mTargetStackSize = aNBT.getInteger("mTargetStackSize"); } @@ -250,6 +255,7 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isServerSide() && (aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified() || aTimer % 200 == 0 || mSuccess > 0)) { mSuccess--; + updateSlots(); moveItems(aBaseMetaTileEntity, aTimer); for(byte b = 0;b<6;b++) aBaseMetaTileEntity.setInternalOutputRedstoneSignal(b,bInvert ? (byte)15 : (byte)0); @@ -300,4 +306,31 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM public boolean allowGeneralRedstoneOutput(){ return true; } + + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + if (bSortStacks) { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) + if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) + GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + } + } + + @Override + public boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + // I was so proud of all this but I literally just copied code from OutputBus + bSortStacks = !bSortStacks; + GT_Utility.sendChatToPlayer(aPlayer, trans("200", "Sort mode: " + (bSortStacks ? "Disabled" : "Enabled"))); + return true; + } + return super.onSolderingToolRightClick(aSide,aWrenchingSide,aPlayer,aX,aY,aZ); + } + } |