diff options
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_CircuitryBehavior.java | 100 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java | 2 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Utility.java | 52 |
3 files changed, 76 insertions, 78 deletions
diff --git a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java index b7ded54d64..2813df0973 100644 --- a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java @@ -1,5 +1,7 @@ package gregtech.api.util; +import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES; + import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; @@ -31,17 +33,17 @@ public abstract class GT_CircuitryBehavior { /** * returns if there is Redstone applied to any of the valid Inputs (OR) */ - public static final boolean getAnyRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { - for (byte i = 0; i < 6; i++) { - if (i != aRedstoneCircuitBlock.getOutputFacing() + public static boolean getAnyRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + for (byte side : ALL_VALID_SIDES) { + if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock - .getCover(i) + .getCover(side) .letsRedstoneGoIn( - i, - aRedstoneCircuitBlock.getCoverID(i), - aRedstoneCircuitBlock.getCoverVariable(i), + side, + aRedstoneCircuitBlock.getCoverID(side), + aRedstoneCircuitBlock.getCoverVariable(side), aRedstoneCircuitBlock.getOwnTileEntity())) { - if (aRedstoneCircuitBlock.getInputRedstone(i) > 0) { + if (aRedstoneCircuitBlock.getInputRedstone(side) > 0) { return true; } } @@ -52,17 +54,17 @@ public abstract class GT_CircuitryBehavior { /** * returns if there is Redstone applied to all the valid Inputs (AND) */ - public static final boolean getAllRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { - for (byte i = 0; i < 6; i++) { - if (i != aRedstoneCircuitBlock.getOutputFacing() + public static boolean getAllRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + for (byte side : ALL_VALID_SIDES) { + if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock - .getCover(i) + .getCover(side) .letsRedstoneGoIn( - i, - aRedstoneCircuitBlock.getCoverID(i), - aRedstoneCircuitBlock.getCoverVariable(i), + side, + aRedstoneCircuitBlock.getCoverID(side), + aRedstoneCircuitBlock.getCoverVariable(side), aRedstoneCircuitBlock.getOwnTileEntity())) { - if (aRedstoneCircuitBlock.getInputRedstone(i) == 0) { + if (aRedstoneCircuitBlock.getInputRedstone(side) == 0) { return false; } } @@ -73,18 +75,18 @@ public abstract class GT_CircuitryBehavior { /** * returns if there is Redstone applied to exactly one of the valid Inputs (XOR) */ - public static final boolean getOneRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + public static boolean getOneRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { int tRedstoneAmount = 0; - for (byte i = 0; i < 6; i++) { - if (i != aRedstoneCircuitBlock.getOutputFacing() + for (byte side : ALL_VALID_SIDES) { + if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock - .getCover(i) + .getCover(side) .letsRedstoneGoIn( - i, - aRedstoneCircuitBlock.getCoverID(i), - aRedstoneCircuitBlock.getCoverVariable(i), + side, + aRedstoneCircuitBlock.getCoverID(side), + aRedstoneCircuitBlock.getCoverVariable(side), aRedstoneCircuitBlock.getOwnTileEntity())) { - if (aRedstoneCircuitBlock.getInputRedstone(i) > 0) { + if (aRedstoneCircuitBlock.getInputRedstone(side) > 0) { tRedstoneAmount++; } } @@ -95,18 +97,18 @@ public abstract class GT_CircuitryBehavior { /** * returns the strongest incoming RS-Power */ - public static final byte getStrongestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + public static byte getStrongestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { byte tRedstoneAmount = 0; - for (byte i = 0; i < 6; i++) { - if (i != aRedstoneCircuitBlock.getOutputFacing() + for (byte side : ALL_VALID_SIDES) { + if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock - .getCover(i) + .getCover(side) .letsRedstoneGoIn( - i, - aRedstoneCircuitBlock.getCoverID(i), - aRedstoneCircuitBlock.getCoverVariable(i), + side, + aRedstoneCircuitBlock.getCoverID(side), + aRedstoneCircuitBlock.getCoverVariable(side), aRedstoneCircuitBlock.getOwnTileEntity())) { - tRedstoneAmount = (byte) Math.max(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(i)); + tRedstoneAmount = (byte) Math.max(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(side)); } } return tRedstoneAmount; @@ -119,20 +121,20 @@ public abstract class GT_CircuitryBehavior { /** * returns the weakest incoming non-zero RS-Power */ - public static final byte getWeakestNonZeroRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + public static byte getWeakestNonZeroRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { if (!getAnyRedstone(aRedstoneCircuitBlock)) return 0; byte tRedstoneAmount = 15; - for (byte i = 0; i < 6; i++) { - if (i != aRedstoneCircuitBlock.getOutputFacing() + for (byte side : ALL_VALID_SIDES) { + if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock - .getCover(i) + .getCover(side) .letsRedstoneGoIn( - i, - aRedstoneCircuitBlock.getCoverID(i), - aRedstoneCircuitBlock.getCoverVariable(i), + side, + aRedstoneCircuitBlock.getCoverID(side), + aRedstoneCircuitBlock.getCoverVariable(side), aRedstoneCircuitBlock.getOwnTileEntity())) { - if (aRedstoneCircuitBlock.getInputRedstone(i) > 0) - tRedstoneAmount = (byte) Math.min(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(i)); + if (aRedstoneCircuitBlock.getInputRedstone(side) > 0) + tRedstoneAmount = (byte) Math.min(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(side)); } } return tRedstoneAmount; @@ -141,19 +143,19 @@ public abstract class GT_CircuitryBehavior { /** * returns the weakest incoming RS-Power */ - public static final byte getWeakestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + public static byte getWeakestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { if (!getAnyRedstone(aRedstoneCircuitBlock)) return 0; byte tRedstoneAmount = 15; - for (byte i = 0; i < 6; i++) { - if (i != aRedstoneCircuitBlock.getOutputFacing() + for (byte side : ALL_VALID_SIDES) { + if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock - .getCover(i) + .getCover(side) .letsRedstoneGoIn( - i, - aRedstoneCircuitBlock.getCoverID(i), - aRedstoneCircuitBlock.getCoverVariable(i), + side, + aRedstoneCircuitBlock.getCoverID(side), + aRedstoneCircuitBlock.getCoverVariable(side), aRedstoneCircuitBlock.getOwnTileEntity())) { - tRedstoneAmount = (byte) Math.min(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(i)); + tRedstoneAmount = (byte) Math.min(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(side)); } } return tRedstoneAmount; diff --git a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java index 8991289a78..12505dff31 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java @@ -62,7 +62,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { return createDataObject(((NBTTagInt) aNBT).func_150287_d()); } - T ret = createDataObject(); + final T ret = createDataObject(); ret.loadDataFromNBT(aNBT); return ret; } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index cfa261c321..ee4a92b1a4 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -798,11 +798,11 @@ public class GT_Utility { || aMaxStackTransfer == 0) return 0; // find where to take from - int[] tGrabSlots = new int[aTileEntity1.getSizeInventory()]; + final int[] tGrabSlots = new int[aTileEntity1.getSizeInventory()]; int tGrabSlotsSize = 0; if (aTileEntity1 instanceof ISidedInventory) { for (int i : ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom)) { - ItemStack s = aTileEntity1.getStackInSlot(i); + final ItemStack s = aTileEntity1.getStackInSlot(i); if (s == null || !isAllowedToTakeFromSlot(aTileEntity1, i, aGrabFrom, s) || s.stackSize < aMinMoveAtOnce @@ -839,15 +839,15 @@ public class GT_Utility { // if target is an inventory, e.g. chest, machine, drawers... if (aTileEntity2 instanceof IInventory) { - IInventory tPutInventory = (IInventory) aTileEntity2; + final IInventory tPutInventory = (IInventory) aTileEntity2; // partially filled slot spare space mapping. // value is the sum of all spare space left not counting completely empty slot - HashMap<ItemId, Integer> tPutItems = new HashMap<>(tPutInventory.getSizeInventory()); + final HashMap<ItemId, Integer> tPutItems = new HashMap<>(tPutInventory.getSizeInventory()); // partially filled slot contents - HashMap<ItemId, List<ItemStack>> tPutItemStacks = new HashMap<>(tPutInventory.getSizeInventory()); + final HashMap<ItemId, List<ItemStack>> tPutItemStacks = new HashMap<>(tPutInventory.getSizeInventory()); // completely empty slots - List<Integer> tPutFreeSlots = new ArrayList<>(tPutInventory.getSizeInventory()); + final List<Integer> tPutFreeSlots = new ArrayList<>(tPutInventory.getSizeInventory()); // find possible target slots int[] accessibleSlots = null; @@ -895,28 +895,28 @@ public class GT_Utility { // go over source stacks one by one int tStacksMoved = 0, tTotalItemsMoved = 0; for (int j = 0; j < tGrabSlotsSize; j++) { - int grabSlot = tGrabSlots[j]; + final int grabSlot = tGrabSlots[j]; int tMovedItems; int tStackSize; do { tMovedItems = 0; - ItemStack tGrabStack = aTileEntity1.getStackInSlot(grabSlot); + final ItemStack tGrabStack = aTileEntity1.getStackInSlot(grabSlot); if (tGrabStack == null) break; tStackSize = tGrabStack.stackSize; - ItemId sID = ItemId.createNoCopy(tGrabStack); + final ItemId sID = ItemId.createNoCopy(tGrabStack); if (tPutItems.containsKey(sID)) { // there is a partially filled slot, try merging - int canPut = Math.min(tPutItems.get(sID), aMaxMoveAtOnce); + final int canPut = Math.min(tPutItems.get(sID), aMaxMoveAtOnce); if (canPut >= aMinMoveAtOnce) { - List<ItemStack> putStack = tPutItemStacks.get(sID); + final List<ItemStack> putStack = tPutItemStacks.get(sID); if (!putStack.isEmpty()) { // can move, do merge int toPut = Math.min(canPut, tStackSize); tMovedItems = toPut; for (int i = 0; i < putStack.size(); i++) { - ItemStack s = putStack.get(i); - int sToPut = Math.min( + final ItemStack s = putStack.get(i); + final int sToPut = Math.min( Math.min( Math.min(toPut, s.getMaxStackSize() - s.stackSize), tPutInventory.getInventoryStackLimit() - s.stackSize), @@ -953,10 +953,10 @@ public class GT_Utility { // still stuff to move & have completely empty slots if (tStackSize > 0 && !tPutFreeSlots.isEmpty()) { for (int i = 0; i < tPutFreeSlots.size(); i++) { - int tPutSlot = tPutFreeSlots.get(i); + final int tPutSlot = tPutFreeSlots.get(i); if (isAllowedToPutIntoSlot(tPutInventory, tPutSlot, aPutTo, tGrabStack, (byte) 64)) { // allowed, now do moving - int tMoved = moveStackFromSlotAToSlotB( + final int tMoved = moveStackFromSlotAToSlotB( aTileEntity1, tPutInventory, grabSlot, @@ -966,15 +966,15 @@ public class GT_Utility { (byte) (aMaxMoveAtOnce - tMovedItems), aMinMoveAtOnce); if (tMoved > 0) { - ItemStack s = tPutInventory.getStackInSlot(tPutSlot); + final ItemStack s = tPutInventory.getStackInSlot(tPutSlot); if (s != null) { // s might be null if tPutInventory is very special, e.g. infinity chest // if s is null, we will not mark this slot as target candidate for anything - int spare = + final int spare = Math.min(s.getMaxStackSize(), tPutInventory.getInventoryStackLimit()) - s.stackSize; if (spare > 0) { - ItemId ssID = ItemId.createNoCopy(s); + final ItemId ssID = ItemId.createNoCopy(s); // add back to spare space count tPutItems.merge(ssID, spare, Integer::sum); // add to partially filled slot list @@ -1007,7 +1007,7 @@ public class GT_Utility { // check if source is a double chest, if yes, try move from the adjacent as well if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) { - int tAmount = moveFromAdjacentChests( + final int tAmount = moveFromAdjacentChests( (TileEntityChest) aTileEntity1, aTileEntity2, aGrabFrom, @@ -1024,7 +1024,7 @@ public class GT_Utility { // check if target is a double chest, if yes, try move to the adjacent as well if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) { - int tAmount = moveToAdjacentChests( + final int tAmount = moveToAdjacentChests( aTileEntity1, (TileEntityChest) aTileEntity2, aGrabFrom, @@ -1044,9 +1044,9 @@ public class GT_Utility { // there should be a function to transfer more than 1 stack in a pipe // however I do not see any ways to improve it. too much work for what it is worth int tTotalItemsMoved = 0; - int tGrabInventorySize = tGrabSlots.length; + final int tGrabInventorySize = tGrabSlots.length; for (int i = 0; i < tGrabInventorySize; i++) { - int tMoved = moveStackIntoPipe( + final int tMoved = moveStackIntoPipe( aTileEntity1, aTileEntity2, tGrabSlots, @@ -3380,12 +3380,8 @@ public class GT_Utility { if (tTileEntity instanceof ICoverable) { rEUAmount += 300; final String tString = ((ICoverable) tTileEntity) - .getCoverBehaviorAtSideNew((byte) aSide) - .getDescription( - (byte) aSide, - ((ICoverable) tTileEntity).getCoverIDAtSide((byte) aSide), - ((ICoverable) tTileEntity).getComplexCoverDataAtSide((byte) aSide), - (ICoverable) tTileEntity); + .getCoverInfoAtSide((byte) aSide) + .getBehaviorDescription(); if (tString != null && !tString.equals(E)) tList.add(tString); } } catch (Throwable e) { |