diff options
author | Martin Robertz <dream-master@gmx.net> | 2020-12-19 22:53:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 22:53:19 +0100 |
commit | 11314ffc91e14d4b2fbc7e5d2bb98e59e0e8ab49 (patch) | |
tree | 7775f7b0a003ff6bd13c3322f8f216f1a45e49b5 /src/main/java | |
parent | 677ca610b6d4789fa71153531d0911008012f7ac (diff) | |
parent | c89cf6b80eb25e842be49090534a2415d9e14534 (diff) | |
download | GT5-Unofficial-11314ffc91e14d4b2fbc7e5d2bb98e59e0e8ab49.tar.gz GT5-Unofficial-11314ffc91e14d4b2fbc7e5d2bb98e59e0e8ab49.tar.bz2 GT5-Unofficial-11314ffc91e14d4b2fbc7e5d2bb98e59e0e8ab49.zip |
Merge pull request #376 from GTNewHorizons/fix-move-items
Fix move items
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java | 14 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Utility.java | 37 |
2 files changed, 42 insertions, 9 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java index c73e95e95b..6ed5a9edd0 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item.java @@ -38,6 +38,7 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE public int mTransferredItems = 0; public byte mLastReceivedFrom = 0, oLastReceivedFrom = 0; public boolean mIsRestrictive = false; + private int[] cacheSides; public GT_MetaPipeEntity_Item(int aID, String aName, String aNameRegional, float aThickNess, Materials aMaterial, int aInvSlotCount, int aStepSize, boolean aIsRestrictive, int aTickTime) { super(aID, aName, aNameRegional, aInvSlotCount, false); @@ -313,6 +314,19 @@ public class GT_MetaPipeEntity_Item extends MetaPipeEntity implements IMetaTileE } @Override + public int[] getAccessibleSlotsFromSide(int aSide) { + IGregTechTileEntity tTileEntity = getBaseMetaTileEntity(); + boolean tAllow = tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity) || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, tTileEntity); + if (tAllow) { + if (cacheSides == null) + cacheSides = super.getAccessibleSlotsFromSide(aSide); + return cacheSides; + } else { + return new int[0]; + } + } + + @Override public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return isConnectedAtSide(aSide); } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 05e0874e7a..3530fa17c2 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -537,24 +537,47 @@ public class GT_Utility { public static int moveMultipleItemStacks(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce,int aMaxStackTransfer, boolean aDoCheckChests) { if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce || aMaxStackTransfer == 0) return 0; - int tGrabInventorySize = aTileEntity1.getSizeInventory(); + + int[] tGrabSlots = null; + if (aTileEntity1 instanceof ISidedInventory) + tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); + if (tGrabSlots == null) { + tGrabSlots = new int[aTileEntity1.getSizeInventory()]; + for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; + } + + + + + int tGrabInventorySize = tGrabSlots.length; if (aTileEntity2 instanceof IInventory) { + int[] tPutSlots = null; + if (aTileEntity2 instanceof ISidedInventory) + tPutSlots = ((ISidedInventory) aTileEntity2).getAccessibleSlotsFromSide(aPutTo); + + if (tPutSlots == null) { + tPutSlots = new int[((IInventory) aTileEntity2).getSizeInventory()]; + for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i; + } + IInventory tPutInventory = (IInventory) aTileEntity2; - int tPutInventorySize = tPutInventory.getSizeInventory(); + int tPutInventorySize = tPutSlots.length; int tFirstsValidSlot = 0,tStacksMoved = 0,tTotalItemsMoved = 0; - for (int tGrabSlot = 0;tGrabSlot<tGrabInventorySize;tGrabSlot++) + for (int tGrabSlotIndex = 0;tGrabSlotIndex<tGrabInventorySize;tGrabSlotIndex++) { //ItemStack tInventoryStack : mInventory int tMovedItems; do { - tMovedItems = 0; + int tGrabSlot = tGrabSlots[tGrabSlotIndex]; + tMovedItems = 0; ItemStack tGrabStack = aTileEntity1.getStackInSlot(tGrabSlot); if (listContainsItem(aFilter, tGrabStack, true, aInvertFilter) && (tGrabStack.stackSize >= aMinMoveAtOnce && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlot, aGrabFrom, tGrabStack))) { int tStackSize = tGrabStack.stackSize; - for (int tPutSlot = tFirstsValidSlot; tPutSlot < tPutInventorySize; tPutSlot++) { + for (int tPutSlotIndex = tFirstsValidSlot; tPutSlotIndex < tPutInventorySize; tPutSlotIndex++) { + int tPutSlot = tPutSlots[tPutSlotIndex]; if (isAllowedToPutIntoSlot(tPutInventory, tPutSlot, aPutTo, tGrabStack, (byte) 64)) { int tMoved = moveStackFromSlotAToSlotB(aTileEntity1, tPutInventory, tGrabSlot, tPutSlot, aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItems), aMinMoveAtOnce); tTotalItemsMoved += tMoved; @@ -609,10 +632,6 @@ public class GT_Utility { } //there should be a function to transfer more then 1 stack in a pipe //ut i dont see any ways to improve it too much work for what it is worth - int[] tGrabSlots = new int[tGrabInventorySize]; - for (int i = 0; i < tGrabInventorySize; i++) { - tGrabSlots[i] = i; - } int tTotalItemsMoved = 0; for (int i = 0; i < tGrabInventorySize; i++) { int tMoved = moveStackIntoPipe(aTileEntity1, aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests); |