diff options
author | Jason Mitchell <mitchej@gmail.com> | 2023-04-22 22:33:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-23 07:33:35 +0200 |
commit | 56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b (patch) | |
tree | 745e6d92025ec4ef449fc59fa5fdd741200b0489 /src/main/java/gregtech/api/util | |
parent | ac0b7a7da46646d325def36eed811941dbfc5950 (diff) | |
download | GT5-Unofficial-56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b.tar.gz GT5-Unofficial-56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b.tar.bz2 GT5-Unofficial-56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b.zip |
Forge direction (#1895)
* ForgeDirection
Also refactor the clusterfuck that was `getCoordinateScan`
Co-authored by: Jason Mitchell <mitchej@gmail.com>
* Fix rendering of Frame Boxes
Frame boxes needed their own implementation of getTexture with int connexion mask,
which is returning an error texture for the MetaTileEntity, because pipes (FrameBox
**is** a pipe) do use this method to return different textures based on connexion
status.
---------
Co-authored-by: Léa Gris <lea.gris@noiraude.net>
Diffstat (limited to 'src/main/java/gregtech/api/util')
6 files changed, 1081 insertions, 1064 deletions
diff --git a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java index b15627bb05..d5cd50049e 100644 --- a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java @@ -1,6 +1,6 @@ package gregtech.api.util; -import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES; +import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -35,7 +35,7 @@ public abstract class GT_CircuitryBehavior { * returns if there is Redstone applied to any of the valid Inputs (OR) */ public static boolean getAnyRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(side) .letsRedstoneGoIn( side, @@ -54,7 +54,7 @@ public abstract class GT_CircuitryBehavior { * returns if there is Redstone applied to all the valid Inputs (AND) */ public static boolean getAllRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(side) .letsRedstoneGoIn( side, @@ -74,7 +74,7 @@ public abstract class GT_CircuitryBehavior { */ public static boolean getOneRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { int tRedstoneAmount = 0; - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(side) .letsRedstoneGoIn( side, @@ -94,7 +94,7 @@ public abstract class GT_CircuitryBehavior { */ public static byte getStrongestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { byte tRedstoneAmount = 0; - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(side) .letsRedstoneGoIn( side, @@ -117,7 +117,7 @@ public abstract class GT_CircuitryBehavior { public static byte getWeakestNonZeroRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { if (!getAnyRedstone(aRedstoneCircuitBlock)) return 0; byte tRedstoneAmount = 15; - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(side) .letsRedstoneGoIn( side, @@ -137,7 +137,7 @@ public abstract class GT_CircuitryBehavior { public static byte getWeakestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { if (!getAnyRedstone(aRedstoneCircuitBlock)) return 0; byte tRedstoneAmount = 15; - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (side != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(side) .letsRedstoneGoIn( side, diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java index 60196bd236..6441adb22b 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java @@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import gregtech.api.enums.GT_Values; @@ -47,172 +48,161 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl } @Override - protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, + protected boolean isRedstoneSensitiveImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { - return isRedstoneSensitive(aSide, aCoverID, aCoverVariable.get(), aTileEntity, aTimer); + return isRedstoneSensitive(side, aCoverID, aCoverVariable.get(), aTileEntity, aTimer); } @Override - protected ISerializableObject.LegacyCoverData doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, - ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { + protected ISerializableObject.LegacyCoverData doCoverThingsImpl(ForgeDirection side, byte aInputRedstone, + int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { if (aCoverVariable == null) aCoverVariable = new ISerializableObject.LegacyCoverData(); - aCoverVariable.set(doCoverThings(aSide, aInputRedstone, aCoverID, aCoverVariable.get(), aTileEntity, aTimer)); + aCoverVariable.set(doCoverThings(side, aInputRedstone, aCoverID, aCoverVariable.get(), aTileEntity, aTimer)); return aCoverVariable; } @Override - protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, + protected boolean onCoverRightClickImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return onCoverRightclick(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); + return onCoverRightclick(side, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); } @Override - protected ISerializableObject.LegacyCoverData onCoverScrewdriverClickImpl(byte aSide, int aCoverID, + protected ISerializableObject.LegacyCoverData onCoverScrewdriverClickImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { if (aCoverVariable == null) aCoverVariable = new ISerializableObject.LegacyCoverData(); aCoverVariable - .set(onCoverScrewdriverclick(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ)); + .set(onCoverScrewdriverclick(side, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ)); return aCoverVariable; } @Override - protected boolean onCoverShiftRightClickImpl(byte aSide, int aCoverID, + protected boolean onCoverShiftRightClickImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { - return onCoverShiftRightclick(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer); + return onCoverShiftRightclick(side, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer); } @Deprecated @Override - protected Object getClientGUIImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { - return getClientGUI(aSide, aCoverID, convert(aCoverVariable), aTileEntity); - } - - @Override - protected boolean onCoverRemovalImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity, boolean aForced) { - return onCoverRemoval(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aForced); + protected Object getClientGUIImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, + World aWorld) { + return getClientGUI(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected String getDescriptionImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return getDescription(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected boolean onCoverRemovalImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, boolean aForced) { + return onCoverRemoval(side, aCoverID, convert(aCoverVariable), aTileEntity, aForced); } @Override - protected float getBlastProofLevelImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return getBlastProofLevel(aSide, aCoverID, convert(aCoverVariable), aTileEntity); - } - - @Override - protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return letsRedstoneGoIn(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected String getDescriptionImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getDescription(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, + protected float getBlastProofLevelImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { - return letsRedstoneGoOut(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + return getBlastProofLevel(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean letsFibreGoInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return letsFibreGoIn(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected boolean letsRedstoneGoInImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoIn(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean letsFibreGoOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return letsFibreGoOut(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected boolean letsRedstoneGoOutImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoOut(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean letsEnergyInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return letsEnergyIn(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected boolean letsEnergyInImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsEnergyIn(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return letsEnergyOut(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected boolean letsEnergyOutImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return letsEnergyOut(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean letsFluidInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - Fluid aFluid, ICoverable aTileEntity) { - return letsFluidIn(aSide, aCoverID, convert(aCoverVariable), aFluid, aTileEntity); + protected boolean letsFluidInImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidIn(side, aCoverID, convert(aCoverVariable), aFluid, aTileEntity); } @Override - protected boolean letsFluidOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - Fluid aFluid, ICoverable aTileEntity) { - return letsFluidOut(aSide, aCoverID, convert(aCoverVariable), aFluid, aTileEntity); + protected boolean letsFluidOutImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return letsFluidOut(side, aCoverID, convert(aCoverVariable), aFluid, aTileEntity); } @Override - protected boolean letsItemsInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - int aSlot, ICoverable aTileEntity) { - return letsItemsIn(aSide, aCoverID, convert(aCoverVariable), aSlot, aTileEntity); + protected boolean letsItemsInImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsIn(side, aCoverID, convert(aCoverVariable), aSlot, aTileEntity); } @Override - protected boolean letsItemsOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - int aSlot, ICoverable aTileEntity) { - return letsItemsOut(aSide, aCoverID, convert(aCoverVariable), aSlot, aTileEntity); + protected boolean letsItemsOutImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, int aSlot, ICoverable aTileEntity) { + return letsItemsOut(side, aCoverID, convert(aCoverVariable), aSlot, aTileEntity); } @Override - protected boolean isGUIClickableImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return isGUIClickable(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected boolean isGUIClickableImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return isGUIClickable(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean manipulatesSidedRedstoneOutputImpl(byte aSide, int aCoverID, + protected boolean manipulatesSidedRedstoneOutputImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { - return manipulatesSidedRedstoneOutput(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + return manipulatesSidedRedstoneOutput(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, + protected boolean alwaysLookConnectedImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { - return alwaysLookConnected(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + return alwaysLookConnected(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected byte getRedstoneInputImpl(byte aSide, byte aInputRedstone, int aCoverID, + protected byte getRedstoneInputImpl(ForgeDirection side, byte aInputRedstone, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { - return getRedstoneInput(aSide, aInputRedstone, aCoverID, convert(aCoverVariable), aTileEntity); + return getRedstoneInput(side, aInputRedstone, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected int getTickRateImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, + protected int getTickRateImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { - return getTickRate(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + return getTickRate(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected byte getLensColorImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return getLensColor(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected byte getLensColorImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getLensColor(side, aCoverID, convert(aCoverVariable), aTileEntity); } @Override - protected ItemStack getDropImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity) { - return getDrop(aSide, aCoverID, convert(aCoverVariable), aTileEntity); + protected ItemStack getDropImpl(ForgeDirection side, int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + return getDrop(side, aCoverID, convert(aCoverVariable), aTileEntity); } // endregion - public boolean isRedstoneSensitive(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + public boolean isRedstoneSensitive(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { return true; } @@ -220,8 +210,8 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl /** * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. */ - public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, - long aTimer) { + public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity, long aTimer) { return aCoverVariable; } @@ -230,7 +220,7 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * <p/> * return true, if something actually happens. */ - public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + public boolean onCoverRightclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { return false; } @@ -240,7 +230,7 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * <p/> * return the new Value of the Cover Variable */ - public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + public int onCoverScrewdriverclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { return aCoverVariable; } @@ -248,17 +238,17 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl /** * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. */ - public boolean onCoverShiftRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + public boolean onCoverShiftRightclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) { lastPlayer = aPlayer; mPlayerNotified = false; if (useModularUI()) { - GT_UIInfos.openCoverUI(aTileEntity, aPlayer, aSide); + GT_UIInfos.openCoverUI(aTileEntity, aPlayer, side); } else { GT_Values.NW.sendToPlayer( new GT_Packet_TileEntityCoverGUI( - aSide, + side, aCoverID, aCoverVariable, aTileEntity, @@ -271,7 +261,7 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl } @Deprecated - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { + public Object getClientGUI(ForgeDirection side, int aCoverID, int coverData, ICoverable aTileEntity) { return null; } @@ -279,7 +269,7 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * Removes the Cover if this returns true, or if aForced is true. Doesn't get called when the Machine Block is * getting broken, only if you break the Cover away from the Machine. */ - public boolean onCoverRemoval(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + public boolean onCoverRemoval(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, boolean aForced) { return true; } @@ -287,14 +277,14 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl /** * Gives a small Text for the status of the Cover. */ - public String getDescription(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public String getDescription(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return E; } /** * How Blast Proof the Cover is. 30 is normal. */ - public float getBlastProofLevel(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public float getBlastProofLevel(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 10.0F; } @@ -303,58 +293,44 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * <p/> * This is just Informative so that Machines know if their Redstone Input is blocked or not */ - public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } /** * If it lets RS-Signals out of the Block */ - public boolean letsRedstoneGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Fibre-Signals into the Block - * <p/> - * This is just Informative so that Machines know if their Redstone Input is blocked or not - */ - public boolean letsFibreGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Fibre-Signals out of the Block - */ - public boolean letsFibreGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } /** * If it lets Energy into the Block */ - public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } /** * If it lets Energy out of the Block */ - public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } /** * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. */ - public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + public boolean letsFluidIn(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { return false; } /** * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. */ - public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + public boolean letsFluidOut(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { return false; } @@ -363,7 +339,8 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each * Slot). */ - public boolean letsItemsIn(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) { + public boolean letsItemsIn(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { return false; } @@ -372,21 +349,22 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each * Slot). */ - public boolean letsItemsOut(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) { + public boolean letsItemsOut(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { return false; } /** * If it lets you rightclick the Machine normally */ - public boolean isGUIClickable(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean isGUIClickable(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } /** * Needs to return true for Covers, which have a Redstone Output on their Facing. */ - public boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, int aCoverVariable, + public boolean manipulatesSidedRedstoneOutput(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } @@ -394,7 +372,7 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl /** * if this Cover should let Pipe Connections look connected even if it is not the case. */ - public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } @@ -402,9 +380,9 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * Called to determine the incoming Redstone Signal of a Machine. Returns the original Redstone per default. The * Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. */ - public byte getRedstoneInput(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, + public byte getRedstoneInput(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - return letsRedstoneGoIn(aSide, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0; + return letsRedstoneGoIn(side, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0; } /** @@ -412,21 +390,21 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl * <p/> * 0 = No Ticks! Yes, 0 is Default, you have to override this */ - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 0; } /** * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). */ - public byte getLensColor(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public byte getLensColor(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return -1; } /** * @return the ItemStack dropped by this Cover */ - public ItemStack getDrop(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(aSide)); + public ItemStack getDrop(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(side)); } } diff --git a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java index 1757d0375a..8f65ae1553 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java @@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagInt; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import com.gtnewhorizons.modularui.api.ModularUITextures; @@ -89,23 +90,23 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * Get target facade block. Does not affect rendering of **this** block. It is only used as a hint for other block * in case of CTM - * + * * @return null if none, otherwise return facade target block */ - public final Block getFacadeBlock(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final Block getFacadeBlock(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getFacadeBlockImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getFacadeBlockImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Get target facade block. Does not affect rendering of **this** block. It is only used as a hint for other block * in case of CTM - * + * * @return 0 if none, otherwise return facade target meta */ - public final int getFacadeMeta(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final int getFacadeMeta(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getFacadeMetaImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getFacadeMetaImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** @@ -120,46 +121,46 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * passed to {@link gregtech.api.GregTech_API#registerCover(ItemStack, ITexture, GT_CoverBehaviorBase)} or its * overloads. */ - public final ITexture getSpecialCoverFGTexture(byte aSide, int aCoverID, ISerializableObject aCoverVariable, - ICoverable aTileEntity) { - return getSpecialCoverFGTextureImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + public final ITexture getSpecialCoverFGTexture(ForgeDirection side, int aCoverID, + ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return getSpecialCoverFGTextureImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Get the special cover texture associated with this cover. Return null if one should use the texture passed to * {@link gregtech.api.GregTech_API#registerCover(ItemStack, ITexture, GT_CoverBehaviorBase)} or its overloads. */ - public final ITexture getSpecialCoverTexture(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final ITexture getSpecialCoverTexture(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getSpecialCoverTextureImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getSpecialCoverTextureImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Return whether cover data needs to be synced to client upon tile entity creation or cover placement. * * Note if you want to sync the data afterwards you will have to manually do it by calling - * {@link ICoverable#issueCoverUpdate(byte)} This option only affects the initial sync. + * {@link ICoverable#issueCoverUpdate(ForgeDirection)} This option only affects the initial sync. */ - public final boolean isDataNeededOnClient(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean isDataNeededOnClient(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return isDataNeededOnClientImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return isDataNeededOnClientImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Called upon receiving data from network. Use {@link ICoverable#isClientSide()} to determine the side. */ - public final void onDataChanged(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final void onDataChanged(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - onDataChangedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + onDataChangedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Called before receiving data from network. Use {@link ICoverable#isClientSide()} to determine the side. */ - public final void preDataChanged(byte aSide, int aCoverID, int aNewCoverId, ISerializableObject aCoverVariable, - ISerializableObject aNewCoverVariable, ICoverable aTileEntity) { + public final void preDataChanged(ForgeDirection side, int aCoverID, int aNewCoverId, + ISerializableObject aCoverVariable, ISerializableObject aNewCoverVariable, ICoverable aTileEntity) { preDataChangedImpl( - aSide, + side, aCoverID, aNewCoverId, forceCast(aCoverVariable), @@ -170,21 +171,22 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * Called upon cover being removed. Called on both server and client. */ - public final void onDropped(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - onDroppedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + public final void onDropped(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, + ICoverable aTileEntity) { + onDroppedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } - public final boolean isRedstoneSensitive(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean isRedstoneSensitive(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { - return isRedstoneSensitiveImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); + return isRedstoneSensitiveImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); } /** * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. */ - public final T doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, - ICoverable aTileEntity, long aTimer) { - return doCoverThingsImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); + public final T doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, + ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) { + return doCoverThingsImpl(side, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer); } /** @@ -192,9 +194,9 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * return true, if something actually happens. */ - public final boolean onCoverRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean onCoverRightClick(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return onCoverRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); + return onCoverRightClickImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); } /** @@ -202,65 +204,57 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * return the new Value of the Cover Variable */ - public final T onCoverScrewdriverClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final T onCoverScrewdriverClick(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - return onCoverScrewdriverClickImpl( - aSide, - aCoverID, - forceCast(aCoverVariable), - aTileEntity, - aPlayer, - aX, - aY, - aZ); + return onCoverScrewdriverClickImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ); } /** * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. */ - public final boolean onCoverShiftRightClick(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean onCoverShiftRightClick(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { - return onCoverShiftRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer); + return onCoverShiftRightClickImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer); } @Deprecated - public final Object getClientGUI(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final Object getClientGUI(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { - return getClientGUIImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aWorld); + return getClientGUIImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aWorld); } /** * Removes the Cover if this returns true, or if aForced is true. Doesn't get called when the Machine Block is * getting broken, only if you break the Cover away from the Machine. */ - public final boolean onCoverRemoval(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean onCoverRemoval(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity, boolean aForced) { - return onCoverRemovalImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aForced); + return onCoverRemovalImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aForced); } /** * Called upon Base TE being destroyed (once getDrops is called), thus getting called only when destroyed in * survival. */ - public final void onBaseTEDestroyed(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final void onBaseTEDestroyed(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - onBaseTEDestroyedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + onBaseTEDestroyedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Gives a small Text for the status of the Cover. */ - public final String getDescription(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final String getDescription(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getDescriptionImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getDescriptionImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * How Blast Proof the Cover is. 30 is normal. */ - public final float getBlastProofLevel(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final float getBlastProofLevel(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getBlastProofLevelImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getBlastProofLevelImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** @@ -268,67 +262,49 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * This is just Informative so that Machines know if their Redstone Input is blocked or not */ - public final boolean letsRedstoneGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsRedstoneGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return letsRedstoneGoInImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * If it lets RS-Signals out of the Block */ - public final boolean letsRedstoneGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, - ICoverable aTileEntity) { - return letsRedstoneGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets Fibre-Signals into the Block - * <p/> - * This is just Informative so that Machines know if their Redstone Input is blocked or not - */ - public final boolean letsFibreGoIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, - ICoverable aTileEntity) { - return letsFibreGoInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); - } - - /** - * If it lets Fibre-Signals out of the Block - */ - public final boolean letsFibreGoOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsFibreGoOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return letsRedstoneGoOutImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * If it lets Energy into the Block */ - public final boolean letsEnergyIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean letsEnergyIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsEnergyInImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return letsEnergyInImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * If it lets Energy out of the Block */ - public final boolean letsEnergyOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean letsEnergyOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return letsEnergyOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return letsEnergyOutImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. */ - public final boolean letsFluidIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, - ICoverable aTileEntity) { - return letsFluidInImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); + public final boolean letsFluidIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, + Fluid aFluid, ICoverable aTileEntity) { + return letsFluidInImpl(side, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); } /** * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. */ - public final boolean letsFluidOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, Fluid aFluid, - ICoverable aTileEntity) { - return letsFluidOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); + public final boolean letsFluidOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, + Fluid aFluid, ICoverable aTileEntity) { + return letsFluidOutImpl(side, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity); } /** @@ -336,9 +312,9 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * reaction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each * Slot). */ - public final boolean letsItemsIn(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, + public final boolean letsItemsIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { - return letsItemsInImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); + return letsItemsInImpl(side, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); } /** @@ -346,42 +322,42 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * reaction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each * Slot). */ - public final boolean letsItemsOut(byte aSide, int aCoverID, ISerializableObject aCoverVariable, int aSlot, + public final boolean letsItemsOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, int aSlot, ICoverable aTileEntity) { - return letsItemsOutImpl(aSide, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); + return letsItemsOutImpl(side, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity); } /** * If it lets you rightclick the Machine normally */ - public final boolean isGUIClickable(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean isGUIClickable(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return isGUIClickableImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return isGUIClickableImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Needs to return true for Covers, which have a Redstone Output on their Facing. */ - public final boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, ISerializableObject aCoverVariable, - ICoverable aTileEntity) { - return manipulatesSidedRedstoneOutputImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + public final boolean manipulatesSidedRedstoneOutput(ForgeDirection side, int aCoverID, + ISerializableObject aCoverVariable, ICoverable aTileEntity) { + return manipulatesSidedRedstoneOutputImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * if this Cover should let Pipe Connections look connected even if it is not the case. */ - public final boolean alwaysLookConnected(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final boolean alwaysLookConnected(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return alwaysLookConnectedImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return alwaysLookConnectedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * Called to determine the incoming Redstone Signal of a Machine. Returns the original Redstone per default. The * Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. */ - public final byte getRedstoneInput(byte aSide, byte aInputRedstone, int aCoverID, + public final byte getRedstoneInput(ForgeDirection side, byte aInputRedstone, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getRedstoneInputImpl(aSide, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getRedstoneInputImpl(side, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** @@ -389,24 +365,25 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * 0 = No Ticks! Yes, 0 is Default, you have to override this */ - public final int getTickRate(byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getTickRateImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + public final int getTickRate(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, + ICoverable aTileEntity) { + return getTickRateImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). */ - public final byte getLensColor(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final byte getLensColor(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getLensColorImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getLensColorImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } /** * @return the ItemStack dropped by this Cover */ - public final ItemStack getDrop(byte aSide, int aCoverID, ISerializableObject aCoverVariable, + public final ItemStack getDrop(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { - return getDropImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity); + return getDropImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } // endregion @@ -540,11 +517,11 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { // region impl - protected Block getFacadeBlockImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected Block getFacadeBlockImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return null; } - protected int getFacadeMetaImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected int getFacadeMetaImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return 0; } @@ -552,37 +529,39 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { return GT_Utility.intToStack(aCoverID); } - protected ITexture getSpecialCoverFGTextureImpl(byte aSide, int aCoverID, T aCoverVariable, + protected ITexture getSpecialCoverFGTextureImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return coverFGTexture; } - protected ITexture getSpecialCoverTextureImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected ITexture getSpecialCoverTextureImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity) { return null; } - protected boolean isDataNeededOnClientImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected boolean isDataNeededOnClientImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity) { return false; } - protected void onDataChangedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} + protected void onDataChangedImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} - protected void preDataChangedImpl(byte aSide, int aCoverID, int aNewCoverId, T aCoverVariable, T aNewCoverVariable, - ICoverable aTileEntity) {} + protected void preDataChangedImpl(ForgeDirection side, int aCoverID, int aNewCoverId, T aCoverVariable, + T aNewCoverVariable, ICoverable aTileEntity) {} - protected void onDroppedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} + protected void onDroppedImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} - protected void onBaseTEDestroyedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} + protected void onBaseTEDestroyedImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {} - protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, - long aTimer) { + protected boolean isRedstoneSensitiveImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity, long aTimer) { return false; } /** * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. */ - protected T doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, + protected T doCoverThingsImpl(ForgeDirection side, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity, long aTimer) { return aCoverVariable; } @@ -592,7 +571,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * return true, if something actually happens. */ - protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, + protected boolean onCoverRightClickImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { return false; } @@ -602,7 +581,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * return the new Value of the Cover Variable */ - protected T onCoverScrewdriverClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, + protected T onCoverScrewdriverClickImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { return aCoverVariable; } @@ -610,16 +589,16 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case. */ - protected boolean onCoverShiftRightClickImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, - EntityPlayer aPlayer) { + protected boolean onCoverShiftRightClickImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity, EntityPlayer aPlayer) { if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) { lastPlayer = aPlayer; if (useModularUI()) { - GT_UIInfos.openCoverUI(aTileEntity, aPlayer, aSide); + GT_UIInfos.openCoverUI(aTileEntity, aPlayer, side); } else { GT_Values.NW.sendToPlayer( new GT_Packet_TileEntityCoverGUI( - aSide, + side, aCoverID, aCoverVariable, aTileEntity, @@ -632,7 +611,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { } @Deprecated - protected Object getClientGUIImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, + protected Object getClientGUIImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { return null; } @@ -641,7 +620,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * Removes the Cover if this returns true, or if aForced is true. Doesn't get called when the Machine Block is * getting broken, only if you break the Cover away from the Machine. */ - protected boolean onCoverRemovalImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, + protected boolean onCoverRemovalImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity, boolean aForced) { return true; } @@ -649,14 +628,15 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * Gives a small Text for the status of the Cover. */ - protected String getDescriptionImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected String getDescriptionImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return E; } /** * How Blast Proof the Cover is. 30 is normal. */ - protected float getBlastProofLevelImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected float getBlastProofLevelImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity) { return 10.0F; } @@ -665,51 +645,37 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * This is just Informative so that Machines know if their Redstone Input is blocked or not */ - protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected boolean letsRedstoneGoInImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity) { return false; } /** * If it lets RS-Signals out of the Block */ - protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Fibre-Signals into the Block - * <p/> - * This is just Informative so that Machines know if their Redstone Input is blocked or not - */ - protected boolean letsFibreGoInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return false; - } - - /** - * If it lets Fibre-Signals out of the Block - */ - protected boolean letsFibreGoOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected boolean letsRedstoneGoOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity) { return false; } /** * If it lets Energy into the Block */ - protected boolean letsEnergyInImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected boolean letsEnergyInImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return false; } /** * If it lets Energy out of the Block */ - protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected boolean letsEnergyOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return false; } /** * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. */ - protected boolean letsFluidInImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, + protected boolean letsFluidInImpl(ForgeDirection side, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { return false; } @@ -717,7 +683,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. */ - protected boolean letsFluidOutImpl(byte aSide, int aCoverID, T aCoverVariable, Fluid aFluid, + protected boolean letsFluidOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { return false; } @@ -727,7 +693,8 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each * Slot). */ - protected boolean letsItemsInImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { + protected boolean letsItemsInImpl(ForgeDirection side, int aCoverID, T aCoverVariable, int aSlot, + ICoverable aTileEntity) { return false; } @@ -736,21 +703,22 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each * Slot). */ - protected boolean letsItemsOutImpl(byte aSide, int aCoverID, T aCoverVariable, int aSlot, ICoverable aTileEntity) { + protected boolean letsItemsOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable, int aSlot, + ICoverable aTileEntity) { return false; } /** * If it lets you rightclick the Machine normally */ - protected boolean isGUIClickableImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected boolean isGUIClickableImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return false; } /** * Needs to return true for Covers, which have a Redstone Output on their Facing. */ - protected boolean manipulatesSidedRedstoneOutputImpl(byte aSide, int aCoverID, T aCoverVariable, + protected boolean manipulatesSidedRedstoneOutputImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return false; } @@ -758,7 +726,8 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * if this Cover should let Pipe Connections look connected even if it is not the case. */ - protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected boolean alwaysLookConnectedImpl(ForgeDirection side, int aCoverID, T aCoverVariable, + ICoverable aTileEntity) { return false; } @@ -766,9 +735,9 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * Called to determine the incoming Redstone Signal of a Machine. Returns the original Redstone per default. The * Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. */ - protected byte getRedstoneInputImpl(byte aSide, byte aInputRedstone, int aCoverID, T aCoverVariable, + protected byte getRedstoneInputImpl(ForgeDirection side, byte aInputRedstone, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return letsRedstoneGoIn(aSide, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0; + return letsRedstoneGoIn(side, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0; } /** @@ -776,22 +745,22 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * 0 = No Ticks! Yes, 0 is Default, you have to override this */ - protected int getTickRateImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected int getTickRateImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return 0; } /** * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). */ - protected byte getLensColorImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + protected byte getLensColorImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return -1; } /** * @return the ItemStack dropped by this Cover */ - protected ItemStack getDropImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { - return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(aSide)); + protected ItemStack getDropImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(side)); } // endregion @@ -801,16 +770,16 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * Checks if the Cover can be placed on this. */ - public boolean isCoverPlaceable(byte aSide, ItemStack aStack, ICoverable aTileEntity) { - return isCoverPlaceable(aSide, new GT_ItemStack(aStack), aTileEntity); + public boolean isCoverPlaceable(ForgeDirection side, ItemStack aStack, ICoverable aTileEntity) { + return isCoverPlaceable(side, new GT_ItemStack(aStack), aTileEntity); } /** * Checks if the Cover can be placed on this. You will probably want to call - * {@link #isCoverPlaceable(byte, ItemStack, ICoverable)} instead. + * {@link #isCoverPlaceable(ForgeDirection, ItemStack, ICoverable)} instead. */ @Deprecated - public boolean isCoverPlaceable(byte aSide, GT_ItemStack aStack, ICoverable aTileEntity) { + public boolean isCoverPlaceable(ForgeDirection side, GT_ItemStack aStack, ICoverable aTileEntity) { return true; } @@ -823,8 +792,8 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { * <p/> * return true, if something actually happens. */ - public boolean onCoverRightclickClient(byte aSide, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, - float aZ) { + public boolean onCoverRightclickClient(ForgeDirection side, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, + float aY, float aZ) { return false; } @@ -838,8 +807,8 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { /** * sets the Cover upon placement. */ - public void placeCover(byte aSide, ItemStack aCover, ICoverable aTileEntity) { - aTileEntity.setCoverIDAtSide(aSide, GT_Utility.stackToInt(aCover)); + public void placeCover(ForgeDirection side, ItemStack aCover, ICoverable aTileEntity) { + aTileEntity.setCoverIDAtSide(side, GT_Utility.stackToInt(aCover)); } @Deprecated diff --git a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java index ba9e3b9773..8565dc21f5 100644 --- a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java +++ b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java @@ -495,7 +495,7 @@ public class GT_HatchElementBuilder<T> { if (facing.offsetY == 0) break; } assert result != null; - ((IGregTechTileEntity) tileEntity).setFrontFacing((byte) result.ordinal()); + ((IGregTechTileEntity) tileEntity).setFrontFacing(result); } } return mNoStop ? PlaceResult.ACCEPT : PlaceResult.ACCEPT_STOP; diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 91d5a90fe6..7420dc14f9 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -11,6 +11,13 @@ import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.W; import static gregtech.api.enums.Materials.FLUID_MAP; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; +import static net.minecraftforge.common.util.ForgeDirection.DOWN; +import static net.minecraftforge.common.util.ForgeDirection.EAST; +import static net.minecraftforge.common.util.ForgeDirection.NORTH; +import static net.minecraftforge.common.util.ForgeDirection.SOUTH; +import static net.minecraftforge.common.util.ForgeDirection.UNKNOWN; +import static net.minecraftforge.common.util.ForgeDirection.UP; +import static net.minecraftforge.common.util.ForgeDirection.WEST; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -448,9 +455,8 @@ public class GT_Utility { return null; } - public static byte getOppositeSide(int aSide) { - return (byte) ForgeDirection.getOrientation(aSide) - .getOpposite() + public static byte getOppositeSide(ForgeDirection side) { + return (byte) side.getOpposite() .ordinal(); } @@ -501,14 +507,13 @@ public class GT_Utility { } } - public static boolean isConnectableNonInventoryPipe(Object aTileEntity, int aSide) { - if (aTileEntity == null) return false; + public static boolean isConnectableNonInventoryPipe(TileEntity tileEntity, ForgeDirection side) { + if (tileEntity == null) return false; checkAvailabilities(); - if (TE_CHECK && aTileEntity instanceof IItemDuct) return true; - if (BC_CHECK && aTileEntity instanceof buildcraft.api.transport.IPipeTile) - return ((buildcraft.api.transport.IPipeTile) aTileEntity) - .isPipeConnected(ForgeDirection.getOrientation(aSide)); - return GregTech_API.mTranslocator && aTileEntity instanceof codechicken.translocator.TileItemTranslocator; + if (TE_CHECK && tileEntity instanceof IItemDuct) return true; + if (BC_CHECK && tileEntity instanceof buildcraft.api.transport.IPipeTile pipeTile) + return pipeTile.isPipeConnected(side); + return GregTech_API.mTranslocator && tileEntity instanceof codechicken.translocator.TileItemTranslocator; } /** @@ -516,15 +521,15 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, - int aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, - byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, + ForgeDirection fromSide, ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, + byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { return moveStackIntoPipe( aTileEntity1, aTileEntity2, aGrabSlots, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -535,44 +540,44 @@ public class GT_Utility { } /** - * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. + * Moves Stack from Inv-Slot to Inv-Slot, without checking if it is even allowed. * * @return the Amount of moved Items */ - public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, - int aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, - byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean dropItem) { - if (aTileEntity1 == null || aMaxTargetStackSize <= 0 + public static byte moveStackIntoPipe(IInventory fromInventory, Object toObject, int[] fromSlots, + ForgeDirection fromSide, ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, + byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, + boolean dropItem) { + if (fromInventory == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; - if (aTileEntity2 != null) { + if (toObject != null) { checkAvailabilities(); - if (TE_CHECK && aTileEntity2 instanceof IItemDuct) { - for (int aGrabSlot : aGrabSlots) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) { + if (TE_CHECK && toObject instanceof IItemDuct itemDuct) { + for (final int aGrabSlot : fromSlots) { + if (listContainsItem(aFilter, fromInventory.getStackInSlot(aGrabSlot), true, aInvertFilter)) { if (isAllowedToTakeFromSlot( - aTileEntity1, + fromInventory, aGrabSlot, - (byte) aGrabFrom, - aTileEntity1.getStackInSlot(aGrabSlot))) { + fromSide, + fromInventory.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) - <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { + <= fromInventory.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount( Math.min( - aTileEntity1.getStackInSlot(aGrabSlot).stackSize, + fromInventory.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), - aTileEntity1.getStackInSlot(aGrabSlot)); - ItemStack rStack = ((IItemDuct) aTileEntity2) - .insertItem(ForgeDirection.getOrientation(aPutTo), copyOrNull(tStack)); + fromInventory.getStackInSlot(aGrabSlot)); + ItemStack rStack = itemDuct.insertItem(putSide, copyOrNull(tStack)); byte tMovedItemCount = (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize)); if (tMovedItemCount >= 1 /* Math.max(aMinMoveAtOnce, aMinTargetStackSize) */) { // ((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), // copyAmount(tMovedItemCount, tStack), F); - aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount); - aTileEntity1.markDirty(); + fromInventory.decrStackSize(aGrabSlot, tMovedItemCount); + fromInventory.markDirty(); return tMovedItemCount; } } @@ -581,31 +586,27 @@ public class GT_Utility { } return 0; } - if (BC_CHECK && aTileEntity2 instanceof buildcraft.api.transport.IPipeTile) { - for (int aGrabSlot : aGrabSlots) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) { + if (BC_CHECK && toObject instanceof buildcraft.api.transport.IPipeTile bcPipe) { + for (int fromSlot : fromSlots) { + if (listContainsItem(aFilter, fromInventory.getStackInSlot(fromSlot), true, aInvertFilter)) { if (isAllowedToTakeFromSlot( - aTileEntity1, - aGrabSlot, - (byte) aGrabFrom, - aTileEntity1.getStackInSlot(aGrabSlot))) { + fromInventory, + fromSlot, + fromSide, + fromInventory.getStackInSlot(fromSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) - <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { + <= fromInventory.getStackInSlot(fromSlot).stackSize) { ItemStack tStack = copyAmount( Math.min( - aTileEntity1.getStackInSlot(aGrabSlot).stackSize, + fromInventory.getStackInSlot(fromSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), - aTileEntity1.getStackInSlot(aGrabSlot)); - byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2) - .injectItem(copyOrNull(tStack), false, ForgeDirection.getOrientation(aPutTo)); + fromInventory.getStackInSlot(fromSlot)); + byte tMovedItemCount = (byte) bcPipe.injectItem(copyOrNull(tStack), false, putSide); if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) { - tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2) - .injectItem( - copyAmount(tMovedItemCount, tStack), - true, - ForgeDirection.getOrientation(aPutTo))); - aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount); - aTileEntity1.markDirty(); + tMovedItemCount = (byte) (bcPipe + .injectItem(copyAmount(tMovedItemCount, tStack), true, putSide)); + fromInventory.decrStackSize(fromSlot, tMovedItemCount); + fromInventory.markDirty(); return tMovedItemCount; } } @@ -616,38 +617,37 @@ public class GT_Utility { } } - ForgeDirection tDirection = ForgeDirection.getOrientation(aGrabFrom); - if (aTileEntity1 instanceof TileEntity && tDirection != ForgeDirection.UNKNOWN - && tDirection.getOpposite() == ForgeDirection.getOrientation(aPutTo)) { - int tX = ((TileEntity) aTileEntity1).xCoord + tDirection.offsetX, - tY = ((TileEntity) aTileEntity1).yCoord + tDirection.offsetY, - tZ = ((TileEntity) aTileEntity1).zCoord + tDirection.offsetZ; - if (!hasBlockHitBox(((TileEntity) aTileEntity1).getWorldObj(), tX, tY, tZ) && dropItem) { - for (int aGrabSlot : aGrabSlots) { - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) { + if (fromInventory instanceof TileEntity fromTileEntity && fromSide != ForgeDirection.UNKNOWN + && fromSide.getOpposite() == ForgeDirection.getOrientation(putSide.ordinal())) { + int tX = fromTileEntity.xCoord + fromSide.offsetX, tY = fromTileEntity.yCoord + fromSide.offsetY, + tZ = fromTileEntity.zCoord + fromSide.offsetZ; + if (!hasBlockHitBox(((TileEntity) fromInventory).getWorldObj(), tX, tY, tZ) && dropItem) { + for (final int fromSlot : fromSlots) { + if (listContainsItem(aFilter, fromInventory.getStackInSlot(fromSlot), true, aInvertFilter)) { if (isAllowedToTakeFromSlot( - aTileEntity1, - aGrabSlot, - (byte) aGrabFrom, - aTileEntity1.getStackInSlot(aGrabSlot))) { + fromInventory, + fromSlot, + fromSide, + fromInventory.getStackInSlot(fromSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) - <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { - ItemStack tStack = copyAmount( + <= fromInventory.getStackInSlot(fromSlot).stackSize) { + final ItemStack tStack = copyAmount( Math.min( - aTileEntity1.getStackInSlot(aGrabSlot).stackSize, + fromInventory.getStackInSlot(fromSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), - aTileEntity1.getStackInSlot(aGrabSlot)); - EntityItem tEntity = new EntityItem( - ((TileEntity) aTileEntity1).getWorldObj(), + fromInventory.getStackInSlot(fromSlot)); + final EntityItem tEntity = new EntityItem( + ((TileEntity) fromInventory).getWorldObj(), tX + 0.5, tY + 0.5, tZ + 0.5, tStack); tEntity.motionX = tEntity.motionY = tEntity.motionZ = 0; - ((TileEntity) aTileEntity1).getWorldObj() + ((TileEntity) fromInventory).getWorldObj() .spawnEntityInWorld(tEntity); - aTileEntity1.decrStackSize(aGrabSlot, tStack.stackSize); - aTileEntity1.markDirty(); + assert tStack != null; + fromInventory.decrStackSize(fromSlot, tStack.stackSize); + fromInventory.markDirty(); return (byte) tStack.stackSize; } } @@ -667,14 +667,13 @@ public class GT_Utility { public static byte moveStackFromSlotAToSlotB(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, int aPutTo, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { if (aTileEntity1 == null || aTileEntity2 == null - || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), - tStack3 = null; + tStack3; if (tStack1 != null) { if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0; tStack3 = copyOrNull(tStack1); @@ -706,35 +705,27 @@ public class GT_Utility { return 0; } - public static boolean isAllowedToTakeFromSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack) { - if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) { - return isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 0, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 1, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 2, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 3, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 4, aStack) - || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 5, aStack); + public static boolean isAllowedToTakeFromSlot(IInventory aTileEntity, int aSlot, ForgeDirection side, + ItemStack aStack) { + if (side == ForgeDirection.UNKNOWN) { + return Arrays.stream(ForgeDirection.VALID_DIRECTIONS) + .anyMatch(d -> isAllowedToTakeFromSlot(aTileEntity, aSlot, d, aStack)); } - if (aTileEntity instanceof ISidedInventory) - return ((ISidedInventory) aTileEntity).canExtractItem(aSlot, aStack, aSide); + if (aTileEntity instanceof ISidedInventory sided) return sided.canExtractItem(aSlot, aStack, side.ordinal()); return true; } - public static boolean isAllowedToPutIntoSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack, - byte aMaxStackSize) { + public static boolean isAllowedToPutIntoSlot(IInventory aTileEntity, int aSlot, ForgeDirection side, + ItemStack aStack, byte aMaxStackSize) { ItemStack tStack = aTileEntity.getStackInSlot(aSlot); if (tStack != null && (!areStacksEqual(tStack, aStack) || tStack.stackSize >= tStack.getMaxStackSize())) return false; - if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) { - return isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 0, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 1, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 2, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 3, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 4, aStack, aMaxStackSize) - || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 5, aStack, aMaxStackSize); + if (side == ForgeDirection.UNKNOWN) { + return Arrays.stream(ForgeDirection.VALID_DIRECTIONS) + .anyMatch(d -> isAllowedToPutIntoSlot(aTileEntity, aSlot, d, aStack, aMaxStackSize)); } if (aTileEntity instanceof ISidedInventory - && !((ISidedInventory) aTileEntity).canInsertItem(aSlot, aStack, aSide)) return false; + && !((ISidedInventory) aTileEntity).canInsertItem(aSlot, aStack, side.ordinal())) return false; return aSlot < aTileEntity.getSizeInventory() && aTileEntity.isItemValidForSlot(aSlot, aStack); } @@ -743,14 +734,14 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static int moveMultipleItemStacks(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, - List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, - byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aStackAmount) { + public static int moveMultipleItemStacks(Object aTileEntity1, Object aTileEntity2, ForgeDirection fromSide, + ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, + byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aStackAmount) { if (aTileEntity1 instanceof IInventory) return moveMultipleItemStacks( (IInventory) aTileEntity1, aTileEntity2, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -762,10 +753,11 @@ public class GT_Utility { return 0; } - 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 + public static int moveMultipleItemStacks(IInventory fromInventory, Object toObject, ForgeDirection fromSide, + ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, + byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aMaxStackTransfer, + boolean aDoCheckChests) { + if (fromInventory == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize @@ -773,19 +765,19 @@ public class GT_Utility { || aMaxStackTransfer == 0) return 0; // find where to take from - final int[] tGrabSlots = new int[aTileEntity1.getSizeInventory()]; + final int[] tGrabSlots = new int[fromInventory.getSizeInventory()]; int tGrabSlotsSize = 0; - if (aTileEntity1 instanceof ISidedInventory) { - for (int i : ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom)) { - final ItemStack s = aTileEntity1.getStackInSlot(i); - if (s == null || !isAllowedToTakeFromSlot(aTileEntity1, i, aGrabFrom, s) + if (fromInventory instanceof ISidedInventory) { + for (int i : ((ISidedInventory) fromInventory).getAccessibleSlotsFromSide(fromSide.ordinal())) { + final ItemStack s = fromInventory.getStackInSlot(i); + if (s == null || !isAllowedToTakeFromSlot(fromInventory, i, fromSide, s) || s.stackSize < aMinMoveAtOnce || !listContainsItem(aFilter, s, true, aInvertFilter)) continue; tGrabSlots[tGrabSlotsSize++] = i; } } else { for (int i = 0; i < tGrabSlots.length; i++) { - ItemStack s = aTileEntity1.getStackInSlot(i); + ItemStack s = fromInventory.getStackInSlot(i); if (s == null || s.stackSize < aMinMoveAtOnce || !listContainsItem(aFilter, s, true, aInvertFilter)) continue; tGrabSlots[tGrabSlotsSize++] = i; @@ -795,11 +787,11 @@ public class GT_Utility { // no source, bail out if (tGrabSlotsSize == 0) { // maybe source is a double chest. check it - if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) return moveFromAdjacentChests( - (TileEntityChest) aTileEntity1, - aTileEntity2, - aGrabFrom, - aPutTo, + if (aDoCheckChests && fromInventory instanceof TileEntityChest chest) return moveFromAdjacentChests( + chest, + toObject, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -811,35 +803,35 @@ public class GT_Utility { } // if target is an inventory, e.g. chest, machine, drawers... - if (aTileEntity2 instanceof IInventory tPutInventory) { + if (toObject instanceof IInventory toInventory) { // partially filled slot spare space mapping. // value is the sum of all spare space left not counting completely empty slot - final HashMap<ItemId, Integer> tPutItems = new HashMap<>(tPutInventory.getSizeInventory()); + final HashMap<ItemId, Integer> tPutItems = new HashMap<>(toInventory.getSizeInventory()); // partially filled slot contents - final HashMap<ItemId, List<ItemStack>> tPutItemStacks = new HashMap<>(tPutInventory.getSizeInventory()); + final HashMap<ItemId, List<ItemStack>> tPutItemStacks = new HashMap<>(toInventory.getSizeInventory()); // completely empty slots - final List<Integer> tPutFreeSlots = new ArrayList<>(tPutInventory.getSizeInventory()); + final List<Integer> tPutFreeSlots = new ArrayList<>(toInventory.getSizeInventory()); // find possible target slots int[] accessibleSlots = null; - if (aTileEntity2 instanceof ISidedInventory) - accessibleSlots = ((ISidedInventory) tPutInventory).getAccessibleSlotsFromSide(aPutTo); - for (int i = 0; i < tPutInventory.getSizeInventory(); i++) { + if (toObject instanceof ISidedInventory sided) + accessibleSlots = sided.getAccessibleSlotsFromSide(putSide.ordinal()); + for (int i = 0; i < toInventory.getSizeInventory(); i++) { int slot = i; if (accessibleSlots != null) { if (accessibleSlots.length <= i) break; slot = accessibleSlots[slot]; } - ItemStack s = tPutInventory.getStackInSlot(slot); + ItemStack s = toInventory.getStackInSlot(slot); if (s == null) { tPutFreeSlots.add(slot); - } else if ((s.stackSize < s.getMaxStackSize() && s.stackSize < tPutInventory.getInventoryStackLimit()) + } else if ((s.stackSize < s.getMaxStackSize() && s.stackSize < toInventory.getInventoryStackLimit()) && aMinMoveAtOnce <= s.getMaxStackSize() - s.stackSize) { ItemId sID = ItemId.createNoCopy(s); tPutItems.merge( sID, - (Math.min(s.getMaxStackSize(), tPutInventory.getInventoryStackLimit()) - s.stackSize), + (Math.min(s.getMaxStackSize(), toInventory.getInventoryStackLimit()) - s.stackSize), Integer::sum); tPutItemStacks.computeIfAbsent(sID, k -> new ArrayList<>()) .add(s); @@ -849,11 +841,11 @@ public class GT_Utility { // target completely filled, bail out if (tPutItems.isEmpty() && tPutFreeSlots.isEmpty()) { // maybe target is a double chest. check it. - if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) return moveToAdjacentChests( - aTileEntity1, - (TileEntityChest) aTileEntity2, - aGrabFrom, - aPutTo, + if (aDoCheckChests && toObject instanceof TileEntityChest chest) return moveToAdjacentChests( + fromInventory, + chest, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -872,7 +864,7 @@ public class GT_Utility { int tStackSize; do { tMovedItems = 0; - final ItemStack tGrabStack = aTileEntity1.getStackInSlot(grabSlot); + final ItemStack tGrabStack = fromInventory.getStackInSlot(grabSlot); if (tGrabStack == null) break; tStackSize = tGrabStack.stackSize; final ItemId sID = ItemId.createNoCopy(tGrabStack); @@ -891,7 +883,7 @@ public class GT_Utility { final int sToPut = Math.min( Math.min( Math.min(toPut, s.getMaxStackSize() - s.stackSize), - tPutInventory.getInventoryStackLimit() - s.stackSize), + toInventory.getInventoryStackLimit() - s.stackSize), aMaxTargetStackSize - s.stackSize); if (sToPut <= 0) continue; if (sToPut < aMinMoveAtOnce) continue; @@ -899,7 +891,7 @@ public class GT_Utility { toPut -= sToPut; s.stackSize += sToPut; if (s.stackSize == s.getMaxStackSize() - || s.stackSize == tPutInventory.getInventoryStackLimit()) { + || s.stackSize == toInventory.getInventoryStackLimit()) { // this slot is full. remove this stack from candidate list putStack.remove(i); i--; @@ -913,11 +905,11 @@ public class GT_Utility { // deduct spare space tPutItems.merge(sID, tMovedItems, (a, b) -> a.equals(b) ? null : a - b); - if (tStackSize == 0) aTileEntity1.setInventorySlotContents(grabSlot, null); + if (tStackSize == 0) fromInventory.setInventorySlotContents(grabSlot, null); else tGrabStack.stackSize = tStackSize; - aTileEntity1.markDirty(); - tPutInventory.markDirty(); + fromInventory.markDirty(); + toInventory.markDirty(); } } } @@ -926,11 +918,11 @@ public class GT_Utility { if (tStackSize > 0 && !tPutFreeSlots.isEmpty()) { for (int i = 0; i < tPutFreeSlots.size(); i++) { final int tPutSlot = tPutFreeSlots.get(i); - if (isAllowedToPutIntoSlot(tPutInventory, tPutSlot, aPutTo, tGrabStack, (byte) 64)) { + if (isAllowedToPutIntoSlot(toInventory, tPutSlot, putSide, tGrabStack, (byte) 64)) { // allowed, now do moving final int tMoved = moveStackFromSlotAToSlotB( - aTileEntity1, - tPutInventory, + fromInventory, + toInventory, grabSlot, tPutSlot, aMaxTargetStackSize, @@ -938,12 +930,12 @@ public class GT_Utility { (byte) (aMaxMoveAtOnce - tMovedItems), aMinMoveAtOnce); if (tMoved > 0) { - final ItemStack s = tPutInventory.getStackInSlot(tPutSlot); + final ItemStack s = toInventory.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 final int spare = Math - .min(s.getMaxStackSize(), tPutInventory.getInventoryStackLimit()) + .min(s.getMaxStackSize(), toInventory.getInventoryStackLimit()) - s.stackSize; if (spare > 0) { final ItemId ssID = ItemId.createNoCopy(s); @@ -977,12 +969,12 @@ 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) { + if (aDoCheckChests && fromInventory instanceof TileEntityChest chest) { final int tAmount = moveFromAdjacentChests( - (TileEntityChest) aTileEntity1, - aTileEntity2, - aGrabFrom, - aPutTo, + chest, + toObject, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -994,12 +986,12 @@ 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) { + if (aDoCheckChests && toObject instanceof TileEntityChest chest) { final int tAmount = moveToAdjacentChests( - aTileEntity1, - (TileEntityChest) aTileEntity2, - aGrabFrom, - aPutTo, + fromInventory, + chest, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1018,11 +1010,11 @@ public class GT_Utility { final int tGrabInventorySize = tGrabSlots.length; for (int i = 0; i < tGrabInventorySize; i++) { final int tMoved = moveStackIntoPipe( - aTileEntity1, - aTileEntity2, + fromInventory, + toObject, tGrabSlots, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1036,16 +1028,17 @@ public class GT_Utility { return 0; } - private static int moveToAdjacentChests(IInventory aTileEntity1, TileEntityChest aTargetChest, byte aGrabFrom, - byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, - byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aMaxStackTransfer) { + private static int moveToAdjacentChests(IInventory aTileEntity1, TileEntityChest aTargetChest, + ForgeDirection fromSide, ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, + byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, + int aMaxStackTransfer) { if (aTargetChest.adjacentChestChecked) { if (aTargetChest.adjacentChestXNeg != null) { return moveMultipleItemStacks( aTileEntity1, aTargetChest.adjacentChestXNeg, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1058,8 +1051,8 @@ public class GT_Utility { return moveMultipleItemStacks( aTileEntity1, aTargetChest.adjacentChestZNeg, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1072,8 +1065,8 @@ public class GT_Utility { return moveMultipleItemStacks( aTileEntity1, aTargetChest.adjacentChestXPos, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1086,8 +1079,8 @@ public class GT_Utility { return moveMultipleItemStacks( aTileEntity1, aTargetChest.adjacentChestZPos, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1101,15 +1094,16 @@ public class GT_Utility { return 0; } - private static int moveFromAdjacentChests(TileEntityChest aChest, Object aTileEntity2, byte aGrabFrom, byte aPutTo, - List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, - byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aMaxStackTransfer) { - if (aChest.adjacentChestXNeg != null) { + private static int moveFromAdjacentChests(TileEntityChest fromTileEntityChest, Object toObject, + ForgeDirection fromSide, ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, + byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, + int aMaxStackTransfer) { + if (fromTileEntityChest.adjacentChestXNeg != null) { return moveMultipleItemStacks( - aChest.adjacentChestXNeg, - aTileEntity2, - aGrabFrom, - aPutTo, + fromTileEntityChest.adjacentChestXNeg, + toObject, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1118,12 +1112,12 @@ public class GT_Utility { aMinMoveAtOnce, aMaxStackTransfer, false); - } else if (aChest.adjacentChestZNeg != null) { + } else if (fromTileEntityChest.adjacentChestZNeg != null) { return moveMultipleItemStacks( - aChest.adjacentChestZNeg, - aTileEntity2, - aGrabFrom, - aPutTo, + fromTileEntityChest.adjacentChestZNeg, + toObject, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1132,12 +1126,12 @@ public class GT_Utility { aMinMoveAtOnce, aMaxStackTransfer, false); - } else if (aChest.adjacentChestXPos != null) { + } else if (fromTileEntityChest.adjacentChestXPos != null) { return moveMultipleItemStacks( - aChest.adjacentChestXPos, - aTileEntity2, - aGrabFrom, - aPutTo, + fromTileEntityChest.adjacentChestXPos, + toObject, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1146,12 +1140,12 @@ public class GT_Utility { aMinMoveAtOnce, aMaxStackTransfer, false); - } else if (aChest.adjacentChestZPos != null) { + } else if (fromTileEntityChest.adjacentChestZPos != null) { return moveMultipleItemStacks( - aChest.adjacentChestZPos, - aTileEntity2, - aGrabFrom, - aPutTo, + fromTileEntityChest.adjacentChestZPos, + toObject, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1169,14 +1163,14 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static byte moveOneItemStack(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, - List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, - byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (aTileEntity1 instanceof IInventory) return moveOneItemStack( - (IInventory) aTileEntity1, - aTileEntity2, - aGrabFrom, - aPutTo, + public static byte moveOneItemStack(Object fromObject, Object toObject, ForgeDirection fromSide, + ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, + byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + if (fromObject instanceof IInventory inv) return moveOneItemStack( + inv, + toObject, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1190,190 +1184,184 @@ public class GT_Utility { /** * This is only because I needed an additional Parameter for the Double Chest Check. */ - private static byte moveOneItemStack(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, - List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, - byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { - if (aTileEntity1 == null || aMaxTargetStackSize <= 0 + private static byte moveOneItemStack(IInventory fromInventory, Object toObject, ForgeDirection fromSide, + ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, + byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { + if (fromInventory == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; int[] tGrabSlots = null; - if (aTileEntity1 instanceof ISidedInventory) - tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); + if (fromInventory instanceof ISidedInventory) + tGrabSlots = ((ISidedInventory) fromInventory).getAccessibleSlotsFromSide(fromSide.ordinal()); if (tGrabSlots == null) { - tGrabSlots = new int[aTileEntity1.getSizeInventory()]; + tGrabSlots = new int[fromInventory.getSizeInventory()]; for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; } - if (aTileEntity2 instanceof IInventory) { + if (toObject instanceof IInventory inv) { int[] tPutSlots = null; - if (aTileEntity2 instanceof ISidedInventory) - tPutSlots = ((ISidedInventory) aTileEntity2).getAccessibleSlotsFromSide(aPutTo); + if (toObject instanceof ISidedInventory sided) + tPutSlots = sided.getAccessibleSlotsFromSide(putSide.ordinal()); if (tPutSlots == null) { - tPutSlots = new int[((IInventory) aTileEntity2).getSizeInventory()]; + tPutSlots = new int[inv.getSizeInventory()]; for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i; } - for (int tGrabSlot : tGrabSlots) { + for (final int tGrabSlot : tGrabSlots) { byte tMovedItemCount = 0; - ItemStack tGrabStack = aTileEntity1.getStackInSlot(tGrabSlot); - if (listContainsItem(aFilter, tGrabStack, true, aInvertFilter)) { - if (tGrabStack.stackSize >= aMinMoveAtOnce - && isAllowedToTakeFromSlot(aTileEntity1, tGrabSlot, aGrabFrom, tGrabStack)) { - for (int tPutSlot : tPutSlots) { - if (isAllowedToPutIntoSlot( - (IInventory) aTileEntity2, + final ItemStack tGrabStack = fromInventory.getStackInSlot(tGrabSlot); + if (listContainsItem(aFilter, tGrabStack, true, aInvertFilter) + && (tGrabStack.stackSize >= aMinMoveAtOnce + && isAllowedToTakeFromSlot(fromInventory, tGrabSlot, fromSide, tGrabStack))) { + for (final int tPutSlot : tPutSlots) { + if (isAllowedToPutIntoSlot(inv, tPutSlot, putSide, tGrabStack, aMaxTargetStackSize)) { + tMovedItemCount += moveStackFromSlotAToSlotB( + fromInventory, + inv, + tGrabSlot, tPutSlot, - aPutTo, - tGrabStack, - aMaxTargetStackSize)) { - tMovedItemCount += moveStackFromSlotAToSlotB( - aTileEntity1, - (IInventory) aTileEntity2, - tGrabSlot, - tPutSlot, - aMaxTargetStackSize, - aMinTargetStackSize, - (byte) (aMaxMoveAtOnce - tMovedItemCount), - aMinMoveAtOnce); - if (tMovedItemCount >= aMaxMoveAtOnce - || (tMovedItemCount > 0 && aMaxTargetStackSize < 64)) return tMovedItemCount; - } + aMaxTargetStackSize, + aMinTargetStackSize, + (byte) (aMaxMoveAtOnce - tMovedItemCount), + aMinMoveAtOnce); + if (tMovedItemCount >= aMaxMoveAtOnce || (tMovedItemCount > 0 && aMaxTargetStackSize < 64)) + return tMovedItemCount; } } + } if (tMovedItemCount > 0) return tMovedItemCount; } - if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest tTileEntity1) { - if (tTileEntity1.adjacentChestChecked) { - byte tAmount = 0; - if (tTileEntity1.adjacentChestXNeg != null) { - tAmount = moveOneItemStack( - tTileEntity1.adjacentChestXNeg, - aTileEntity2, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } else if (tTileEntity1.adjacentChestZNeg != null) { - tAmount = moveOneItemStack( - tTileEntity1.adjacentChestZNeg, - aTileEntity2, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } else if (tTileEntity1.adjacentChestXPos != null) { - tAmount = moveOneItemStack( - tTileEntity1.adjacentChestXPos, - aTileEntity2, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } else if (tTileEntity1.adjacentChestZPos != null) { - tAmount = moveOneItemStack( - tTileEntity1.adjacentChestZPos, - aTileEntity2, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } - if (tAmount != 0) return tAmount; + if (aDoCheckChests && fromInventory instanceof TileEntityChest fromChest + && (fromChest.adjacentChestChecked)) { + byte tAmount = 0; + if (fromChest.adjacentChestXNeg != null) { + tAmount = moveOneItemStack( + fromChest.adjacentChestXNeg, + toObject, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); + } else if (fromChest.adjacentChestZNeg != null) { + tAmount = moveOneItemStack( + fromChest.adjacentChestZNeg, + toObject, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); + } else if (fromChest.adjacentChestXPos != null) { + tAmount = moveOneItemStack( + fromChest.adjacentChestXPos, + toObject, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); + } else if (fromChest.adjacentChestZPos != null) { + tAmount = moveOneItemStack( + fromChest.adjacentChestZPos, + toObject, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); } + if (tAmount != 0) return tAmount; + } - if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest tTileEntity2) { - if (tTileEntity2.adjacentChestChecked) { - byte tAmount = 0; - if (tTileEntity2.adjacentChestXNeg != null) { - tAmount = moveOneItemStack( - aTileEntity1, - tTileEntity2.adjacentChestXNeg, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } else if (tTileEntity2.adjacentChestZNeg != null) { - tAmount = moveOneItemStack( - aTileEntity1, - tTileEntity2.adjacentChestZNeg, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } else if (tTileEntity2.adjacentChestXPos != null) { - tAmount = moveOneItemStack( - aTileEntity1, - tTileEntity2.adjacentChestXPos, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } else if (tTileEntity2.adjacentChestZPos != null) { - tAmount = moveOneItemStack( - aTileEntity1, - tTileEntity2.adjacentChestZPos, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - false); - } - if (tAmount != 0) return tAmount; + if (aDoCheckChests && toObject instanceof TileEntityChest toChest && (toChest.adjacentChestChecked)) { + byte tAmount = 0; + if (toChest.adjacentChestXNeg != null) { + tAmount = moveOneItemStack( + fromInventory, + toChest.adjacentChestXNeg, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); + } else if (toChest.adjacentChestZNeg != null) { + tAmount = moveOneItemStack( + fromInventory, + toChest.adjacentChestZNeg, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); + } else if (toChest.adjacentChestXPos != null) { + tAmount = moveOneItemStack( + fromInventory, + toChest.adjacentChestXPos, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); + } else if (toChest.adjacentChestZPos != null) { + tAmount = moveOneItemStack( + fromInventory, + toChest.adjacentChestZPos, + fromSide, + putSide, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + false); } + if (tAmount != 0) return tAmount; + } } return moveStackIntoPipe( - aTileEntity1, - aTileEntity2, + fromInventory, + toObject, tGrabSlots, - aGrabFrom, - aPutTo, + fromSide, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1388,11 +1376,10 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static byte moveOneItemStackIntoSlot(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, int aPutTo, - List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, + public static byte moveOneItemStackIntoSlot(Object fromTileEntity, Object toTileEntity, ForgeDirection fromSide, + int putSlot, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (aTileEntity1 == null || !(aTileEntity1 instanceof IInventory) - || aPutTo < 0 + if (fromTileEntity == null || !(fromTileEntity instanceof IInventory fromInv) || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 @@ -1400,36 +1387,28 @@ public class GT_Utility { || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; int[] tGrabSlots = null; - if (aTileEntity1 instanceof ISidedInventory) - tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom); + if (fromTileEntity instanceof ISidedInventory sided) + tGrabSlots = sided.getAccessibleSlotsFromSide(fromSide.ordinal()); if (tGrabSlots == null) { - tGrabSlots = new int[((IInventory) aTileEntity1).getSizeInventory()]; + tGrabSlots = new int[fromInv.getSizeInventory()]; for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i; } - if (aTileEntity2 instanceof IInventory) { - for (int tGrabSlot : tGrabSlots) { - if (listContainsItem( - aFilter, - ((IInventory) aTileEntity1).getStackInSlot(tGrabSlot), - true, - aInvertFilter)) { - if (isAllowedToTakeFromSlot( - (IInventory) aTileEntity1, - tGrabSlot, - aGrabFrom, - ((IInventory) aTileEntity1).getStackInSlot(tGrabSlot))) { + if (toTileEntity instanceof IInventory toInv) { + for (final int tGrabSlot : tGrabSlots) { + if (listContainsItem(aFilter, fromInv.getStackInSlot(tGrabSlot), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot(fromInv, tGrabSlot, fromSide, fromInv.getStackInSlot(tGrabSlot))) { if (isAllowedToPutIntoSlot( - (IInventory) aTileEntity2, - aPutTo, - (byte) 6, - ((IInventory) aTileEntity1).getStackInSlot(tGrabSlot), + toInv, + putSlot, + ForgeDirection.UNKNOWN, + fromInv.getStackInSlot(tGrabSlot), aMaxTargetStackSize)) { byte tMovedItemCount = moveStackFromSlotAToSlotB( - (IInventory) aTileEntity1, - (IInventory) aTileEntity2, + fromInv, + toInv, tGrabSlot, - aPutTo, + putSlot, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, @@ -1441,12 +1420,13 @@ public class GT_Utility { } } + final ForgeDirection toSide = fromSide.getOpposite(); moveStackIntoPipe( - ((IInventory) aTileEntity1), - aTileEntity2, + fromInv, + toTileEntity, tGrabSlots, - aGrabFrom, - aPutTo, + fromSide, + ForgeDirection.UNKNOWN, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1461,28 +1441,31 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static byte moveFromSlotToSlot(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, int aPutTo, + public static byte moveFromSlotToSlot(IInventory fromInv, IInventory toInv, int aGrabFrom, int aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { - if (aTileEntity1 == null || aTileEntity2 == null + if (fromInv == null || toInv == null || aGrabFrom < 0 || aPutTo < 0 - || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; - if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabFrom), true, aInvertFilter)) { - if (isAllowedToTakeFromSlot(aTileEntity1, aGrabFrom, (byte) 6, aTileEntity1.getStackInSlot(aGrabFrom))) { + if (listContainsItem(aFilter, fromInv.getStackInSlot(aGrabFrom), true, aInvertFilter)) { + if (isAllowedToTakeFromSlot( + fromInv, + aGrabFrom, + ForgeDirection.UNKNOWN, + fromInv.getStackInSlot(aGrabFrom))) { if (isAllowedToPutIntoSlot( - aTileEntity2, + toInv, aPutTo, - (byte) 6, - aTileEntity1.getStackInSlot(aGrabFrom), + ForgeDirection.UNKNOWN, + fromInv.getStackInSlot(aGrabFrom), aMaxTargetStackSize)) { byte tMovedItemCount = moveStackFromSlotAToSlotB( - aTileEntity1, - aTileEntity2, + fromInv, + toInv, aGrabFrom, aPutTo, aMaxTargetStackSize, @@ -1501,22 +1484,23 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int aGrabFrom, byte aPutTo, + public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int fromSlot, ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { - if (fromTile == null || aGrabFrom < 0 + if (fromTile == null || fromSlot < 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; - if (!listContainsItem(aFilter, fromTile.getStackInSlot(aGrabFrom), true, aInvertFilter) - || !isAllowedToTakeFromSlot(fromTile, aGrabFrom, (byte) 6, fromTile.getStackInSlot(aGrabFrom))) return 0; + if (!listContainsItem(aFilter, fromTile.getStackInSlot(fromSlot), true, aInvertFilter) + || !isAllowedToTakeFromSlot(fromTile, fromSlot, ForgeDirection.UNKNOWN, fromTile.getStackInSlot(fromSlot))) + return 0; if (toTile instanceof IInventory) { int[] tPutSlots = null; - if (toTile instanceof ISidedInventory) - tPutSlots = ((ISidedInventory) toTile).getAccessibleSlotsFromSide(aPutTo); + if (toTile instanceof ISidedInventory sided) + tPutSlots = sided.getAccessibleSlotsFromSide(putSide.ordinal()); if (tPutSlots == null) { tPutSlots = new int[((IInventory) toTile).getSizeInventory()]; @@ -1524,17 +1508,17 @@ public class GT_Utility { } byte tMovedItemCount = 0; - for (int tPutSlot : tPutSlots) { + for (final int tPutSlot : tPutSlots) { if (isAllowedToPutIntoSlot( (IInventory) toTile, tPutSlot, - aPutTo, - fromTile.getStackInSlot(aGrabFrom), + putSide, + fromTile.getStackInSlot(fromSlot), aMaxTargetStackSize)) { tMovedItemCount += moveStackFromSlotAToSlotB( fromTile, (IInventory) toTile, - aGrabFrom, + fromSlot, tPutSlot, aMaxTargetStackSize, aMinTargetStackSize, @@ -1553,8 +1537,8 @@ public class GT_Utility { tMovedItemCount = moveFromSlotToSide( fromTile, tTileEntity2.adjacentChestXNeg, - aGrabFrom, - aPutTo, + fromSlot, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1566,8 +1550,8 @@ public class GT_Utility { tMovedItemCount = moveFromSlotToSide( fromTile, tTileEntity2.adjacentChestZNeg, - aGrabFrom, - aPutTo, + fromSlot, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1579,8 +1563,8 @@ public class GT_Utility { tMovedItemCount = moveFromSlotToSide( fromTile, tTileEntity2.adjacentChestXPos, - aGrabFrom, - aPutTo, + fromSlot, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1592,8 +1576,8 @@ public class GT_Utility { tMovedItemCount = moveFromSlotToSide( fromTile, tTileEntity2.adjacentChestZPos, - aGrabFrom, - aPutTo, + fromSlot, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1609,9 +1593,9 @@ public class GT_Utility { return moveStackIntoPipe( fromTile, toTile, - new int[] { aGrabFrom }, - (byte) 6, - aPutTo, + new int[] { fromSlot }, + ForgeDirection.UNKNOWN, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -1621,14 +1605,14 @@ public class GT_Utility { aDoCheckChests); } - public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int aGrabFrom, byte aPutTo, + public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int fromSlot, ForgeDirection putSide, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { return moveFromSlotToSide( fromTile, toTile, - aGrabFrom, - aPutTo, + fromSlot, + putSide, aFilter, aInvertFilter, aMaxTargetStackSize, @@ -3168,7 +3152,7 @@ public class GT_Utility { } public static int getCoordinateScan(ArrayList<String> aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, - int aX, int aY, int aZ, int aSide, float aClickX, float aClickY, float aClickZ) { + int aX, int aY, int aZ, ForgeDirection side, float aClickX, float aClickY, float aClickZ) { if (aList == null) return 0; ArrayList<String> tList = new ArrayList<>(); @@ -3178,6 +3162,65 @@ public class GT_Utility { final Block tBlock = aWorld.getBlock(aX, aY, aZ); + addBaseInfo(aPlayer, aWorld, aX, aY, aZ, tList, tTileEntity, tBlock); + + if (tTileEntity != null) { + rEUAmount += addFluidHandlerInfo(side, tList, tTileEntity); + + try { + if (tTileEntity instanceof ic2.api.reactor.IReactorChamber chamber) { + rEUAmount += 500; + // Redirect the rest of the scans to the reactor itself + tTileEntity = (TileEntity) chamber.getReactor(); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + rEUAmount += addReactorInfo(tList, tTileEntity); + rEUAmount += addAlignmentInfo(tList, tTileEntity); + rEUAmount += addIC2WrenchableInfo(aPlayer, tList, tTileEntity); + rEUAmount += addIC2EnergyConductorInfo(tList, tTileEntity); + rEUAmount += addIC2EnergyStorageInfo(tList, tTileEntity); + rEUAmount += addUpgradableMachineInfo(tList, tTileEntity); + rEUAmount += addMachineProgressInfo(tList, tTileEntity); + rEUAmount += addCoverableInfo(side, tList, tTileEntity); + addEnergyContainerInfo(tList, tTileEntity); + addOwnerInfo(tList, tTileEntity); + addDeviceInfo(tList, tTileEntity); + + rEUAmount += addIC2CropInfo(tList, tTileEntity); + + rEUAmount += addForestryLeavesInfo(tList, tTileEntity); + } + + final Chunk currentChunk = aWorld.getChunkFromBlockCoords(aX, aZ); + addUndergroundFluidInfo(aPlayer, tList, currentChunk); + addPollutionInfo(tList, currentChunk); + + rEUAmount += addDebuggableBlockInfo(aPlayer, aX, aY, aZ, tList, tBlock); + + final BlockScanningEvent tEvent = new BlockScanningEvent( + aWorld, + aPlayer, + aX, + aY, + aZ, + side, + aScanLevel, + tBlock, + tTileEntity, + tList, + aClickX, + aClickY, + aClickZ); + tEvent.mEUCost = rEUAmount; + MinecraftForge.EVENT_BUS.post(tEvent); + if (!tEvent.isCanceled()) aList.addAll(tList); + return tEvent.mEUCost; + } + + private static void addBaseInfo(EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, ArrayList<String> tList, + TileEntity tTileEntity, Block tBlock) { tList.add( "----- X: " + EnumChatFormatting.AQUA + formatNumbers(aX) @@ -3196,23 +3239,14 @@ public class GT_Utility { + EnumChatFormatting.RESET + " -----"); try { - if (tTileEntity instanceof IInventory) tList.add( - GT_Utility.trans("162", "Name: ") + EnumChatFormatting.BLUE - + ((IInventory) tTileEntity).getInventoryName() - + EnumChatFormatting.RESET - + GT_Utility.trans("163", " MetaData: ") - + EnumChatFormatting.AQUA - + aWorld.getBlockMetadata(aX, aY, aZ) - + EnumChatFormatting.RESET); - else tList.add( + tList.add( GT_Utility.trans("162", "Name: ") + EnumChatFormatting.BLUE - + tBlock.getUnlocalizedName() + + ((tTileEntity instanceof IInventory inv) ? inv.getInventoryName() : tBlock.getUnlocalizedName()) + EnumChatFormatting.RESET + GT_Utility.trans("163", " MetaData: ") + EnumChatFormatting.AQUA + aWorld.getBlockMetadata(aX, aY, aZ) + EnumChatFormatting.RESET); - tList.add( GT_Utility.trans("164", "Hardness: ") + EnumChatFormatting.YELLOW + tBlock.getBlockHardness(aWorld, aX, aY, aZ) @@ -3228,288 +3262,67 @@ public class GT_Utility { } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); } - if (tTileEntity != null) { - try { - if (tTileEntity instanceof IFluidHandler) { - rEUAmount += 500; - final FluidTankInfo[] tTanks = ((IFluidHandler) tTileEntity) - .getTankInfo(ForgeDirection.getOrientation(aSide)); - if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { - tList.add( - GT_Utility.trans("167", "Tank ") + i - + ": " - + EnumChatFormatting.GREEN - + formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) - + EnumChatFormatting.RESET - + " L / " - + EnumChatFormatting.YELLOW - + formatNumbers(tTanks[i].capacity) - + EnumChatFormatting.RESET - + " L " - + EnumChatFormatting.GOLD - + getFluidName(tTanks[i].fluid, true) - + EnumChatFormatting.RESET); - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.reactor.IReactorChamber) { - rEUAmount += 500; - tTileEntity = (TileEntity) (((ic2.api.reactor.IReactorChamber) tTileEntity).getReactor()); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.reactor.IReactor) { - rEUAmount += 500; - tList.add( - GT_Utility.trans("168", "Heat: ") + EnumChatFormatting.GREEN - + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getHeat()) - + EnumChatFormatting.RESET - + " / " - + EnumChatFormatting.YELLOW - + formatNumbers(((ic2.api.reactor.IReactor) tTileEntity).getMaxHeat()) - + EnumChatFormatting.RESET); - tList.add( - GT_Utility.trans("169", "HEM: ") + EnumChatFormatting.YELLOW - + ((ic2.api.reactor.IReactor) tTileEntity).getHeatEffectModifier() - + EnumChatFormatting.RESET - /* - * + GT_Utility.trans("170"," Base EU Output: ")/* + - * ((ic2.api.reactor.IReactor)tTileEntity).getOutput() - */ ); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IAlignmentProvider) { - final IAlignment tAlignment = ((IAlignmentProvider) tTileEntity).getAlignment(); - if (tAlignment != null) { - rEUAmount += 100; - tList.add( - GT_Utility.trans("219", "Extended Facing: ") + EnumChatFormatting.GREEN - + tAlignment.getExtendedFacing() - + EnumChatFormatting.RESET); - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.tile.IWrenchable) { - rEUAmount += 100; - tList.add( - GT_Utility.trans("171", "Facing: ") + EnumChatFormatting.GREEN - + ((ic2.api.tile.IWrenchable) tTileEntity).getFacing() - + EnumChatFormatting.RESET - + GT_Utility.trans("172", " / Chance: ") - + EnumChatFormatting.YELLOW - + (((ic2.api.tile.IWrenchable) tTileEntity).getWrenchDropRate() * 100) - + EnumChatFormatting.RESET - + "%"); - tList.add( - ((ic2.api.tile.IWrenchable) tTileEntity).wrenchCanRemove(aPlayer) - ? EnumChatFormatting.GREEN + GT_Utility.trans("173", "You can remove this with a Wrench") - + EnumChatFormatting.RESET - : EnumChatFormatting.RED + GT_Utility.trans("174", "You can NOT remove this with a Wrench") - + EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor) { - rEUAmount += 200; - tList.add( - GT_Utility.trans("175", "Conduction Loss: ") + EnumChatFormatting.YELLOW - + ((ic2.api.energy.tile.IEnergyConductor) tTileEntity).getConductionLoss() - + EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.tile.IEnergyStorage) { - rEUAmount += 200; - tList.add( - GT_Utility.trans("176", "Contained Energy: ") + EnumChatFormatting.YELLOW - + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getStored()) - + EnumChatFormatting.RESET - + " EU / " - + EnumChatFormatting.YELLOW - + formatNumbers(((ic2.api.tile.IEnergyStorage) tTileEntity).getCapacity()) - + EnumChatFormatting.RESET - + " EU"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IUpgradableMachine) { - rEUAmount += 500; - if (((IUpgradableMachine) tTileEntity).hasMufflerUpgrade()) tList.add( - EnumChatFormatting.GREEN + GT_Utility.trans("177", "Has Muffler Upgrade") - + EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IMachineProgress) { - if (((IMachineProgress) tTileEntity).isAllowedToWork()) { - tList.add(EnumChatFormatting.RED + "Disabled." + EnumChatFormatting.RESET); - } - if (((IMachineProgress) tTileEntity).wasShutdown()) { - tList.add(EnumChatFormatting.RED + "Shut down due to power loss." + EnumChatFormatting.RESET); - } - rEUAmount += 400; - int tValue = 0; - if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) tList.add( - GT_Utility.trans("178", "Progress/Load: ") + EnumChatFormatting.GREEN - + formatNumbers(((IMachineProgress) tTileEntity).getProgress()) - + EnumChatFormatting.RESET - + " / " - + EnumChatFormatting.YELLOW - + formatNumbers(tValue) - + EnumChatFormatting.RESET); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ICoverable) { - rEUAmount += 300; - final String tString = ((ICoverable) tTileEntity).getCoverInfoAtSide((byte) aSide) - .getBehaviorDescription(); - if (tString != null && !tString.equals(E)) tList.add(tString); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IBasicEnergyContainer - && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { - tList.add( - GT_Utility.trans("179", "Max IN: ") + EnumChatFormatting.RED - + formatNumbers(((IBasicEnergyContainer) tTileEntity).getInputVoltage()) - + " (" - + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getInputVoltage())] - + ") " - + EnumChatFormatting.RESET - + GT_Utility.trans("182", " EU at ") - + EnumChatFormatting.RED - + formatNumbers(((IBasicEnergyContainer) tTileEntity).getInputAmperage()) - + EnumChatFormatting.RESET - + GT_Utility.trans("183", " A")); - tList.add( - GT_Utility.trans("181", "Max OUT: ") + EnumChatFormatting.RED - + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputVoltage()) - + " (" - + GT_Values.VN[getTier(((IBasicEnergyContainer) tTileEntity).getOutputVoltage())] - + ") " - + EnumChatFormatting.RESET - + GT_Utility.trans("182", " EU at ") - + EnumChatFormatting.RED - + formatNumbers(((IBasicEnergyContainer) tTileEntity).getOutputAmperage()) - + EnumChatFormatting.RESET - + GT_Utility.trans("183", " A")); + } + + private static int addFluidHandlerInfo(ForgeDirection side, ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof IFluidHandler fluidHandler) { + rEUAmount += 500; + final FluidTankInfo[] tTanks = fluidHandler.getTankInfo(side); + if (tTanks != null) for (byte i = 0; i < tTanks.length; i++) { tList.add( - GT_Utility.trans("184", "Energy: ") + EnumChatFormatting.GREEN - + formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + GT_Utility.trans("167", "Tank ") + i + + ": " + + EnumChatFormatting.GREEN + + formatNumbers((tTanks[i].fluid == null ? 0 : tTanks[i].fluid.amount)) + EnumChatFormatting.RESET - + " EU / " + + " L / " + EnumChatFormatting.YELLOW - + formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + + formatNumbers(tTanks[i].capacity) + EnumChatFormatting.RESET - + " EU"); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IGregTechTileEntity) { - tList.add( - GT_Utility.trans("186", "Owned by: ") + EnumChatFormatting.BLUE - + ((IGregTechTileEntity) tTileEntity).getOwnerName() + + " L " + + EnumChatFormatting.GOLD + + getFluidName(tTanks[i].fluid, true) + EnumChatFormatting.RESET); } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof IGregTechDeviceInformation - && ((IGregTechDeviceInformation) tTileEntity).isGivingInformation()) { - tList.addAll(Arrays.asList(((IGregTechDeviceInformation) tTileEntity).getInfoData())); - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); - } - try { - if (tTileEntity instanceof ic2.api.crops.ICropTile crop) { - rEUAmount += 1000; - if (crop.getScanLevel() < 4) crop.setScanLevel((byte) 4); - if (crop.getCrop() != null) { - tList.add( - GT_Utility.trans("187", "Type -- Crop-Name: ") + crop.getCrop() - .name() - + GT_Utility.trans("188", " Growth: ") - + crop.getGrowth() - + GT_Utility.trans("189", " Gain: ") - + crop.getGain() - + GT_Utility.trans("190", " Resistance: ") - + crop.getResistance()); - } - tList.add( - GT_Utility.trans("191", "Plant -- Fertilizer: ") + crop.getNutrientStorage() - + GT_Utility.trans("192", " Water: ") - + crop.getHydrationStorage() - + GT_Utility.trans("193", " Weed-Ex: ") - + crop.getWeedExStorage() - + GT_Utility.trans("194", " Scan-Level: ") - + crop.getScanLevel()); - tList.add( - GT_Utility.trans("195", "Environment -- Nutrients: ") + crop.getNutrients() - + GT_Utility.trans("196", " Humidity: ") - + crop.getHumidity() - + GT_Utility.trans("197", " Air-Quality: ") - + crop.getAirQuality()); - if (crop.getCrop() != null) { - final StringBuilder tStringB = new StringBuilder(); - for (String tAttribute : crop.getCrop() - .attributes()) { - tStringB.append(", ") - .append(tAttribute); - } - final String tString = tStringB.toString(); - tList.add(GT_Utility.trans("198", "Attributes:") + tString.replaceFirst(",", E)); - tList.add( - GT_Utility.trans("199", "Discovered by: ") + crop.getCrop() - .discoveredBy()); - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } - try { - if (tTileEntity instanceof forestry.arboriculture.tiles.TileLeaves tileLeaves) { - final forestry.api.arboriculture.ITree tree = tileLeaves.getTree(); - if (tree != null) { - rEUAmount += 1000; - if (!tree.isAnalyzed()) tree.analyze(); - tree.addTooltip(tList); - } - } - } catch (Throwable e) { - if (D1) e.printStackTrace(GT_Log.err); + private static int addDebuggableBlockInfo(EntityPlayer aPlayer, int aX, int aY, int aZ, ArrayList<String> tList, + Block tBlock) { + int rEUAmount = 0; + try { + if (tBlock instanceof IDebugableBlock debugableBlock) { + rEUAmount += 500; + final ArrayList<String> temp = debugableBlock.getDebugInfo(aPlayer, aX, aY, aZ, 3); + if (temp != null) tList.addAll(temp); } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); } + return rEUAmount; + } - final Chunk currentChunk = aWorld.getChunkFromBlockCoords(aX, aZ); + private static void addPollutionInfo(ArrayList<String> tList, Chunk currentChunk) { + if (GT_Pollution.hasPollution(currentChunk)) { + tList.add( + GT_Utility.trans("202", "Pollution in Chunk: ") + EnumChatFormatting.RED + + formatNumbers(GT_Pollution.getPollution(currentChunk)) + + EnumChatFormatting.RESET + + GT_Utility.trans("203", " gibbl")); + } else { + tList.add( + EnumChatFormatting.GREEN + GT_Utility.trans("204", "No Pollution in Chunk! HAYO!") + + EnumChatFormatting.RESET); + } + } + + private static void addUndergroundFluidInfo(EntityPlayer aPlayer, ArrayList<String> tList, Chunk currentChunk) { if (aPlayer.capabilities.isCreativeMode) { final FluidStack tFluid = undergroundOilReadInformation(currentChunk); // -# to only read if (tFluid != null) tList.add( @@ -3529,47 +3342,303 @@ public class GT_Utility { + EnumChatFormatting.RESET + " L"); } - // if(aPlayer.capabilities.isCreativeMode){ - if (GT_Pollution.hasPollution(currentChunk)) { - tList.add( - GT_Utility.trans("202", "Pollution in Chunk: ") + EnumChatFormatting.RED - + formatNumbers(GT_Pollution.getPollution(currentChunk)) - + EnumChatFormatting.RESET - + GT_Utility.trans("203", " gibbl")); - } else { - tList.add( - EnumChatFormatting.GREEN + GT_Utility.trans("204", "No Pollution in Chunk! HAYO!") - + EnumChatFormatting.RESET); + } + + private static int addForestryLeavesInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof forestry.arboriculture.tiles.TileLeaves tileLeaves) { + final forestry.api.arboriculture.ITree tree = tileLeaves.getTree(); + if (tree != null) { + rEUAmount += 1000; + if (!tree.isAnalyzed()) tree.analyze(); + tree.addTooltip(tList); + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); } + return rEUAmount; + } + private static int addIC2CropInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof ic2.api.crops.ICropTile crop) { + rEUAmount += 1000; + if (crop.getScanLevel() < 4) crop.setScanLevel((byte) 4); + if (crop.getCrop() != null) { + tList.add( + GT_Utility.trans("187", "Type -- Crop-Name: ") + crop.getCrop() + .name() + + GT_Utility.trans("188", " Growth: ") + + crop.getGrowth() + + GT_Utility.trans("189", " Gain: ") + + crop.getGain() + + GT_Utility.trans("190", " Resistance: ") + + crop.getResistance()); + } + tList.add( + GT_Utility.trans("191", "Plant -- Fertilizer: ") + crop.getNutrientStorage() + + GT_Utility.trans("192", " Water: ") + + crop.getHydrationStorage() + + GT_Utility.trans("193", " Weed-Ex: ") + + crop.getWeedExStorage() + + GT_Utility.trans("194", " Scan-Level: ") + + crop.getScanLevel()); + tList.add( + GT_Utility.trans("195", "Environment -- Nutrients: ") + crop.getNutrients() + + GT_Utility.trans("196", " Humidity: ") + + crop.getHumidity() + + GT_Utility.trans("197", " Air-Quality: ") + + crop.getAirQuality()); + if (crop.getCrop() != null) { + final StringBuilder tStringB = new StringBuilder(); + for (final String tAttribute : crop.getCrop() + .attributes()) { + tStringB.append(", ") + .append(tAttribute); + } + final String tString = tStringB.toString(); + tList.add(GT_Utility.trans("198", "Attributes:") + tString.replaceFirst(",", E)); + tList.add( + GT_Utility.trans("199", "Discovered by: ") + crop.getCrop() + .discoveredBy()); + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } + + private static void addDeviceInfo(ArrayList<String> tList, TileEntity tTileEntity) { + try { + if (tTileEntity instanceof IGregTechDeviceInformation info && info.isGivingInformation()) { + tList.addAll(Arrays.asList(info.getInfoData())); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + } + + private static void addOwnerInfo(ArrayList<String> tList, TileEntity tTileEntity) { try { - if (tBlock instanceof IDebugableBlock) { + if (tTileEntity instanceof IGregTechTileEntity gtTE) { + tList.add( + GT_Utility.trans("186", "Owned by: ") + EnumChatFormatting.BLUE + + gtTE.getOwnerName() + + EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + } + + private static void addEnergyContainerInfo(ArrayList<String> tList, TileEntity tTileEntity) { + try { + if (tTileEntity instanceof IBasicEnergyContainer energyContainer && energyContainer.getEUCapacity() > 0) { + tList.add( + GT_Utility.trans("179", "Max IN: ") + EnumChatFormatting.RED + + formatNumbers(energyContainer.getInputVoltage()) + + " (" + + GT_Values.VN[getTier(energyContainer.getInputVoltage())] + + ") " + + EnumChatFormatting.RESET + + GT_Utility.trans("182", " EU at ") + + EnumChatFormatting.RED + + formatNumbers(energyContainer.getInputAmperage()) + + EnumChatFormatting.RESET + + GT_Utility.trans("183", " A")); + tList.add( + GT_Utility.trans("181", "Max OUT: ") + EnumChatFormatting.RED + + formatNumbers(energyContainer.getOutputVoltage()) + + " (" + + GT_Values.VN[getTier(energyContainer.getOutputVoltage())] + + ") " + + EnumChatFormatting.RESET + + GT_Utility.trans("182", " EU at ") + + EnumChatFormatting.RED + + formatNumbers(energyContainer.getOutputAmperage()) + + EnumChatFormatting.RESET + + GT_Utility.trans("183", " A")); + tList.add( + GT_Utility.trans("184", "Energy: ") + EnumChatFormatting.GREEN + + formatNumbers(energyContainer.getStoredEU()) + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + formatNumbers(energyContainer.getEUCapacity()) + + EnumChatFormatting.RESET + + " EU"); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + } + + private static int addCoverableInfo(ForgeDirection side, ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof ICoverable coverable) { + rEUAmount += 300; + final String tString = coverable.getCoverInfoAtSide(side) + .getBehaviorDescription(); + if (tString != null && !tString.equals(E)) tList.add(tString); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } + + private static int addMachineProgressInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof IMachineProgress progress) { + if (progress.isAllowedToWork()) { + tList.add(EnumChatFormatting.RED + "Disabled." + EnumChatFormatting.RESET); + } + if (progress.wasShutdown()) { + tList.add(EnumChatFormatting.RED + "Shut down due to power loss." + EnumChatFormatting.RESET); + } + rEUAmount += 400; + int tValue = 0; + if (0 < (tValue = progress.getMaxProgress())) tList.add( + GT_Utility.trans("178", "Progress/Load: ") + EnumChatFormatting.GREEN + + formatNumbers(progress.getProgress()) + + EnumChatFormatting.RESET + + " / " + + EnumChatFormatting.YELLOW + + formatNumbers(tValue) + + EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } + + private static int addUpgradableMachineInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof IUpgradableMachine upgradableMachine) { rEUAmount += 500; - final ArrayList<String> temp = ((IDebugableBlock) tBlock).getDebugInfo(aPlayer, aX, aY, aZ, 3); - if (temp != null) tList.addAll(temp); + if (upgradableMachine.hasMufflerUpgrade()) tList.add( + EnumChatFormatting.GREEN + GT_Utility.trans("177", "Has Muffler Upgrade") + + EnumChatFormatting.RESET); } } catch (Throwable e) { if (D1) e.printStackTrace(GT_Log.err); } + return rEUAmount; + } - final BlockScanningEvent tEvent = new BlockScanningEvent( - aWorld, - aPlayer, - aX, - aY, - aZ, - (byte) aSide, - aScanLevel, - tBlock, - tTileEntity, - tList, - aClickX, - aClickY, - aClickZ); - tEvent.mEUCost = rEUAmount; - MinecraftForge.EVENT_BUS.post(tEvent); - if (!tEvent.isCanceled()) aList.addAll(tList); - return tEvent.mEUCost; + private static int addIC2EnergyStorageInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof ic2.api.tile.IEnergyStorage storage) { + rEUAmount += 200; + tList.add( + GT_Utility.trans("176", "Contained Energy: ") + EnumChatFormatting.YELLOW + + formatNumbers(storage.getStored()) + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + formatNumbers(storage.getCapacity()) + + EnumChatFormatting.RESET + + " EU"); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } + + private static int addIC2EnergyConductorInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof ic2.api.energy.tile.IEnergyConductor conductor) { + rEUAmount += 200; + tList.add( + GT_Utility.trans("175", "Conduction Loss: ") + EnumChatFormatting.YELLOW + + conductor.getConductionLoss() + + EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } + + private static int addIC2WrenchableInfo(EntityPlayer aPlayer, ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof ic2.api.tile.IWrenchable wrenchable) { + rEUAmount += 100; + tList.add( + GT_Utility.trans("171", "Facing: ") + EnumChatFormatting.GREEN + + wrenchable.getFacing() + + EnumChatFormatting.RESET + + GT_Utility.trans("172", " / Chance: ") + + EnumChatFormatting.YELLOW + + (wrenchable.getWrenchDropRate() * 100) + + EnumChatFormatting.RESET + + "%"); + tList.add( + wrenchable.wrenchCanRemove(aPlayer) + ? EnumChatFormatting.GREEN + GT_Utility.trans("173", "You can remove this with a Wrench") + + EnumChatFormatting.RESET + : EnumChatFormatting.RED + GT_Utility.trans("174", "You can NOT remove this with a Wrench") + + EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } + + private static int addAlignmentInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof IAlignmentProvider alignmentProvider) { + final IAlignment tAlignment = alignmentProvider.getAlignment(); + if (tAlignment != null) { + rEUAmount += 100; + tList.add( + GT_Utility.trans("219", "Extended Facing: ") + EnumChatFormatting.GREEN + + tAlignment.getExtendedFacing() + + EnumChatFormatting.RESET); + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; + } + + private static int addReactorInfo(ArrayList<String> tList, TileEntity tTileEntity) { + int rEUAmount = 0; + try { + if (tTileEntity instanceof ic2.api.reactor.IReactor reactor) { + rEUAmount += 500; + tList.add( + GT_Utility.trans("168", "Heat: ") + EnumChatFormatting.GREEN + + formatNumbers(reactor.getHeat()) + + EnumChatFormatting.RESET + + " / " + + EnumChatFormatting.YELLOW + + formatNumbers(reactor.getMaxHeat()) + + EnumChatFormatting.RESET); + tList.add( + GT_Utility.trans("169", "HEM: ") + EnumChatFormatting.YELLOW + + reactor.getHeatEffectModifier() + + EnumChatFormatting.RESET); + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + return rEUAmount; } public static String trans(String aKey, String aEnglish) { @@ -3584,14 +3653,14 @@ public class GT_Utility { * @return an Array containing the X and the Y Coordinate of the clicked Point, with the top left Corner as Origin, * like on the Texture Sheet. return values should always be between [0.0F and 0.99F]. */ - public static float[] getClickedFacingCoords(byte aSide, float aX, float aY, float aZ) { - return switch (aSide) { - case 0 -> new float[] { Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, aZ)) }; - case 1 -> new float[] { Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, aZ)) }; - case 2 -> new float[] { Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, 1 - aY)) }; - case 3 -> new float[] { Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, 1 - aY)) }; - case 4 -> new float[] { Math.min(0.99F, Math.max(0, aZ)), Math.min(0.99F, Math.max(0, 1 - aY)) }; - case 5 -> new float[] { Math.min(0.99F, Math.max(0, 1 - aZ)), Math.min(0.99F, Math.max(0, 1 - aY)) }; + public static float[] getClickedFacingCoords(ForgeDirection side, float aX, float aY, float aZ) { + return switch (side) { + case DOWN -> new float[] { Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, aZ)) }; + case UP -> new float[] { Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, aZ)) }; + case NORTH -> new float[] { Math.min(0.99F, Math.max(0, 1 - aX)), Math.min(0.99F, Math.max(0, 1 - aY)) }; + case SOUTH -> new float[] { Math.min(0.99F, Math.max(0, aX)), Math.min(0.99F, Math.max(0, 1 - aY)) }; + case WEST -> new float[] { Math.min(0.99F, Math.max(0, aZ)), Math.min(0.99F, Math.max(0, 1 - aY)) }; + case EAST -> new float[] { Math.min(0.99F, Math.max(0, 1 - aZ)), Math.min(0.99F, Math.max(0, 1 - aY)) }; default -> new float[] { 0.5F, 0.5F }; }; } @@ -3600,56 +3669,56 @@ public class GT_Utility { * This Function determines the direction a Block gets when being Wrenched. returns -1 if invalid. Even though that * could never happen. */ - public static byte determineWrenchingSide(byte aSide, float aX, float aY, float aZ) { - byte tBack = getOppositeSide(aSide); - switch (aSide) { - case 0, 1 -> { + public static ForgeDirection determineWrenchingSide(ForgeDirection side, float aX, float aY, float aZ) { + ForgeDirection tBack = side.getOpposite(); + switch (side) { + case DOWN, UP -> { if (aX < 0.25) { if (aZ < 0.25) return tBack; if (aZ > 0.75) return tBack; - return 4; + return WEST; } if (aX > 0.75) { if (aZ < 0.25) return tBack; if (aZ > 0.75) return tBack; - return 5; + return EAST; } - if (aZ < 0.25) return 2; - if (aZ > 0.75) return 3; - return aSide; + if (aZ < 0.25) return NORTH; + if (aZ > 0.75) return SOUTH; + return side; } - case 2, 3 -> { + case NORTH, SOUTH -> { if (aX < 0.25) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 4; + return WEST; } if (aX > 0.75) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 5; + return WEST; } - if (aY < 0.25) return 0; - if (aY > 0.75) return 1; - return aSide; + if (aY < 0.25) return DOWN; + if (aY > 0.75) return UP; + return side; } - case 4, 5 -> { + case WEST, EAST -> { if (aZ < 0.25) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 2; + return NORTH; } if (aZ > 0.75) { if (aY < 0.25) return tBack; if (aY > 0.75) return tBack; - return 3; + return SOUTH; } - if (aY < 0.25) return 0; - if (aY > 0.75) return 1; - return aSide; + if (aY < 0.25) return DOWN; + if (aY > 0.75) return UP; + return side; } } - return -1; + return UNKNOWN; } private static DecimalFormat getDecimalFormat() { @@ -3759,7 +3828,7 @@ public class GT_Utility { if (aPlayer == null) return false; World aWorld = aPlayer.worldObj; BlockEvent.PlaceEvent event = ForgeEventFactory - .onPlayerBlockPlace(aPlayer, new BlockSnapshot(aWorld, aX, aY, aZ, aBlock, aMeta), ForgeDirection.UNKNOWN); + .onPlayerBlockPlace(aPlayer, new BlockSnapshot(aWorld, aX, aY, aZ, aBlock, aMeta), UNKNOWN); if (!event.isCanceled()) { if (!isSimulate) return aWorld.setBlock(aX, aY, aZ, aBlock, aMeta, 3); return true; diff --git a/src/main/java/gregtech/api/util/LightingHelper.java b/src/main/java/gregtech/api/util/LightingHelper.java index ad4e00fb7a..ad2510e937 100644 --- a/src/main/java/gregtech/api/util/LightingHelper.java +++ b/src/main/java/gregtech/api/util/LightingHelper.java @@ -14,6 +14,7 @@ import net.minecraft.block.Block; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; +import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -195,7 +196,7 @@ public class LightingHelper { * @param side the side * @param rgba the primary short[] RGBA color array */ - public void setupColor(int side, short[] rgba) { + public void setupColor(ForgeDirection side, short[] rgba) { setupColor(side, getColor(rgba)); } @@ -205,9 +206,9 @@ public class LightingHelper { * @param side the side * @param hexColor the primary color */ - public void setupColor(int side, int hexColor) { + public void setupColor(ForgeDirection side, int hexColor) { Tessellator tessellator = Tessellator.instance; - float lightness = hasLightnessOverride ? lightnessOverride : LIGHTNESS[side]; + float lightness = hasLightnessOverride ? lightnessOverride : LIGHTNESS[side.ordinal()]; float[] rgb = getRGB(hexColor); if (hasColorOverride && !renderBlocks.hasOverrideBlockTexture()) { @@ -306,14 +307,14 @@ public class LightingHelper { * @see #setupLightingYPos(Block, int, int, int) * @see #setupLightingZPos(Block, int, int, int) */ - public LightingHelper setupLighting(Block block, int x, int y, int z, byte facing) { + public LightingHelper setupLighting(Block block, int x, int y, int z, ForgeDirection facing) { return switch (facing) { - case 0 -> setupLightingYNeg(block, x, y, z); - case 1 -> setupLightingYPos(block, x, y, z); - case 2 -> setupLightingZNeg(block, x, y, z); - case 3 -> setupLightingZPos(block, x, y, z); - case 4 -> setupLightingXNeg(block, x, y, z); - case 5 -> setupLightingXPos(block, x, y, z); + case DOWN -> setupLightingYNeg(block, x, y, z); + case UP -> setupLightingYPos(block, x, y, z); + case NORTH -> setupLightingZNeg(block, x, y, z); + case SOUTH -> setupLightingZPos(block, x, y, z); + case WEST -> setupLightingXNeg(block, x, y, z); + case EAST -> setupLightingXPos(block, x, y, z); default -> throw new IllegalArgumentException("Unknown side: " + facing); }; } |