From 56f2269f4af6d2130bdb2b6e6ac6e13bce89e47b Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sat, 22 Apr 2023 22:33:35 -0700 Subject: Forge direction (#1895) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ForgeDirection Also refactor the clusterfuck that was `getCoordinateScan` Co-authored by: Jason Mitchell * 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 --- .../gregtech/api/events/BlockScanningEvent.java | 10 +- .../java/gregtech/api/graphs/GenerateNodeMap.java | 85 +- .../gregtech/api/graphs/GenerateNodeMapPower.java | 39 +- src/main/java/gregtech/api/graphs/PowerNodes.java | 18 +- .../api/graphs/consumers/ConsumerNode.java | 8 +- .../api/graphs/consumers/EmptyPowerConsumer.java | 6 +- .../api/graphs/consumers/NodeEnergyConnected.java | 5 +- .../api/graphs/consumers/NodeEnergyReceiver.java | 6 +- .../api/graphs/consumers/NodeEnergySink.java | 7 +- .../api/graphs/consumers/NodeGTBaseMetaTile.java | 6 +- .../api/gui/modularui/GT_CoverUIBuildContext.java | 12 +- .../gregtech/api/gui/modularui/GT_UIInfos.java | 31 +- .../api/gui/widgets/GT_GuiCoverTabLine.java | 33 +- .../gregtech/api/interfaces/IItemBehaviour.java | 7 +- .../api/interfaces/IRedstoneCircuitBlock.java | 21 +- .../api/interfaces/covers/IControlsWorkCover.java | 11 +- .../interfaces/metatileentity/IConnectable.java | 8 +- .../interfaces/metatileentity/IMetaTileEntity.java | 70 +- .../metatileentity/IMetaTileEntityCable.java | 10 +- .../metatileentity/IMetaTileEntityItemPipe.java | 16 +- .../metatileentity/IMetaTileEntityPipe.java | 24 + .../tileentity/IBasicEnergyContainer.java | 4 +- .../api/interfaces/tileentity/ICoverable.java | 56 +- .../interfaces/tileentity/IEnergyConnected.java | 55 +- .../tileentity/IExperimentalEnergyTileEntity.java | 112 -- .../api/interfaces/tileentity/IFibreConnected.java | 12 +- .../tileentity/IGearEnergyTileEntity.java | 7 +- .../interfaces/tileentity/IGregTechTileEntity.java | 5 +- .../tileentity/IHasWorldObjectAndCoords.java | 51 +- .../tileentity/IPipeRenderedTileEntity.java | 8 +- .../interfaces/tileentity/IRedstoneEmitter.java | 17 +- .../interfaces/tileentity/IRedstoneReceiver.java | 6 +- .../interfaces/tileentity/ITexturedTileEntity.java | 3 +- .../api/interfaces/tileentity/ITurnable.java | 16 +- .../api/items/GT_Block_LongDistancePipe.java | 2 +- .../java/gregtech/api/items/GT_MetaBase_Item.java | 23 +- .../gregtech/api/items/GT_SolderingTool_Item.java | 4 +- .../java/gregtech/api/items/GT_Spray_Bug_Item.java | 4 +- .../gregtech/api/items/GT_Spray_Foam_Item.java | 22 +- .../gregtech/api/items/GT_Spray_Hardener_Item.java | 4 +- .../api/items/GT_Spray_Hydration_Item.java | 4 +- .../java/gregtech/api/items/GT_Spray_Ice_Item.java | 10 +- .../gregtech/api/items/GT_Spray_Pepper_Item.java | 4 +- .../api/logic/interfaces/PowerLogicHost.java | 2 +- .../api/metatileentity/BaseMetaPipeEntity.java | 244 ++- .../api/metatileentity/BaseMetaTileEntity.java | 367 +++-- .../api/metatileentity/BaseTileEntity.java | 142 +- .../api/metatileentity/CommonMetaTileEntity.java | 13 +- .../api/metatileentity/CoverableTileEntity.java | 346 ++--- .../api/metatileentity/MetaPipeEntity.java | 205 +-- .../api/metatileentity/MetaTileEntity.java | 112 +- .../api/metatileentity/TileIC2EnergySink.java | 14 +- .../examples/GT_MetaTileEntity_E_Furnace.java | 5 +- .../implementations/GT_MetaPipeEntity_Cable.java | 289 ++-- .../implementations/GT_MetaPipeEntity_Fluid.java | 177 +-- .../implementations/GT_MetaPipeEntity_Frame.java | 19 +- .../implementations/GT_MetaPipeEntity_Item.java | 188 +-- .../GT_MetaTileEntity_BasicBatteryBuffer.java | 23 +- .../GT_MetaTileEntity_BasicGenerator.java | 21 +- .../GT_MetaTileEntity_BasicHull.java | 23 +- .../GT_MetaTileEntity_BasicHull_NonElectric.java | 12 +- .../GT_MetaTileEntity_BasicMachine.java | 150 +- .../GT_MetaTileEntity_BasicMachine_Bronze.java | 24 +- .../GT_MetaTileEntity_BasicMachine_GT_Recipe.java | 21 +- .../GT_MetaTileEntity_BasicTank.java | 8 +- .../implementations/GT_MetaTileEntity_Buffer.java | 89 +- .../GT_MetaTileEntity_EnhancedMultiBlockBase.java | 24 +- .../implementations/GT_MetaTileEntity_Hatch.java | 17 +- .../GT_MetaTileEntity_Hatch_DataAccess.java | 9 +- .../GT_MetaTileEntity_Hatch_Dynamo.java | 13 +- .../GT_MetaTileEntity_Hatch_Energy.java | 13 +- .../GT_MetaTileEntity_Hatch_Input.java | 13 +- .../GT_MetaTileEntity_Hatch_InputBus.java | 17 +- .../GT_MetaTileEntity_Hatch_Maintenance.java | 15 +- .../GT_MetaTileEntity_Hatch_Muffler.java | 30 +- .../GT_MetaTileEntity_Hatch_Output.java | 46 +- .../GT_MetaTileEntity_Hatch_OutputBus.java | 11 +- .../GT_MetaTileEntity_MultiBlockBase.java | 14 +- .../GT_MetaTileEntity_SpecialFilter.java | 6 +- .../GT_MetaTileEntity_Transformer.java | 113 +- .../GT_MetaTileEntity_Wireless_Dynamo.java | 13 +- .../GT_MetaTileEntity_Wireless_Hatch.java | 13 +- .../api/multitileentity/MultiTileEntityBlock.java | 128 +- .../MultiTileEntityBlockInternal.java | 5 +- .../MultiTileEntityItemInternal.java | 97 +- .../api/multitileentity/base/MultiTileEntity.java | 232 ++- .../base/NonTickableMultiTileEntity.java | 11 +- .../base/TickableMultiTileEntity.java | 3 +- .../interfaces/IMultiBlockController.java | 12 +- .../interfaces/IMultiBlockEnergy.java | 10 +- .../interfaces/IMultiBlockInventory.java | 7 +- .../interfaces/IMultiBlockPart.java | 3 +- .../interfaces/IMultiTileEntity.java | 39 +- .../machine/MultiTileBasicMachine.java | 38 +- .../multiblock/base/Controller.java | 98 +- .../multiblock/base/MultiBlockPart.java | 145 +- .../multiblock/base/WallShareablePart.java | 17 +- .../api/net/GT_Packet_GtTileEntityGuiRequest.java | 6 +- .../api/net/GT_Packet_RequestCoverData.java | 11 +- .../gregtech/api/net/GT_Packet_SendCoverData.java | 16 +- .../api/net/GT_Packet_TileEntityCover.java | 12 +- .../api/net/GT_Packet_TileEntityCoverGUI.java | 32 +- .../api/net/GT_Packet_TileEntityCoverNew.java | 12 +- .../api/net/GT_Packet_WirelessRedstoneCover.java | 9 +- .../api/objects/GT_CopiedBlockTexture.java | 12 +- .../gregtech/api/objects/GT_Cover_Default.java | 23 +- .../java/gregtech/api/objects/GT_Cover_None.java | 121 +- .../api/objects/GT_StdRenderedTexture.java | 6 +- .../api/threads/GT_Runnable_Cable_Update.java | 18 +- .../gregtech/api/util/GT_CircuitryBehavior.java | 14 +- .../java/gregtech/api/util/GT_CoverBehavior.java | 218 ++- .../gregtech/api/util/GT_CoverBehaviorBase.java | 299 ++-- .../gregtech/api/util/GT_HatchElementBuilder.java | 2 +- src/main/java/gregtech/api/util/GT_Utility.java | 1591 ++++++++++---------- .../java/gregtech/api/util/LightingHelper.java | 21 +- 115 files changed, 3511 insertions(+), 3480 deletions(-) create mode 100644 src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityPipe.java delete mode 100644 src/main/java/gregtech/api/interfaces/tileentity/IExperimentalEnergyTileEntity.java (limited to 'src/main/java/gregtech/api') diff --git a/src/main/java/gregtech/api/events/BlockScanningEvent.java b/src/main/java/gregtech/api/events/BlockScanningEvent.java index 27eb375a6f..bc2a33bcea 100644 --- a/src/main/java/gregtech/api/events/BlockScanningEvent.java +++ b/src/main/java/gregtech/api/events/BlockScanningEvent.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.world.WorldEvent; import cpw.mods.fml.common.eventhandler.Cancelable; @@ -16,7 +17,7 @@ public class BlockScanningEvent extends WorldEvent { public final EntityPlayer mPlayer; public final int mX, mY, mZ, mScanLevel; public final ArrayList mList; - public final byte mSide; + public final ForgeDirection mSide; public final float mClickX, mClickY, mClickZ; public final TileEntity mTileEntity; public final Block mBlock; @@ -26,15 +27,16 @@ public class BlockScanningEvent extends WorldEvent { */ public int mEUCost = 0; - public BlockScanningEvent(World aWorld, EntityPlayer aPlayer, int aX, int aY, int aZ, byte aSide, int aScanLevel, - Block aBlock, TileEntity aTileEntity, ArrayList aList, float aClickX, float aClickY, float aClickZ) { + public BlockScanningEvent(World aWorld, EntityPlayer aPlayer, int aX, int aY, int aZ, ForgeDirection side, + int aScanLevel, Block aBlock, TileEntity aTileEntity, ArrayList aList, float aClickX, float aClickY, + float aClickZ) { super(aWorld); mPlayer = aPlayer; mScanLevel = aScanLevel; mTileEntity = aTileEntity; mBlock = aBlock; mList = aList; - mSide = aSide; + mSide = side; mX = aX; mY = aY; mZ = aZ; diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java index bbdfa40a10..7289f0faad 100644 --- a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java +++ b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java @@ -1,12 +1,12 @@ package gregtech.api.graphs; import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES; -import static gregtech.api.util.GT_Utility.getOppositeSide; import java.util.ArrayList; import java.util.HashSet; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.graphs.consumers.ConsumerNode; import gregtech.api.graphs.paths.NodePath; @@ -42,17 +42,17 @@ public abstract class GenerateNodeMap { // get how many connections the pipe have private static int getNumberOfConnections(MetaPipeEntity aPipe) { int tCons = 0; - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (aPipe.isConnectedAtSide(side)) tCons++; } return tCons; } // gets the next node - protected void generateNextNode(BaseMetaPipeEntity aPipe, Node aPipeNode, byte aInvalidSide, int aNextNodeValue, - ArrayList tConsumers, HashSet tNodeMap) { + protected void generateNextNode(BaseMetaPipeEntity aPipe, Node aPipeNode, ForgeDirection aInvalidSide, + int aNextNodeValue, ArrayList tConsumers, HashSet tNodeMap) { final MetaPipeEntity tMetaPipe = (MetaPipeEntity) aPipe.getMetaTileEntity(); - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (side == aInvalidSide) { continue; } @@ -70,12 +70,13 @@ public abstract class GenerateNodeMap { tConsumers, tNodeMap); if (tNextNode != null) { + final int i = side.ordinal(); aNextNodeValue = tNextNode.mHighestNodeValue; aPipeNode.mHighestNodeValue = tNextNode.mHighestNodeValue; - aPipeNode.mNeighbourNodes[side] = tNextNode; - aPipeNode.mNodePaths[side] = aPipeNode.returnValues.mReturnPath; - aPipeNode.locks[side] = aPipeNode.returnValues.returnLock; - aPipeNode.mNodePaths[side].reloadLocks(); + aPipeNode.mNeighbourNodes[i] = tNextNode; + aPipeNode.mNodePaths[i] = aPipeNode.returnValues.mReturnPath; + aPipeNode.locks[i] = aPipeNode.returnValues.returnLock; + aPipeNode.mNodePaths[i].reloadLocks(); } } } @@ -84,10 +85,11 @@ public abstract class GenerateNodeMap { // on a valid tile entity create a new node protected Node generateNode(TileEntity aTileEntity, Node aPreviousNode, int aNextNodeValue, - ArrayList aPipes, int aSide, ArrayList aConsumers, HashSet aNodeMap) { + ArrayList aPipes, ForgeDirection side, ArrayList aConsumers, + HashSet aNodeMap) { if (aTileEntity.isInvalid()) return null; - final byte tSideOp = getOppositeSide(aSide); - final byte tInvalidSide = aPreviousNode == null ? -1 : tSideOp; + final ForgeDirection oppositeSide = side.getOpposite(); + final ForgeDirection tInvalidSide = aPreviousNode == null ? ForgeDirection.UNKNOWN : oppositeSide; Node tThisNode = null; if (isPipe(aTileEntity)) { final BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity; @@ -95,33 +97,35 @@ public abstract class GenerateNodeMap { final int tConnections = getNumberOfConnections(tMetaPipe); final Node tPipeNode; if (tConnections == 1) { - tPipeNode = getEmptyNode(aNextNodeValue, tSideOp, aTileEntity, aConsumers); + tPipeNode = getEmptyNode(aNextNodeValue, oppositeSide, aTileEntity, aConsumers); if (tPipeNode == null) return null; } else { - tPipeNode = getPipeNode(aNextNodeValue, tSideOp, aTileEntity, aConsumers); + tPipeNode = getPipeNode(aNextNodeValue, oppositeSide, aTileEntity, aConsumers); } tPipe.setNode(tPipeNode); aNodeMap.add(tPipeNode); tPipeNode.mSelfPath = getNewPath(new MetaPipeEntity[] { tMetaPipe }); tThisNode = tPipeNode; - if (tInvalidSide > -1) { - tPipeNode.mNeighbourNodes[tInvalidSide] = aPreviousNode; - tPipeNode.mNodePaths[tInvalidSide] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); + if (tInvalidSide != ForgeDirection.UNKNOWN) { + final int iInvalid = tInvalidSide.ordinal(); + tPipeNode.mNeighbourNodes[iInvalid] = aPreviousNode; + tPipeNode.mNodePaths[iInvalid] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); final Lock lock = new Lock(); - tPipeNode.mNodePaths[tSideOp].lock = lock; - tPipeNode.locks[tInvalidSide] = lock; - aPreviousNode.returnValues.mReturnPath = tPipeNode.mNodePaths[tInvalidSide]; + tPipeNode.mNodePaths[oppositeSide.ordinal()].lock = lock; + tPipeNode.locks[iInvalid] = lock; + aPreviousNode.returnValues.mReturnPath = tPipeNode.mNodePaths[iInvalid]; aPreviousNode.returnValues.returnLock = lock; } if (tConnections > 1) generateNextNode(tPipe, tPipeNode, tInvalidSide, aNextNodeValue, aConsumers, aNodeMap); - } else if (addConsumer(aTileEntity, tSideOp, aNextNodeValue, aConsumers)) { + } else if (addConsumer(aTileEntity, oppositeSide, aNextNodeValue, aConsumers)) { + final int oppositeSideOrdinal = oppositeSide.ordinal(); final ConsumerNode tConsumeNode = aConsumers.get(aConsumers.size() - 1); - tConsumeNode.mNeighbourNodes[tSideOp] = aPreviousNode; - tConsumeNode.mNodePaths[tSideOp] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); + tConsumeNode.mNeighbourNodes[oppositeSideOrdinal] = aPreviousNode; + tConsumeNode.mNodePaths[oppositeSideOrdinal] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); final Lock lock = new Lock(); - tConsumeNode.mNodePaths[tSideOp].lock = lock; - aPreviousNode.returnValues.mReturnPath = tConsumeNode.mNodePaths[tSideOp]; + tConsumeNode.mNodePaths[oppositeSideOrdinal].lock = lock; + aPreviousNode.returnValues.mReturnPath = tConsumeNode.mNodePaths[oppositeSideOrdinal]; aPreviousNode.returnValues.returnLock = lock; tThisNode = tConsumeNode; } @@ -129,7 +133,7 @@ public abstract class GenerateNodeMap { } // go over the pipes until we see a valid tile entity that needs a node - protected Pair getNextValidTileEntity(TileEntity aTileEntity, ArrayList aPipes, byte aSide, + protected Pair getNextValidTileEntity(TileEntity aTileEntity, ArrayList aPipes, ForgeDirection side, HashSet aNodeMap) { if (isPipe(aTileEntity)) { final BaseMetaPipeEntity tPipe = (BaseMetaPipeEntity) aTileEntity; @@ -140,23 +144,23 @@ public abstract class GenerateNodeMap { } final int tConnections = getNumberOfConnections(tMetaPipe); if (tConnections == 2) { - final byte tSideOp = getOppositeSide(aSide); - for (byte i : ALL_VALID_SIDES) { - if (i == tSideOp || !(tMetaPipe.isConnectedAtSide(i))) continue; - final TileEntity tNewTileEntity = tPipe.getTileEntityAtSide(i); + final ForgeDirection tSideOp = side.getOpposite(); + for (final ForgeDirection s : ForgeDirection.VALID_DIRECTIONS) { + if (s == tSideOp || !(tMetaPipe.isConnectedAtSide(s))) continue; + final TileEntity tNewTileEntity = tPipe.getTileEntityAtSide(s); if (tNewTileEntity == null) continue; if (isPipe(tNewTileEntity)) { aPipes.add(tMetaPipe); - return getNextValidTileEntity(tNewTileEntity, aPipes, i, aNodeMap); + return getNextValidTileEntity(tNewTileEntity, aPipes, s, aNodeMap); } else { - return new Pair(aTileEntity, i); + return new Pair(aTileEntity, s); } } } else { - return new Pair(aTileEntity, aSide); + return new Pair(aTileEntity, side); } } else { - return new Pair(aTileEntity, aSide); + return new Pair(aTileEntity, side); } return null; } @@ -167,31 +171,32 @@ public abstract class GenerateNodeMap { } // checks if the tile entity is a consumer and add to the list - protected abstract boolean addConsumer(TileEntity aTileEntity, byte aSide, int aNodeValue, + protected abstract boolean addConsumer(TileEntity aTileEntity, ForgeDirection side, int aNodeValue, ArrayList aConsumers); // get correct pathClass that you need for your node network protected abstract NodePath getNewPath(MetaPipeEntity[] aPipes); // used for if you need to use dead ends for something can be null - protected Node getEmptyNode(int aNodeValue, byte aSide, TileEntity aTileEntity, + protected Node getEmptyNode(int aNodeValue, ForgeDirection side, TileEntity aTileEntity, ArrayList aConsumers) { return null; } // get correct node type you need for your network - protected Node getPipeNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList aConsumers) { + protected Node getPipeNode(int aNodeValue, ForgeDirection side, TileEntity aTileEntity, + ArrayList aConsumers) { return new Node(aNodeValue, aTileEntity, aConsumers); } private static class Pair { - public byte mSide; + public ForgeDirection mSide; public TileEntity mTileEntity; - public Pair(TileEntity aTileEntity, byte aSide) { + public Pair(TileEntity aTileEntity, ForgeDirection side) { this.mTileEntity = aTileEntity; - this.mSide = aSide; + this.mSide = side; } } } diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java b/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java index f2a2e95df8..95f9aee32d 100644 --- a/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java +++ b/src/main/java/gregtech/api/graphs/GenerateNodeMapPower.java @@ -27,7 +27,7 @@ import ic2.api.energy.tile.IEnergySink; public class GenerateNodeMapPower extends GenerateNodeMap { public GenerateNodeMapPower(BaseMetaPipeEntity aTileEntity) { - generateNode(aTileEntity, null, 1, null, -1, new ArrayList<>(), new HashSet<>()); + generateNode(aTileEntity, null, 1, null, ForgeDirection.UNKNOWN, new ArrayList<>(), new HashSet<>()); } @Override @@ -37,27 +37,27 @@ public class GenerateNodeMapPower extends GenerateNodeMap { } @Override - protected boolean addConsumer(TileEntity aTileEntity, byte aSide, int aNodeValue, + protected boolean addConsumer(TileEntity aTileEntity, ForgeDirection side, int aNodeValue, ArrayList aConsumers) { if (aTileEntity instanceof BaseMetaTileEntity tBaseTileEntity) { - if (tBaseTileEntity.inputEnergyFrom(aSide, false)) { - ConsumerNode tConsumerNode = new NodeGTBaseMetaTile(aNodeValue, tBaseTileEntity, aSide, aConsumers); + if (tBaseTileEntity.inputEnergyFrom(side, false)) { + ConsumerNode tConsumerNode = new NodeGTBaseMetaTile(aNodeValue, tBaseTileEntity, side, aConsumers); aConsumers.add(tConsumerNode); return true; } } else if (aTileEntity instanceof IEnergyConnected tTileEntity) { - if (tTileEntity.inputEnergyFrom(aSide, false)) { - ConsumerNode tConsumerNode = new NodeEnergyConnected(aNodeValue, tTileEntity, aSide, aConsumers); + if (tTileEntity.inputEnergyFrom(side, false)) { + ConsumerNode tConsumerNode = new NodeEnergyConnected(aNodeValue, tTileEntity, side, aConsumers); aConsumers.add(tConsumerNode); return true; } - } else if (aTileEntity instanceof IEnergySink) { + } else if (aTileEntity instanceof IEnergySink sink) { // ic2 wants the tilentity next to it of that side not going to add a bunch of arguments just for ic2 // crossborder checks to not load chuncks just to make sure - int dX = aTileEntity.xCoord + ForgeDirection.getOrientation(aSide).offsetX; - int dY = aTileEntity.yCoord + ForgeDirection.getOrientation(aSide).offsetY; - int dZ = aTileEntity.zCoord + ForgeDirection.getOrientation(aSide).offsetZ; + int dX = aTileEntity.xCoord + side.offsetX; + int dY = aTileEntity.yCoord + side.offsetY; + int dZ = aTileEntity.zCoord + side.offsetZ; boolean crossesChuncks = dX >> 4 != aTileEntity.xCoord >> 4 || dZ >> 4 != aTileEntity.zCoord >> 4; TileEntity tNextTo = null; if (!crossesChuncks || !aTileEntity.getWorldObj() @@ -65,21 +65,17 @@ public class GenerateNodeMapPower extends GenerateNodeMap { tNextTo = aTileEntity.getWorldObj() .getTileEntity(dX, dY, dZ); - if (((IEnergySink) aTileEntity).acceptsEnergyFrom(tNextTo, ForgeDirection.getOrientation(aSide))) { + if (sink.acceptsEnergyFrom(tNextTo, side)) { ConsumerNode tConsumerNode = new NodeEnergySink( aNodeValue, (IEnergySink) aTileEntity, - aSide, + side, aConsumers); aConsumers.add(tConsumerNode); return true; } - } else if (GregTech_API.mOutputRF && aTileEntity instanceof IEnergyReceiver) { - ConsumerNode tConsumerNode = new NodeEnergyReceiver( - aNodeValue, - (IEnergyReceiver) aTileEntity, - aSide, - aConsumers); + } else if (GregTech_API.mOutputRF && aTileEntity instanceof IEnergyReceiver receiver) { + ConsumerNode tConsumerNode = new NodeEnergyReceiver(aNodeValue, receiver, side, aConsumers); aConsumers.add(tConsumerNode); return true; } @@ -93,15 +89,16 @@ public class GenerateNodeMapPower extends GenerateNodeMap { // used to apply voltage on dead ends @Override - protected Node getEmptyNode(int aNodeValue, byte aSide, TileEntity aTileEntity, + protected Node getEmptyNode(int aNodeValue, ForgeDirection side, TileEntity aTileEntity, ArrayList aConsumers) { - ConsumerNode tNode = new EmptyPowerConsumer(aNodeValue, aTileEntity, aSide, aConsumers); + ConsumerNode tNode = new EmptyPowerConsumer(aNodeValue, aTileEntity, side, aConsumers); aConsumers.add(tNode); return tNode; } @Override - protected Node getPipeNode(int aNodeValue, byte aSide, TileEntity aTileEntity, ArrayList aConsumers) { + protected Node getPipeNode(int aNodeValue, ForgeDirection side, TileEntity aTileEntity, + ArrayList aConsumers) { return new PowerNode(aNodeValue, aTileEntity, aConsumers); } } diff --git a/src/main/java/gregtech/api/graphs/PowerNodes.java b/src/main/java/gregtech/api/graphs/PowerNodes.java index be94d2312a..98d35e2971 100644 --- a/src/main/java/gregtech/api/graphs/PowerNodes.java +++ b/src/main/java/gregtech/api/graphs/PowerNodes.java @@ -120,13 +120,13 @@ public class PowerNodes { return tAmpsUsed; } - protected static long processNextNode(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, + protected static long processNextNode(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int ordinalSide, long aMaxAmps, long aVoltage) { - if (aCurrentNode.locks[aSide].isLocked()) { + if (aCurrentNode.locks[ordinalSide].isLocked()) { aConsumers.getNextNode(); return 0; } - final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; + final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[ordinalSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; if (tSelfPath != null) { @@ -141,13 +141,13 @@ public class PowerNodes { return tAmps; } - protected static long processNextNodeAbove(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, + protected static long processNextNodeAbove(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int ordinalSide, long aMaxAmps, long aVoltage) { - if (aCurrentNode.locks[aSide].isLocked()) { + if (aCurrentNode.locks[ordinalSide].isLocked()) { aConsumers.getNextNode(); return 0; } - final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; + final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[ordinalSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; if (tSelfPath != null) { @@ -162,10 +162,10 @@ public class PowerNodes { return tAmps; } - protected static long processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int aSide, long aMaxAmps, + protected static long processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int ordinalSide, long aMaxAmps, long aVoltage) { - if (aCurrentNode.locks[aSide].isLocked()) return 0; - final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; + if (aCurrentNode.locks[ordinalSide].isLocked()) return 0; + final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[ordinalSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; if (tSelfPath != null) { diff --git a/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java b/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java index f82798f09b..04d7ebbe5a 100644 --- a/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java +++ b/src/main/java/gregtech/api/graphs/consumers/ConsumerNode.java @@ -3,17 +3,19 @@ package gregtech.api.graphs.consumers; import java.util.ArrayList; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.graphs.Node; // node attached to a tile entity that can consume stuff from the network public class ConsumerNode extends Node { - public byte mSide; + public ForgeDirection mSide; - public ConsumerNode(int aNodeValue, TileEntity aTileEntity, byte aSide, ArrayList aConsumers) { + public ConsumerNode(int aNodeValue, TileEntity aTileEntity, ForgeDirection side, + ArrayList aConsumers) { super(aNodeValue, aTileEntity, aConsumers); - this.mSide = aSide; + this.mSide = side; } public boolean needsEnergy() { diff --git a/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java b/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java index 6507d0f8e4..48cf330bdb 100644 --- a/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java +++ b/src/main/java/gregtech/api/graphs/consumers/EmptyPowerConsumer.java @@ -3,6 +3,7 @@ package gregtech.api.graphs.consumers; import java.util.ArrayList; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.graphs.paths.PowerNodePath; import gregtech.api.metatileentity.BaseMetaPipeEntity; @@ -10,8 +11,9 @@ import gregtech.api.metatileentity.BaseMetaPipeEntity; // this is here to apply voltage to dead ends public class EmptyPowerConsumer extends ConsumerNode { - public EmptyPowerConsumer(int aNodeValue, TileEntity aTileEntity, byte aSide, ArrayList aConsumers) { - super(aNodeValue, aTileEntity, aSide, aConsumers); + public EmptyPowerConsumer(int aNodeValue, TileEntity aTileEntity, ForgeDirection side, + ArrayList aConsumers) { + super(aNodeValue, aTileEntity, side, aConsumers); } @Override diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java index 65dd50f9df..6daeae8c9c 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyConnected.java @@ -3,14 +3,15 @@ package gregtech.api.graphs.consumers; import java.util.ArrayList; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.interfaces.tileentity.IEnergyConnected; public class NodeEnergyConnected extends ConsumerNode { - public NodeEnergyConnected(int aNodeValue, IEnergyConnected aTileEntity, byte aSide, + public NodeEnergyConnected(int aNodeValue, IEnergyConnected aTileEntity, ForgeDirection side, ArrayList aConsumers) { - super(aNodeValue, (TileEntity) aTileEntity, aSide, aConsumers); + super(aNodeValue, (TileEntity) aTileEntity, side, aConsumers); } @Override diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java index 4e84b04e2a..4f35922029 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergyReceiver.java @@ -21,14 +21,14 @@ public class NodeEnergyReceiver extends ConsumerNode { int mRestRF = 0; - public NodeEnergyReceiver(int aNodeValue, IEnergyReceiver aTileEntity, byte aSide, + public NodeEnergyReceiver(int aNodeValue, IEnergyReceiver aTileEntity, ForgeDirection side, ArrayList aConsumers) { - super(aNodeValue, (TileEntity) aTileEntity, aSide, aConsumers); + super(aNodeValue, (TileEntity) aTileEntity, side, aConsumers); } @Override public int injectEnergy(long aVoltage, long aMaxAmps) { - ForgeDirection tDirection = ForgeDirection.getOrientation(mSide); + ForgeDirection tDirection = mSide; int rfOut = GT_Utility.safeInt(aVoltage * GregTech_API.mEUtoRF / 100); int ampsUsed = 0; if (mRestRF < rfOut) { diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java b/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java index d978a99d0b..44fb88e5e8 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeEnergySink.java @@ -10,7 +10,8 @@ import ic2.api.energy.tile.IEnergySink; // consumer for IC2 machines public class NodeEnergySink extends ConsumerNode { - public NodeEnergySink(int nodeValue, IEnergySink tileEntity, byte side, ArrayList consumers) { + public NodeEnergySink(int nodeValue, IEnergySink tileEntity, ForgeDirection side, + ArrayList consumers) { super(nodeValue, (TileEntity) tileEntity, side, consumers); } @@ -23,9 +24,7 @@ public class NodeEnergySink extends ConsumerNode { public int injectEnergy(long aVoltage, long aMaxAmps) { int tUsedAmps = 0; while (aMaxAmps > tUsedAmps && ((IEnergySink) mTileEntity).getDemandedEnergy() > 0 - && ((IEnergySink) mTileEntity).injectEnergy(ForgeDirection.getOrientation(mSide), aVoltage, aVoltage) - < aVoltage) - tUsedAmps++; + && ((IEnergySink) mTileEntity).injectEnergy(mSide, aVoltage, aVoltage) < aVoltage) tUsedAmps++; return tUsedAmps; } } diff --git a/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java b/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java index ec75468db5..e8d8304eb3 100644 --- a/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java +++ b/src/main/java/gregtech/api/graphs/consumers/NodeGTBaseMetaTile.java @@ -2,15 +2,17 @@ package gregtech.api.graphs.consumers; import java.util.ArrayList; +import net.minecraftforge.common.util.ForgeDirection; + import gregtech.api.interfaces.tileentity.IEnergyConnected; import gregtech.api.metatileentity.BaseMetaTileEntity; // consumer for gt machines public class NodeGTBaseMetaTile extends ConsumerNode { - public NodeGTBaseMetaTile(int aNodeValue, BaseMetaTileEntity aTileEntity, byte aSide, + public NodeGTBaseMetaTile(int aNodeValue, BaseMetaTileEntity aTileEntity, ForgeDirection side, ArrayList aConsumers) { - super(aNodeValue, aTileEntity, aSide, aConsumers); + super(aNodeValue, aTileEntity, side, aConsumers); } @Override diff --git a/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java b/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java index 62a933cfa6..20586b9c48 100644 --- a/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java +++ b/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java @@ -1,6 +1,7 @@ package gregtech.api.gui.modularui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.api.interfaces.tileentity.ICoverable; @@ -9,7 +10,7 @@ public class GT_CoverUIBuildContext extends UIBuildContext { // cover data is not synced to client, while ID is private final int coverID; - private final byte side; + private final ForgeDirection side; private final ICoverable tile; private final boolean anotherWindow; private final int guiColorization; @@ -22,8 +23,8 @@ public class GT_CoverUIBuildContext extends UIBuildContext { * @param anotherWindow If cover UI is shown on top of another window * @param guiColorization The color used to render machine's GUI */ - public GT_CoverUIBuildContext(EntityPlayer player, int coverID, byte side, ICoverable tile, boolean anotherWindow, - int guiColorization) { + public GT_CoverUIBuildContext(EntityPlayer player, int coverID, ForgeDirection side, ICoverable tile, + boolean anotherWindow, int guiColorization) { super(player); this.coverID = coverID; this.side = side; @@ -39,7 +40,8 @@ public class GT_CoverUIBuildContext extends UIBuildContext { * @param tile Tile this cover is attached to * @param anotherWindow If cover GUI is shown in opened on top of another window */ - public GT_CoverUIBuildContext(EntityPlayer player, int coverID, byte side, ICoverable tile, boolean anotherWindow) { + public GT_CoverUIBuildContext(EntityPlayer player, int coverID, ForgeDirection side, ICoverable tile, + boolean anotherWindow) { this(player, coverID, side, tile, anotherWindow, tile.getGUIColorization()); } @@ -47,7 +49,7 @@ public class GT_CoverUIBuildContext extends UIBuildContext { return coverID; } - public byte getCoverSide() { + public ForgeDirection getCoverSide() { return side; } diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java index b132f33d63..afa60e5583 100644 --- a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java +++ b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java @@ -40,23 +40,16 @@ public class GT_UIInfos { .of() .container((player, world, x, y, z) -> { TileEntity te = world.getTileEntity(x, y, z); - if (te instanceof ITileWithModularUI) { - return createTileEntityContainer( - player, - ((ITileWithModularUI) te)::createWindow, - te::markDirty, - containerConstructor); + if (te instanceof ITileWithModularUI mui) { + return createTileEntityContainer(player, mui::createWindow, te::markDirty, containerConstructor); } return null; }) .gui(((player, world, x, y, z) -> { if (!world.isRemote) return null; TileEntity te = world.getTileEntity(x, y, z); - if (te instanceof ITileWithModularUI) { - return createTileEntityGuiContainer( - player, - ((ITileWithModularUI) te)::createWindow, - containerConstructor); + if (te instanceof ITileWithModularUI mui) { + return createTileEntityGuiContainer(player, mui::createWindow, containerConstructor); } return null; })) @@ -64,18 +57,17 @@ public class GT_UIInfos { private static final UIInfo GTTileEntityDefaultUI = GTTileEntityUIFactory.apply(ModularUIContainer::new); - private static final Map> coverUI = new HashMap<>(); + private static final Map> coverUI = new HashMap<>(); static { - for (byte i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { - final byte side = i; + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { coverUI.put( side, UIBuilder.of() .container((player, world, x, y, z) -> { final TileEntity te = world.getTileEntity(x, y, z); if (!(te instanceof ICoverable gtTileEntity)) return null; - GT_CoverBehaviorBase cover = gtTileEntity.getCoverBehaviorAtSideNew(side); + final GT_CoverBehaviorBase cover = gtTileEntity.getCoverBehaviorAtSideNew(side); return createCoverContainer( player, cover::createWindow, @@ -116,7 +108,7 @@ public class GT_UIInfos { /** * Opens cover UI, created by {@link GT_CoverBehaviorBase#createWindow}. */ - public static void openCoverUI(ICoverable tileEntity, EntityPlayer player, byte side) { + public static void openCoverUI(ICoverable tileEntity, EntityPlayer player, ForgeDirection side) { if (tileEntity.isClientSide()) return; GT_Values.NW.sendToPlayer( @@ -167,8 +159,8 @@ public class GT_UIInfos { } private static ModularUIContainer createCoverContainer(EntityPlayer player, - Function windowCreator, Runnable onWidgetUpdate, int coverID, byte side, - ICoverable tile) { + Function windowCreator, Runnable onWidgetUpdate, int coverID, + ForgeDirection side, ICoverable tile) { final GT_CoverUIBuildContext buildContext = new GT_CoverUIBuildContext(player, coverID, side, tile, false); final ModularWindow window = windowCreator.apply(buildContext); if (window == null) return null; @@ -177,7 +169,8 @@ public class GT_UIInfos { @SideOnly(Side.CLIENT) private static ModularGui createCoverGuiContainer(EntityPlayer player, - Function windowCreator, int coverID, byte side, ICoverable tile) { + Function windowCreator, int coverID, ForgeDirection side, + ICoverable tile) { final ModularUIContainer container = createCoverContainer(player, windowCreator, null, coverID, side, tile); if (container == null) { return null; diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java index 9694316bee..890e6298c9 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java @@ -8,6 +8,7 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; @@ -66,10 +67,10 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine { * Add a tab for each existing cover on this IGregTechTileEntity at creation time */ private void setupTabs() { - for (byte tSide = 0; tSide < 6; tSide++) { - final ItemStack cover = tile.getCoverItemAtSide(tSide); + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + final ItemStack cover = tile.getCoverItemAtSide(side); if (cover != null) { - addCoverToTabs(tSide, cover); + addCoverToTabs(side, cover); } } } @@ -101,26 +102,27 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine { /** * Add the cover on this side of the IGregTechTileEntity to the tabs - * + * * @param side * @param cover */ - private void addCoverToTabs(byte side, ItemStack cover) { + private void addCoverToTabs(ForgeDirection side, ItemStack cover) { final boolean enabled = this.tile.getCoverBehaviorAtSideNew(side) .hasCoverGUI(); - this.setTab(side, cover, null, getTooltipForCoverTab(side, cover, enabled)); - this.setTabEnabled(side, enabled); + final int ordinalSide = side.ordinal(); + this.setTab(ordinalSide, cover, null, getTooltipForCoverTab(side, cover, enabled)); + this.setTabEnabled(ordinalSide, enabled); } /** * Decorate the cover's tooltips according to the side it's on and on whether the tab is enabled or not - * + * * @param side * @param cover * @param enabled * @return This cover tab's tooltip */ - private String[] getTooltipForCoverTab(byte side, ItemStack cover, boolean enabled) { + private String[] getTooltipForCoverTab(ForgeDirection side, ItemStack cover, boolean enabled) { final List tooltip = cover.getTooltip(Minecraft.getMinecraft().thePlayer, true); tooltip.set( 0, @@ -132,16 +134,17 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine { /** * Get the translated name for a side of the IGregTechTileEntity - * + * * @param side * @return translated name for a side of the IGregTechTileEntity */ - private String getSideDescription(byte side) { - if (side < SIDES.length) { - if (this.translatedSides[side] == null) { - this.translatedSides[side] = StatCollector.translateToLocal(SIDES[side]); + private String getSideDescription(ForgeDirection side) { + final int ordinalSide = side.ordinal(); + if (ordinalSide < SIDES.length) { + if (this.translatedSides[ordinalSide] == null) { + this.translatedSides[ordinalSide] = StatCollector.translateToLocal(SIDES[ordinalSide]); } - return this.translatedSides[side]; + return this.translatedSides[ordinalSide]; } return null; } diff --git a/src/main/java/gregtech/api/interfaces/IItemBehaviour.java b/src/main/java/gregtech/api/interfaces/IItemBehaviour.java index 1f67b9c1a8..67bb505c6b 100644 --- a/src/main/java/gregtech/api/interfaces/IItemBehaviour.java +++ b/src/main/java/gregtech/api/interfaces/IItemBehaviour.java @@ -10,6 +10,7 @@ import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.enums.SubTag; import gregtech.api.items.GT_MetaBase_Item; @@ -18,11 +19,11 @@ public interface IItemBehaviour { boolean onLeftClickEntity(E aItem, ItemStack aStack, EntityPlayer aPlayer, Entity aEntity); - boolean onItemUse(E aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, - float hitX, float hitY, float hitZ); + boolean onItemUse(E aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, + int ordinalSide, float hitX, float hitY, float hitZ); boolean onItemUseFirst(E aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, - int aSide, float hitX, float hitY, float hitZ); + ForgeDirection side, float hitX, float hitY, float hitZ); ItemStack onItemRightClick(E aItem, ItemStack aStack, World aWorld, EntityPlayer aPlayer); diff --git a/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java b/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java index 91219368b7..0eea6ca3a4 100644 --- a/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java +++ b/src/main/java/gregtech/api/interfaces/IRedstoneCircuitBlock.java @@ -2,6 +2,7 @@ package gregtech.api.interfaces; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.util.GT_CoverBehavior; @@ -14,47 +15,47 @@ public interface IRedstoneCircuitBlock { /** * The Output Direction the Circuit Block is Facing */ - byte getOutputFacing(); + ForgeDirection getOutputFacing(); /** * sets Output Redstone State at Side */ - boolean setRedstone(byte aStrength, byte aSide); + boolean setRedstone(byte aStrength, ForgeDirection side); /** * returns Output Redstone State at Side Note that setRedstone checks if there is a Difference between the old and * the new Setting before consuming any Energy */ - byte getOutputRedstone(byte aSide); + byte getOutputRedstone(ForgeDirection side); /** * returns Input Redstone Signal at Side */ - byte getInputRedstone(byte aSide); + byte getInputRedstone(ForgeDirection side); /** * If this Side is Covered up and therefor not doing any Redstone */ - GT_CoverBehavior getCover(byte aSide); + GT_CoverBehavior getCover(ForgeDirection side); - int getCoverID(byte aSide); + int getCoverID(ForgeDirection side); - int getCoverVariable(byte aSide); + int getCoverVariable(ForgeDirection side); /** * returns whatever Block-ID is adjacent to the Redstone Circuit Block */ - Block getBlockAtSide(byte aSide); + Block getBlockAtSide(ForgeDirection side); /** * returns whatever Meta-Value is adjacent to the Redstone Circuit Block */ - byte getMetaIDAtSide(byte aSide); + byte getMetaIDAtSide(ForgeDirection side); /** * returns whatever TileEntity is adjacent to the Redstone Circuit Block */ - TileEntity getTileEntityAtSide(byte aSide); + TileEntity getTileEntityAtSide(ForgeDirection side); /** * returns whatever TileEntity is used by the Redstone Circuit Block diff --git a/src/main/java/gregtech/api/interfaces/covers/IControlsWorkCover.java b/src/main/java/gregtech/api/interfaces/covers/IControlsWorkCover.java index cef20ac3b7..d4cd1e9ec2 100644 --- a/src/main/java/gregtech/api/interfaces/covers/IControlsWorkCover.java +++ b/src/main/java/gregtech/api/interfaces/covers/IControlsWorkCover.java @@ -1,6 +1,6 @@ package gregtech.api.interfaces.covers; -import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; @@ -16,10 +16,11 @@ public interface IControlsWorkCover { * * @return true if the cover is the first (side) one **/ - static boolean makeSureOnlyOne(byte aMySide, ICoverable aTileEntity) { - for (byte tSide : ALL_VALID_SIDES) { - if (aTileEntity.getCoverBehaviorAtSideNew(tSide) instanceof IControlsWorkCover && tSide < aMySide) { - aTileEntity.dropCover(tSide, tSide, true); + static boolean makeSureOnlyOne(ForgeDirection aMySide, ICoverable aTileEntity) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (aTileEntity.getCoverBehaviorAtSideNew(side) instanceof IControlsWorkCover + && side.ordinal() < aMySide.ordinal()) { + aTileEntity.dropCover(side, side, true); aTileEntity.markDirty(); return false; } diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IConnectable.java b/src/main/java/gregtech/api/interfaces/metatileentity/IConnectable.java index 76d8d082ef..0ca519d40b 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IConnectable.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IConnectable.java @@ -1,5 +1,7 @@ package gregtech.api.interfaces.metatileentity; +import net.minecraftforge.common.util.ForgeDirection; + /** * For pipes, wires, and other MetaTiles which need to be decided whether they should connect to the block at each side. */ @@ -21,12 +23,12 @@ public interface IConnectable { * Try to connect to the Block at the specified side returns the connection state. Non-positive values for failed, * others for succeeded. */ - int connect(byte aSide); + int connect(ForgeDirection side); /** * Try to disconnect to the Block at the specified side */ - void disconnect(byte aSide); + void disconnect(ForgeDirection side); - boolean isConnectedAtSide(int aSide); + boolean isConnectedAtSide(ForgeDirection side); } diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java index a24e05f1a2..c9377d10be 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java @@ -16,6 +16,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidTank; @@ -125,28 +126,30 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand * If a Cover of that Type can be placed on this Side. Also Called when the Facing of the Block Changes and a Cover * is on said Side. */ - boolean allowCoverOnSide(byte aSide, GT_ItemStack aStack); + boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aStack); /** * When a Player rightclicks the Facing with a Screwdriver. */ - void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ); + void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ); /** - * When a Player rightclicks the Facing with a Wrench. + * When a Player right-clicks the Facing with a Wrench. */ - boolean onWrenchRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ); + boolean onWrenchRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer entityPlayer, float aX, + float aY, float aZ); /** - * When a Player rightclicks the Facing with a wire cutter. + * When a Player right-clicks the Facing with a wire cutter. */ - boolean onWireCutterRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ); + boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer entityPlayer, + float aX, float aY, float aZ); /** - * When a Player rightclicks the Facing with a soldering iron. + * When a Player right-clicks the Facing with a soldering iron. */ - boolean onSolderingToolRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, - float aZ); + boolean onSolderingToolRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer entityPlayer, + float aX, float aY, float aZ); /** * Called right before this Machine explodes @@ -181,10 +184,10 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand void onRemoval(); /** - * @param aFacing + * @param facing * @return if aFacing would be a valid Facing for this Device. Used for wrenching. */ - boolean isFacingValid(byte aFacing); + boolean isFacingValid(ForgeDirection facing); /** * @return the Server Side Container @@ -214,12 +217,12 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand /** * From new ISidedInventory */ - boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack); + boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, ItemStack aStack); /** * From new ISidedInventory */ - boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack); + boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, ItemStack aStack); /** * @return if aIndex is a valid Slot. false for things like HoloSlots. Is used for determining if an Item is dropped @@ -243,12 +246,12 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand /** * If this Side can connect to inputting pipes */ - boolean isLiquidInput(byte aSide); + boolean isLiquidInput(ForgeDirection side); /** * If this Side can connect to outputting pipes */ - boolean isLiquidOutput(byte aSide); + boolean isLiquidOutput(ForgeDirection side); /** * Just an Accessor for the Name variable. @@ -261,12 +264,12 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand boolean isAccessAllowed(EntityPlayer aPlayer); /** - * a Player rightclicks the Machine Sneaky rightclicks are not getting passed to this! + * a Player right-clicks the Machine Sneaky right clicks are not getting passed to this! * * @return */ - boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, - float aZ); + boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, float aX, + float aY, float aZ); /** * a Player leftclicks the Machine Sneaky leftclicks are getting passed to this unlike with the rightclicks. @@ -364,22 +367,17 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand /** * Icon of the Texture. If this returns null then it falls back to getTextureIndex. * - * @param aSide is the Side of the Block - * @param aFacing is the direction the Block is facing (or a Bitmask of all Connections in case of Pipes) - * @param aColorIndex The Minecraft Color the Block is having - * @param aActive if the Machine is currently active (use this instead of calling - * mBaseMetaTileEntity.mActive!!!). Note: In case of Pipes this means if this Side is connected - * to something or not. - * @param aRedstone if the Machine is currently outputting a RedstoneSignal (use this instead of calling - * mBaseMetaTileEntity.mRedstone!!!) + * @param side is the Side of the Block + * @param facing is the direction the Block is facing + * @param colorIndex The Minecraft Color the Block is having + * @param active if the Machine is currently active (use this instead of calling + * {@code mBaseMetaTileEntity.mActive)}. Note: In case of Pipes this means if this Side is + * connected to something or not. + * @param redstoneLevel if the Machine is currently outputting a RedstoneSignal (use this instead of calling + * {@code mBaseMetaTileEntity.mRedstone} !!!) */ - ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, - boolean aActive, boolean aRedstone); - - /** - * The Textures used for the Item rendering. Return null if you want the regular 3D Block Rendering. - */ - // public ITexture[] getItemTexture(ItemStack aStack); + ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side, ForgeDirection facing, + int colorIndex, boolean active, boolean redstoneLevel); /** * Register Icons here. This gets called when the Icons get initialized by the Base Block Best is you put your Icons @@ -405,9 +403,9 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand /** * Gets the Output for the comparator on the given Side */ - byte getComparatorValue(byte aSide); + byte getComparatorValue(ForgeDirection side); - float getExplosionResistance(byte aSide); + float getExplosionResistance(ForgeDirection side); String[] getInfoData(); @@ -415,7 +413,7 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand ItemStack[] getRealInventory(); - boolean connectsToItemPipe(byte aSide); + boolean connectsToItemPipe(ForgeDirection side); void onColorChangeServer(byte aColor); diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityCable.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityCable.java index 3f7bc73383..a2d672e765 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityCable.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityCable.java @@ -4,14 +4,16 @@ import java.util.ArrayList; import java.util.HashSet; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; -public interface IMetaTileEntityCable extends IMetaTileEntity { +public interface IMetaTileEntityCable extends IMetaTileEntityPipe { @Deprecated - long transferElectricity(byte aSide, long aVoltage, long aAmperage, + long transferElectricity(ForgeDirection side, long aVoltage, long aAmperage, ArrayList aAlreadyPassedTileEntityList); - default long transferElectricity(byte aSide, long aVoltage, long aAmperage, HashSet aAlreadyPassedSet) { - return transferElectricity(aSide, aVoltage, aAmperage, new ArrayList<>(aAlreadyPassedSet)); + default long transferElectricity(ForgeDirection side, long aVoltage, long aAmperage, + HashSet aAlreadyPassedSet) { + return transferElectricity(side, aVoltage, aAmperage, new ArrayList<>(aAlreadyPassedSet)); } } diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java index 76d3f56e74..0c2c5ebf28 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java @@ -1,14 +1,13 @@ package gregtech.api.interfaces.metatileentity; -import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES; - import java.util.Map; +import net.minecraftforge.common.util.ForgeDirection; + import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.BaseMetaPipeEntity; -import gregtech.api.util.GT_Utility; -public interface IMetaTileEntityItemPipe extends IMetaTileEntity { +public interface IMetaTileEntityItemPipe extends IMetaTileEntityPipe { /** * @return if this Pipe can still be used. @@ -32,10 +31,10 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { * Executes the Sending Code for inserting Stacks into the TileEntities. * * @param aSender the BaseMetaTileEntity sending the Stack. - * @param aSide the Side of the PIPE facing the TileEntity. + * @param side the Side of the PIPE facing the TileEntity. * @return if this Side was allowed to Output into the Block. */ - boolean insertItemStackIntoTileEntity(Object aSender, byte aSide); + boolean insertItemStackIntoTileEntity(Object aSender, ForgeDirection side); /** * Can be used to make flow control Pipes, like Redpowers Restriction Tubes. Every normal Pipe returns a Value of @@ -59,11 +58,10 @@ public interface IMetaTileEntityItemPipe extends IMetaTileEntity { if (aMap.get(aMetaTileEntity) == null || aMap.get(aMetaTileEntity) > aStep) { final IGregTechTileEntity aBaseMetaTileEntity = aMetaTileEntity.getBaseMetaTileEntity(); aMap.put(aMetaTileEntity, aStep); - byte oppositeSide; - for (byte side : ALL_VALID_SIDES) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (aMetaTileEntity instanceof IConnectable && !((IConnectable) aMetaTileEntity).isConnectedAtSide(side)) continue; - oppositeSide = GT_Utility.getOppositeSide(side); + final ForgeDirection oppositeSide = side.getOpposite(); if (aSuckItems) { if (aBaseMetaTileE