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 --- .../java/gregtech/common/covers/CoverInfo.java | 23 +++-- .../java/gregtech/common/covers/GT_Cover_Arm.java | 103 +++++++++++---------- .../common/covers/GT_Cover_ControlsWork.java | 45 ++++----- .../gregtech/common/covers/GT_Cover_Conveyor.java | 43 +++++---- .../gregtech/common/covers/GT_Cover_Crafting.java | 5 +- .../gregtech/common/covers/GT_Cover_DoesWork.java | 37 ++++---- .../gregtech/common/covers/GT_Cover_Drain.java | 54 +++++------ .../gregtech/common/covers/GT_Cover_EUMeter.java | 30 +++--- .../common/covers/GT_Cover_FacadeBase.java | 74 ++++++++------- .../common/covers/GT_Cover_FluidLimiter.java | 8 +- .../common/covers/GT_Cover_FluidRegulator.java | 67 +++++++------- .../covers/GT_Cover_FluidStorageMonitor.java | 33 +++---- .../common/covers/GT_Cover_Fluidfilter.java | 59 ++++++------ .../common/covers/GT_Cover_ItemFilter.java | 47 +++++----- .../gregtech/common/covers/GT_Cover_ItemMeter.java | 39 ++++---- .../java/gregtech/common/covers/GT_Cover_Lens.java | 6 +- .../common/covers/GT_Cover_LiquidMeter.java | 33 +++---- .../common/covers/GT_Cover_NeedMaintainance.java | 43 +++++---- .../common/covers/GT_Cover_PlayerDetector.java | 31 ++++--- .../java/gregtech/common/covers/GT_Cover_Pump.java | 67 ++++++-------- .../common/covers/GT_Cover_RedstoneConductor.java | 35 ++++--- .../covers/GT_Cover_RedstoneReceiverExternal.java | 14 +-- .../covers/GT_Cover_RedstoneReceiverInternal.java | 14 +-- .../common/covers/GT_Cover_RedstoneSignalizer.java | 25 +++-- .../GT_Cover_RedstoneTransmitterExternal.java | 21 ++--- .../GT_Cover_RedstoneTransmitterInternal.java | 16 ++-- .../covers/GT_Cover_RedstoneWirelessBase.java | 43 +++++---- .../gregtech/common/covers/GT_Cover_Screen.java | 37 ++++---- .../gregtech/common/covers/GT_Cover_Shutter.java | 33 ++++--- .../common/covers/GT_Cover_SolarPanel.java | 30 +++--- .../common/covers/GT_Cover_SteamValve.java | 3 +- .../java/gregtech/common/covers/GT_Cover_Vent.java | 36 +++---- .../GT_Cover_AdvancedRedstoneReceiverExternal.java | 12 ++- .../GT_Cover_AdvancedRedstoneReceiverInternal.java | 14 +-- .../GT_Cover_AdvancedRedstoneTransmitterBase.java | 23 ++--- ..._Cover_AdvancedRedstoneTransmitterExternal.java | 10 +- ..._Cover_AdvancedRedstoneTransmitterInternal.java | 14 +-- .../GT_Cover_AdvancedWirelessRedstoneBase.java | 25 +++-- .../redstone/GT_Cover_WirelessFluidDetector.java | 13 +-- .../redstone/GT_Cover_WirelessItemDetector.java | 13 +-- .../GT_Cover_WirelessMaintenanceDetector.java | 13 +-- 41 files changed, 689 insertions(+), 602 deletions(-) (limited to 'src/main/java/gregtech/common/covers') diff --git a/src/main/java/gregtech/common/covers/CoverInfo.java b/src/main/java/gregtech/common/covers/CoverInfo.java index 0c3cf6986f..e63fe6e176 100644 --- a/src/main/java/gregtech/common/covers/CoverInfo.java +++ b/src/main/java/gregtech/common/covers/CoverInfo.java @@ -1,13 +1,12 @@ package gregtech.common.covers; -import static gregtech.api.enums.GT_Values.SIDE_UNKNOWN; - import java.lang.ref.WeakReference; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -23,21 +22,21 @@ public final class CoverInfo { private static final String NBT_SIDE = "s", NBT_ID = "id", NBT_DATA = "d"; - public static final CoverInfo EMPTY_INFO = new CoverInfo(SIDE_UNKNOWN, null); - private byte coverSide; + public static final CoverInfo EMPTY_INFO = new CoverInfo(ForgeDirection.UNKNOWN, null); + private final ForgeDirection coverSide; private int coverID = 0; private GT_CoverBehaviorBase coverBehavior = null; private ISerializableObject coverData = null; private final WeakReference coveredTile; private boolean needsUpdate = false; - public CoverInfo(byte aSide, ICoverable aTile) { - coverSide = aSide; + public CoverInfo(ForgeDirection side, ICoverable aTile) { + coverSide = side; coveredTile = new WeakReference<>(aTile); } - public CoverInfo(byte aSide, int aID, ICoverable aTile, ISerializableObject aCoverData) { - coverSide = aSide; + public CoverInfo(ForgeDirection side, int aID, ICoverable aTile, ISerializableObject aCoverData) { + coverSide = side; coverID = aID; coverBehavior = GregTech_API.getCoverBehaviorNew(aID); coverData = aCoverData == null ? coverBehavior.createDataObject() : aCoverData; @@ -45,7 +44,7 @@ public final class CoverInfo { } public CoverInfo(ICoverable aTile, NBTTagCompound aNBT) { - coverSide = aNBT.getByte(NBT_SIDE); + coverSide = ForgeDirection.getOrientation(aNBT.getByte(NBT_SIDE)); coverID = aNBT.getInteger(NBT_ID); coverBehavior = GregTech_API.getCoverBehaviorNew(coverID); coverData = aNBT.hasKey(NBT_DATA) ? coverBehavior.createDataObject(aNBT.getTag(NBT_DATA)) @@ -54,11 +53,11 @@ public final class CoverInfo { } public boolean isValid() { - return coverID != 0 && coverSide != SIDE_UNKNOWN; + return coverID != 0 && coverSide != ForgeDirection.UNKNOWN; } public NBTTagCompound writeToNBT(NBTTagCompound aNBT) { - aNBT.setByte(NBT_SIDE, coverSide); + aNBT.setByte(NBT_SIDE, (byte) coverSide.ordinal()); aNBT.setInteger(NBT_ID, coverID); if (coverData != null) aNBT.setTag(NBT_DATA, coverData.saveDataToNBT()); @@ -123,7 +122,7 @@ public final class CoverInfo { return getCoverBehavior().getTickRate(coverSide, coverID, coverData, coveredTile.get()); } - public byte getSide() { + public ForgeDirection getSide() { return coverSide; } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java index f2c2a65f3a..6bd41e1a25 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java @@ -4,6 +4,7 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import com.gtnewhorizons.modularui.api.math.MathExpression; @@ -51,14 +52,14 @@ public class GT_Cover_Arm extends GT_CoverBehavior { } @Override - 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 false; } @Override - 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) { if ((((aTileEntity instanceof IMachineProgress)) && (!((IMachineProgress) aTileEntity).isAllowedToWork()))) { return aCoverVariable; } @@ -70,41 +71,44 @@ public class GT_Cover_Arm extends GT_CoverBehavior { aCoverVariable = CONVERTED_BIT | Math.min(Math.abs(aCoverVariable - 1), SLOT_ID_MASK); } - TileEntity toTile, fromTile; - int toSlot, fromSlot; + final TileEntity toTile; + final TileEntity fromTile; + final int toSlot; + final int fromSlot; if ((aCoverVariable & EXPORT_MASK) > 0) { fromTile = (TileEntity) aTileEntity; - toTile = aTileEntity.getTileEntityAtSide(aSide); + toTile = aTileEntity.getTileEntityAtSide(side); fromSlot = aCoverVariable & SLOT_ID_MASK; toSlot = (aCoverVariable >> 14) & SLOT_ID_MASK; } else { - fromTile = aTileEntity.getTileEntityAtSide(aSide); + fromTile = aTileEntity.getTileEntityAtSide(side); toTile = (TileEntity) aTileEntity; fromSlot = (aCoverVariable >> 14) & SLOT_ID_MASK; toSlot = aCoverVariable & SLOT_ID_MASK; } if (fromSlot > 0 && toSlot > 0) { - if (fromTile instanceof IInventory && toTile instanceof IInventory) GT_Utility.moveFromSlotToSlot( - (IInventory) fromTile, - (IInventory) toTile, - fromSlot - 1, - toSlot - 1, - null, - false, - (byte) 64, - (byte) 1, - (byte) 64, - (byte) 1); + if (fromTile instanceof IInventory fromInventory && toTile instanceof IInventory toInventory) + GT_Utility.moveFromSlotToSlot( + fromInventory, + toInventory, + fromSlot - 1, + toSlot - 1, + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); } else if (toSlot > 0) { - byte side; - if ((aCoverVariable & EXPORT_MASK) > 0) side = aSide; - else side = GT_Utility.getOppositeSide(aSide); + final ForgeDirection toSide; + if ((aCoverVariable & EXPORT_MASK) > 0) toSide = side; + else toSide = side.getOpposite(); GT_Utility.moveOneItemStackIntoSlot( fromTile, toTile, - side, + toSide, toSlot - 1, null, false, @@ -113,9 +117,9 @@ public class GT_Cover_Arm extends GT_CoverBehavior { (byte) 64, (byte) 1); } else if (fromSlot > 0) { - byte toSide; - if ((aCoverVariable & EXPORT_MASK) > 0) toSide = aSide; - else toSide = GT_Utility.getOppositeSide(aSide); + final ForgeDirection toSide; + if ((aCoverVariable & EXPORT_MASK) > 0) toSide = side; + else toSide = side.getOpposite(); if (fromTile instanceof IInventory) GT_Utility.moveFromSlotToSide( (IInventory) fromTile, toTile, @@ -128,13 +132,14 @@ public class GT_Cover_Arm extends GT_CoverBehavior { (byte) 64, (byte) 1); } else { - byte fromSide, toSide; + final ForgeDirection fromSide; + final ForgeDirection toSide; if ((aCoverVariable & EXPORT_MASK) > 0) { - fromSide = aSide; - toSide = GT_Utility.getOppositeSide(aSide); + fromSide = side; + toSide = side.getOpposite(); } else { - fromSide = GT_Utility.getOppositeSide(aSide); - toSide = aSide; + fromSide = side.getOpposite(); + toSide = side; } GT_Utility.moveOneItemStack( fromTile, @@ -153,10 +158,10 @@ public class GT_Cover_Arm extends GT_CoverBehavior { } @Override - 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) { int step = 0; - if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) { + if (GT_Utility.getClickedFacingCoords(side, aX, aY, aZ)[0] >= 0.5F) { step += aPlayer.isSneaking() ? 256 : 16; } else { step -= aPlayer.isSneaking() ? 256 : 16; @@ -167,10 +172,10 @@ public class GT_Cover_Arm extends GT_CoverBehavior { } @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) { - int step = (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) ? 1 : -1; + int step = (GT_Utility.getClickedFacingCoords(side, aX, aY, aZ)[0] >= 0.5F) ? 1 : -1; int tCoverVariable = getNewVar(aCoverVariable.get(), step); sendMessageToPlayer(aPlayer, tCoverVariable); aCoverVariable.set(tCoverVariable); @@ -179,12 +184,12 @@ public class GT_Cover_Arm extends GT_CoverBehavior { @Override @SuppressWarnings("deprecation") - 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) { - int step = (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) ? 1 : -1; + final int step = (GT_Utility.getClickedFacingCoords(side, aX, aY, aZ)[0] >= 0.5F) ? 1 : -1; aCoverVariable = getNewVar(aCoverVariable, step); sendMessageToPlayer(aPlayer, aCoverVariable); - aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); + aTileEntity.setCoverDataAtSide(side, aCoverVariable); return true; } @@ -217,52 +222,56 @@ public class GT_Cover_Arm extends GT_CoverBehavior { } @Override - public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsRedstoneGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - 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 true; } @Override - 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 true; } @Override - 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 true; } @Override - 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 true; } @Override - public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return this.mTickRate; } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java index 872371a355..5145777f06 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java @@ -1,9 +1,8 @@ package gregtech.common.covers; -import static gregtech.api.enums.GT_Values.ALL_VALID_SIDES; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -36,9 +35,9 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior implements IControls } @Override - public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, - long aTimer) { - if (!makeSureOnlyOne(aSide, aTileEntity)) return 0; + public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity, long aTimer) { + if (!makeSureOnlyOne(side, aTileEntity)) return 0; if (aTileEntity instanceof IMachineProgress machine) { if (aCoverVariable < 2) { if ((aInputRedstone > 0) == (aCoverVariable == 0)) { @@ -64,7 +63,7 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior implements IControls } return 2; } else { - return 3 + doCoverThings(aSide, aInputRedstone, aCoverID, aCoverVariable - 3, aTileEntity, aTimer); + return 3 + doCoverThings(side, aInputRedstone, aCoverID, aCoverVariable - 3, aTileEntity, aTimer); } } } @@ -72,7 +71,7 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior implements IControls } @Override - protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, + protected boolean isRedstoneSensitiveImpl(ForgeDirection side, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { return aCoverVariable.get() != 2; // always off, so no redstone needed either } @@ -83,42 +82,46 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior implements IControls * * @return true if the cover is the first (side) one **/ - private boolean makeSureOnlyOne(byte aSide, ICoverable aTileEntity) { - return IControlsWorkCover.makeSureOnlyOne(aSide, aTileEntity); + private boolean makeSureOnlyOne(ForgeDirection side, ICoverable aTileEntity) { + return IControlsWorkCover.makeSureOnlyOne(side, aTileEntity); } @Override - public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - 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 true; } @Override - 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 true; } @Override - 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 true; } @Override - 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 true; } @Override - public boolean onCoverRemoval(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + public boolean onCoverRemoval(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, boolean aForced) { if ((aTileEntity instanceof IMachineProgress)) { ((IMachineProgress) aTileEntity).enableWorking(); @@ -128,7 +131,7 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior implements IControls } @Override - 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) { aCoverVariable = (aCoverVariable + (aPlayer.isSneaking() ? -1 : 1)) % 5; if (aCoverVariable < 0) { @@ -154,14 +157,14 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior implements IControls } @Override - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 1; } @Override - public boolean isCoverPlaceable(byte aSide, ItemStack aStack, ICoverable aTileEntity) { - if (!super.isCoverPlaceable(aSide, aStack, aTileEntity)) return false; - for (byte tSide : ALL_VALID_SIDES) { + public boolean isCoverPlaceable(ForgeDirection side, ItemStack aStack, ICoverable aTileEntity) { + if (!super.isCoverPlaceable(side, aStack, aTileEntity)) return false; + for (final ForgeDirection tSide : ForgeDirection.VALID_DIRECTIONS) { if (aTileEntity.getCoverBehaviorAtSideNew(tSide) instanceof IControlsWorkCover) { return false; } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java b/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java index 80d7dff6ae..bbea07b450 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java @@ -4,6 +4,7 @@ import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -48,24 +49,24 @@ public class GT_Cover_Conveyor extends GT_CoverBehavior { } @Override - 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 false; } @Override - 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) { if ((aCoverVariable % 6 > 1) && ((aTileEntity instanceof IMachineProgress))) { if (((IMachineProgress) aTileEntity).isAllowedToWork() != aCoverVariable % 6 < 4) { return aCoverVariable; } } - final TileEntity tTileEntity = aTileEntity.getTileEntityAtSide(aSide); + final TileEntity tTileEntity = aTileEntity.getTileEntityAtSide(side); final Object fromEntity = aCoverVariable % 2 == 0 ? aTileEntity : tTileEntity; final Object toEntity = aCoverVariable % 2 != 0 ? aTileEntity : tTileEntity; - final byte fromSide = aCoverVariable % 2 != 0 ? GT_Utility.getOppositeSide(aSide) : aSide; - final byte toSide = aCoverVariable % 2 == 0 ? GT_Utility.getOppositeSide(aSide) : aSide; + final ForgeDirection fromSide = aCoverVariable % 2 != 0 ? side.getOpposite() : side; + final ForgeDirection toSide = aCoverVariable % 2 == 0 ? side.getOpposite() : side; moveMultipleItemStacks( fromEntity, @@ -84,7 +85,7 @@ public class GT_Cover_Conveyor extends GT_CoverBehavior { } @Override - 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) { aCoverVariable = (aCoverVariable + (aPlayer.isSneaking() ? -1 : 1)) % 12; if (aCoverVariable < 0) { @@ -111,52 +112,56 @@ public class GT_Cover_Conveyor extends GT_CoverBehavior { } @Override - public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsRedstoneGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - 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 true; } @Override - 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 true; } @Override - 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 (aCoverVariable >= 6) || (aCoverVariable % 2 != 0); } @Override - 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 (aCoverVariable >= 6) || (aCoverVariable % 2 == 0); } @Override - public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return this.mTickRate; } @@ -285,11 +290,11 @@ public class GT_Cover_Conveyor extends GT_CoverBehavior { } private boolean getClickable(int id, int coverVariable) { - if (coverVariable < 0 | 11 < coverVariable) return false; + if (coverVariable < 0 || 11 < coverVariable) return false; return switch (id) { case 0, 1 -> (0x1 & coverVariable) != id; case 2 -> (coverVariable % 6) >= 2; - case 3 -> (coverVariable % 6) < 2 | 4 <= (coverVariable % 6); + case 3 -> (coverVariable % 6) < 2 || 4 <= (coverVariable % 6); case 4 -> (coverVariable % 6) < 4; case 5 -> coverVariable < 6; case 6 -> coverVariable >= 6; diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Crafting.java b/src/main/java/gregtech/common/covers/GT_Cover_Crafting.java index 139317110b..d985aed767 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Crafting.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Crafting.java @@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.network.play.server.S2DPacketOpenWindow; +import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; @@ -24,13 +25,13 @@ public class GT_Cover_Crafting extends GT_CoverBehavior { } @Override - 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 false; } @Override - 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) { if ((aPlayer instanceof EntityPlayerMP)) { ((EntityPlayerMP) aPlayer).getNextWindowId(); diff --git a/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java b/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java index 367f070848..2e60c8cad2 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java @@ -1,6 +1,7 @@ package gregtech.common.covers; import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -32,39 +33,39 @@ public class GT_Cover_DoesWork extends GT_CoverBehavior { } @Override - 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 false; } @Override - 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) { if ((aTileEntity instanceof IMachineProgress)) { if (aCoverVariable < 2) { int tScale = ((IMachineProgress) aTileEntity).getMaxProgress() / 15; if ((tScale > 0) && (((IMachineProgress) aTileEntity).hasThingsToDo())) { aTileEntity.setOutputRedstoneSignal( - aSide, + side, aCoverVariable % 2 == 0 ? (byte) (((IMachineProgress) aTileEntity).getProgress() / tScale) : (byte) (15 - ((IMachineProgress) aTileEntity).getProgress() / tScale)); } else { - aTileEntity.setOutputRedstoneSignal(aSide, (byte) (aCoverVariable % 2 == 0 ? 0 : 15)); + aTileEntity.setOutputRedstoneSignal(side, (byte) (aCoverVariable % 2 == 0 ? 0 : 15)); } } else { aTileEntity.setOutputRedstoneSignal( - aSide, + side, (byte) ((aCoverVariable % 2 == 0 ? 1 : 0) != (((IMachineProgress) aTileEntity).getMaxProgress() == 0 ? 1 : 0) ? 0 : 15)); } } else { - aTileEntity.setOutputRedstoneSignal(aSide, (byte) 0); + aTileEntity.setOutputRedstoneSignal(side, (byte) 0); } return aCoverVariable; } @Override - 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) { aCoverVariable = (aCoverVariable + (aPlayer.isSneaking() ? -1 : 1)) % 4; if (aCoverVariable < 0) { @@ -84,43 +85,47 @@ public class GT_Cover_DoesWork extends GT_CoverBehavior { } @Override - public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - 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 true; } @Override - 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 true; } @Override - 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 true; } @Override - 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 true; } @Override - public boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, int aCoverVariable, + public boolean manipulatesSidedRedstoneOutput(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 5; } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Drain.java b/src/main/java/gregtech/common/covers/GT_Cover_Drain.java index 82c6e78c57..14b25e4777 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Drain.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Drain.java @@ -31,23 +31,23 @@ public class GT_Cover_Drain extends GT_CoverBehavior { } @Override - 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 false; } @Override - 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) { if ((aCoverVariable % 3 > 1) && ((aTileEntity instanceof IMachineProgress))) { if (((IMachineProgress) aTileEntity).isAllowedToWork() != aCoverVariable % 3 < 2) { return aCoverVariable; } } - if (aSide != 6) { - Block tBlock = aTileEntity.getBlockAtSide(aSide); + if (side != ForgeDirection.UNKNOWN) { + final Block tBlock = aTileEntity.getBlockAtSide(side); if ((aCoverVariable < 3) && ((aTileEntity instanceof IFluidHandler))) { - if ((aSide == 1) && (aTileEntity.getWorld() + if ((side == ForgeDirection.UP) && (aTileEntity.getWorld() .isRaining()) && (aTileEntity.getWorld() .getPrecipitationHeight(aTileEntity.getXCoord(), aTileEntity.getZCoord()) - 2 @@ -55,7 +55,7 @@ public class GT_Cover_Drain extends GT_CoverBehavior { int tAmount = (int) (aTileEntity.getBiome().rainfall * 10.0F); if (tAmount > 0) { ((IFluidHandler) aTileEntity).fill( - ForgeDirection.getOrientation(aSide), + side, Materials.Water.getFluid( aTileEntity.getWorld() .isThundering() ? tAmount * 2 : tAmount), @@ -65,32 +65,31 @@ public class GT_Cover_Drain extends GT_CoverBehavior { FluidStack tLiquid = null; if (tBlock != null) { if (((tBlock == Blocks.water) || (tBlock == Blocks.flowing_water)) - && (aTileEntity.getMetaIDAtSide(aSide) == 0)) { + && (aTileEntity.getMetaIDAtSide(side) == 0)) { tLiquid = Materials.Water.getFluid(1000L); } else if (((tBlock == Blocks.lava) || (tBlock == Blocks.flowing_lava)) - && (aTileEntity.getMetaIDAtSide(aSide) == 0)) { + && (aTileEntity.getMetaIDAtSide(side) == 0)) { tLiquid = Materials.Lava.getFluid(1000L); } else if ((tBlock instanceof IFluidBlock)) { tLiquid = ((IFluidBlock) tBlock).drain( aTileEntity.getWorld(), - aTileEntity.getOffsetX(aSide, 1), - aTileEntity.getOffsetY(aSide, 1), - aTileEntity.getOffsetZ(aSide, 1), + aTileEntity.getOffsetX(side, 1), + aTileEntity.getOffsetY(side, 1), + aTileEntity.getOffsetZ(side, 1), false); } if ((tLiquid != null) && (tLiquid.getFluid() != null) - && ((aSide > 1) || ((aSide == 0) && (tLiquid.getFluid() + && ((side.ordinal() > 1) || ((side == ForgeDirection.DOWN) && (tLiquid.getFluid() .getDensity() <= 0)) - || ((aSide == 1) && (tLiquid.getFluid() + || ((side == ForgeDirection.UP) && (tLiquid.getFluid() .getDensity() >= 0))) - && (((IFluidHandler) aTileEntity).fill(ForgeDirection.getOrientation(aSide), tLiquid, false) - == tLiquid.amount)) { - ((IFluidHandler) aTileEntity).fill(ForgeDirection.getOrientation(aSide), tLiquid, true); + && (((IFluidHandler) aTileEntity).fill(side, tLiquid, false) == tLiquid.amount)) { + ((IFluidHandler) aTileEntity).fill(side, tLiquid, true); aTileEntity.getWorld() .setBlockToAir( - aTileEntity.getXCoord() + ForgeDirection.getOrientation(aSide).offsetX, - aTileEntity.getYCoord() + ForgeDirection.getOrientation(aSide).offsetY, - aTileEntity.getZCoord() + ForgeDirection.getOrientation(aSide).offsetZ); + aTileEntity.getXCoord() + side.offsetX, + aTileEntity.getYCoord() + side.offsetY, + aTileEntity.getZCoord() + side.offsetZ); } } } @@ -101,9 +100,9 @@ public class GT_Cover_Drain extends GT_CoverBehavior { || ((tBlock instanceof IFluidBlock)))) { aTileEntity.getWorld() .setBlock( - aTileEntity.getOffsetX(aSide, 1), - aTileEntity.getOffsetY(aSide, 1), - aTileEntity.getOffsetZ(aSide, 1), + aTileEntity.getOffsetX(side, 1), + aTileEntity.getOffsetY(side, 1), + aTileEntity.getOffsetZ(side, 1), Blocks.air, 0, 0); @@ -113,7 +112,7 @@ public class GT_Cover_Drain extends GT_CoverBehavior { } @Override - 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) { aCoverVariable = (aCoverVariable + (aPlayer.isSneaking() ? -1 : 1)) % 6; if (aCoverVariable < 0) { @@ -131,17 +130,18 @@ public class GT_Cover_Drain extends GT_CoverBehavior { } @Override - 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 ((IMachineProgress) aTileEntity).isAllowedToWork() == aCoverVariable < 2; } @Override - public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @Override - public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return aCoverVariable < 3 ? 50 : 1; } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java index 613e1e546d..d91e62a687 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import com.google.common.io.ByteArrayDataInput; @@ -57,8 +58,8 @@ public class GT_Cover_EUMeter extends GT_CoverBehaviorBase cover removed before data reach client @@ -211,28 +215,28 @@ public abstract class GT_Cover_FacadeBase extends GT_CoverBehaviorBase 0) { - tTank2 = aTileEntity.getITankContainerAtSide(aSide); + tTank2 = aTileEntity.getITankContainerAtSide(side); tTank1 = (IFluidHandler) aTileEntity; - directionFrom = ForgeDirection.getOrientation(aSi