From b088958c9f6935d356b6c087c8e8106b400aa24f Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sat, 1 Apr 2023 20:06:12 +0100 Subject: Jabel, Generic injection and mostly automatic code cleanup (#1829) * Enable Jabel&Generic injection, fix type error caused by this * add missing <> * Infer generic types automatically * Parametrize cast types * Use enhanced for loops * Unnecessary boxing * Unnecessary unboxing * Use Objects.equals * Explicit type can be replaced with `<>` * Collapse identical catch blocks * Add SafeVarargs where applicable * Anonymous type can be replaced with lambda * Use List.sort directly * Lambda can be a method reference * Statement lambda can be an expression lambda * Use string switches * Instanceof pattern matching * Text block can be used * Migrate to enhanced switch * Java style array declarations * Unnecessary toString() * More unnecessary String conversions * Unnecessary modifiers * Unnecessary semicolons * Fix duplicate conditions * Extract common code from if branches * Replace switches with ifs for 1-2 cases * Inner class may be static * Minor performance issues * Replace string appending in loops with string builders * Fix IntelliJ using the wrong empty list method * Use Long.compare * Generic arguments: getSubItems * Generic arguments: getSubBlocks * Raw types warnings * Fix remaining missing generics * Too weak variable type leads to unnecessary cast * Redundant type casts * Redundant array length check * Redundant vararg arrays * Manual min/max implementations * A couple missed inspections * Goodbye explosion power ternary ladder * Apply spotless * Get rid of the other two big ternary ladders * Binary search explosion power * Don't overcomplicate things --- .../api/metatileentity/BaseMetaPipeEntity.java | 28 +- .../api/metatileentity/BaseMetaTileEntity.java | 32 +- .../api/metatileentity/BaseTileEntity.java | 9 +- .../api/metatileentity/CoverableTileEntity.java | 23 +- .../api/metatileentity/MetaPipeEntity.java | 35 +- .../api/metatileentity/MetaTileEntity.java | 35 +- .../implementations/GT_MetaPipeEntity_Cable.java | 3 +- .../implementations/GT_MetaPipeEntity_Fluid.java | 116 ++- .../GT_MetaTileEntity_BasicBatteryBuffer.java | 120 ++- .../GT_MetaTileEntity_BasicGenerator.java | 3 +- .../GT_MetaTileEntity_BasicMachine.java | 39 +- .../GT_MetaTileEntity_BasicMachine_Bronze.java | 49 +- .../GT_MetaTileEntity_BasicMachine_GT_Recipe.java | 826 ++++++--------------- .../implementations/GT_MetaTileEntity_Buffer.java | 68 +- .../GT_MetaTileEntity_CubicMultiBlockBase.java | 2 +- ...MetaTileEntity_ExtendedPowerMultiBlockBase.java | 2 +- .../GT_MetaTileEntity_Hatch_DataAccess.java | 23 +- .../GT_MetaTileEntity_Hatch_InputBus.java | 16 +- .../GT_MetaTileEntity_Hatch_Maintenance.java | 3 +- .../GT_MetaTileEntity_Hatch_Output.java | 40 +- .../GT_MetaTileEntity_Hatch_OutputBus.java | 18 +- .../GT_MetaTileEntity_MultiBlockBase.java | 43 +- .../GT_MetaTileEntity_Transformer.java | 4 +- 23 files changed, 524 insertions(+), 1013 deletions(-) (limited to 'src/main/java/gregtech/api/metatileentity') diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index e1a83f5cc6..0bc1201827 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -346,36 +346,34 @@ public class BaseMetaPipeEntity extends CommonMetaTileEntity if (isClientSide()) { issueTextureUpdate(); switch (aEventID) { - case GregTechTileClientEvents.CHANGE_COMMON_DATA: - mConnections = (byte) aValue; - break; - case GregTechTileClientEvents.CHANGE_CUSTOM_DATA: + case GregTechTileClientEvents.CHANGE_COMMON_DATA -> mConnections = (byte) aValue; + case GregTechTileClientEvents.CHANGE_CUSTOM_DATA -> { if (hasValidMetaTileEntity()) mMetaTileEntity.onValueUpdate((byte) aValue); - break; - case GregTechTileClientEvents.CHANGE_COLOR: + } + case GregTechTileClientEvents.CHANGE_COLOR -> { if (aValue > 16 || aValue < 0) aValue = 0; mColor = (byte) aValue; - break; - case GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT: + } + case GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT -> { mSidedRedstone[0] = (byte) ((aValue & 1) == 1 ? 15 : 0); mSidedRedstone[1] = (byte) ((aValue & 2) == 2 ? 15 : 0); mSidedRedstone[2] = (byte) ((aValue & 4) == 4 ? 15 : 0); mSidedRedstone[3] = (byte) ((aValue & 8) == 8 ? 15 : 0); mSidedRedstone[4] = (byte) ((aValue & 16) == 16 ? 15 : 0); mSidedRedstone[5] = (byte) ((aValue & 32) == 32 ? 15 : 0); - break; - case GregTechTileClientEvents.DO_SOUND: + } + case GregTechTileClientEvents.DO_SOUND -> { if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.doSound((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - case GregTechTileClientEvents.START_SOUND_LOOP: + } + case GregTechTileClientEvents.START_SOUND_LOOP -> { if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.startSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - case GregTechTileClientEvents.STOP_SOUND_LOOP: + } + case GregTechTileClientEvents.STOP_SOUND_LOOP -> { if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.stopSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; + } } } return true; diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 00e31ed9a0..0f908bdaa3 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -728,48 +728,46 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity implements IGregTec if (isClientSide()) { issueTextureUpdate(); switch (aEventID) { - case GregTechTileClientEvents.CHANGE_COMMON_DATA: + case GregTechTileClientEvents.CHANGE_COMMON_DATA -> { mFacing = (byte) (aValue & 7); mActive = ((aValue & 8) != 0); mRedstone = ((aValue & 16) != 0); // mLockUpgrade = ((aValue&32) != 0); mWorks = ((aValue & 64) != 0); - break; - case GregTechTileClientEvents.CHANGE_CUSTOM_DATA: + } + case GregTechTileClientEvents.CHANGE_CUSTOM_DATA -> { if (hasValidMetaTileEntity()) { if ((aValue & 0x80) == 0) // Is texture index mMetaTileEntity.onValueUpdate((byte) (aValue & 0x7F)); else if (mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) // is texture page and hatch ((GT_MetaTileEntity_Hatch) mMetaTileEntity).onTexturePageUpdate((byte) (aValue & 0x7F)); } - break; - case GregTechTileClientEvents.CHANGE_COLOR: + } + case GregTechTileClientEvents.CHANGE_COLOR -> { if (aValue > 16 || aValue < 0) aValue = 0; mColor = (byte) aValue; - break; - case GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT: + } + case GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT -> { mSidedRedstone[0] = (byte) ((aValue & 1) == 1 ? 15 : 0); mSidedRedstone[1] = (byte) ((aValue & 2) == 2 ? 15 : 0); mSidedRedstone[2] = (byte) ((aValue & 4) == 4 ? 15 : 0); mSidedRedstone[3] = (byte) ((aValue & 8) == 8 ? 15 : 0); mSidedRedstone[4] = (byte) ((aValue & 16) == 16 ? 15 : 0); mSidedRedstone[5] = (byte) ((aValue & 32) == 32 ? 15 : 0); - break; - case GregTechTileClientEvents.DO_SOUND: + } + case GregTechTileClientEvents.DO_SOUND -> { if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.doSound((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - case GregTechTileClientEvents.START_SOUND_LOOP: + } + case GregTechTileClientEvents.START_SOUND_LOOP -> { if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.startSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - case GregTechTileClientEvents.STOP_SOUND_LOOP: + } + case GregTechTileClientEvents.STOP_SOUND_LOOP -> { if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.stopSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); - break; - case GregTechTileClientEvents.CHANGE_LIGHT: - mLightValue = (byte) aValue; - break; + } + case GregTechTileClientEvents.CHANGE_LIGHT -> mLightValue = (byte) aValue; } } return true; diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index 238dc6ba30..3ef732b1c8 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -861,8 +861,7 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje final ItemStackHandler inventoryHandler = getInventoryHandler(); if (inventoryHandler == null) return; - if (!(this instanceof IInventory)) return; - final IInventory inv = (IInventory) this; + if (!(this instanceof IInventory inv)) return; final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); if (ccs == null) return; @@ -937,8 +936,7 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); if (ccs == null) return; - if (!(this instanceof IInventory)) return; - final IInventory inv = (IInventory) this; + if (!(this instanceof IInventory inv)) return; final List circuits = ccs.getConfigurationCircuits(); uiContext.openClientWindow( @@ -965,8 +963,7 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); if (ccs == null) return; - if (!(this instanceof IInventory)) return; - final IInventory inv = (IInventory) this; + if (!(this instanceof IInventory inv)) return; GT_Values.NW.sendToServer(new GT_Packet_SetConfigurationCircuit(this, selected)); // we will not do any validation on client side diff --git a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java index f2929e7e1e..4167bf1701 100644 --- a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java @@ -702,18 +702,17 @@ public abstract class CoverableTileEntity extends BaseTileEntity implements ICov .setSize(COVER_TAB_WIDTH, COVER_TAB_HEIGHT)) .addChild( new ItemDrawable( - () -> { return getCoverItemAtSide(side); }) - .asWidget() - .setPos( - (COVER_TAB_WIDTH - - ICON_SIZE) - / 2 - + (flipHorizontally - ? -1 - : 1), - (COVER_TAB_HEIGHT - - ICON_SIZE) - / 2)) + () -> getCoverItemAtSide(side)).asWidget() + .setPos( + (COVER_TAB_WIDTH + - ICON_SIZE) + / 2 + + (flipHorizontally + ? -1 + : 1), + (COVER_TAB_HEIGHT + - ICON_SIZE) + / 2)) .setEnabled(widget -> getCoverItemAtSide(side) != null)); } } diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index cf1cb5dc1b..a42525ae45 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -1,7 +1,6 @@ package gregtech.api.metatileentity; import static gregtech.api.enums.GT_Values.GT; -import static gregtech.api.enums.GT_Values.V; import java.io.File; import java.util.ArrayList; @@ -33,6 +32,7 @@ import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; import gregtech.api.enums.Dyes; +import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.metatileentity.IConnectable; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IColoredTileEntity; @@ -115,7 +115,7 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { ItemStack tStack = new ItemStack(GregTech_API.sBlockMachines, 1, aID); tStack.getItem() - .addInformation(tStack, null, new ArrayList(), true); + .addInformation(tStack, null, new ArrayList<>(), true); } /** @@ -754,36 +754,7 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { @Override public void doExplosion(long aExplosionPower) { - float tStrength = aExplosionPower < V[0] ? 1.0F - : aExplosionPower < V[1] ? 2.0F - : aExplosionPower < V[2] ? 3.0F - : aExplosionPower < V[3] ? 4.0F - : aExplosionPower < V[4] ? 5.0F - : aExplosionPower < V[4] * 2 ? 6.0F - : aExplosionPower < V[5] ? 7.0F - : aExplosionPower < V[6] ? 8.0F - : aExplosionPower < V[7] ? 9.0F - : aExplosionPower < V[8] ? 10.0F - : aExplosionPower < V[8] * 2 - ? 11.0F - : aExplosionPower < V[9] - ? 12.0F - : aExplosionPower - < V[10] ? 13.0F - : aExplosionPower - < V[11] ? 14.0F - : aExplosionPower - < V[12] ? 15.0F - : aExplosionPower - < V[12] * 2 - ? 16.0F - : aExplosionPower - < V[13] ? 17.0F - : aExplosionPower - < V[14] ? 18.0F - : aExplosionPower - < V[15] ? 19.0F - : 20.0F; + float tStrength = GT_Values.getExplosionPowerForVoltage(aExplosionPower); int tX = getBaseMetaTileEntity().getXCoord(), tY = getBaseMetaTileEntity().getYCoord(), tZ = getBaseMetaTileEntity().getZCoord(); World tWorld = getBaseMetaTileEntity().getWorld(); diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index a017fca2e0..c929bd5677 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -1,7 +1,5 @@ package gregtech.api.metatileentity; -import static gregtech.api.enums.GT_Values.V; - import java.io.File; import java.util.ArrayList; import java.util.List; @@ -45,6 +43,7 @@ import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; import gregtech.api.enums.Dyes; +import gregtech.api.enums.GT_Values; import gregtech.api.enums.SoundResource; import gregtech.api.enums.SteamVariant; import gregtech.api.gui.GT_GUIColorOverride; @@ -846,8 +845,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac @Override public void setInventorySlotContents(int aIndex, ItemStack aStack) { markDirty(); - if (this instanceof IConfigurationCircuitSupport) { - IConfigurationCircuitSupport ccs = (IConfigurationCircuitSupport) this; + if (this instanceof IConfigurationCircuitSupport ccs) { if (ccs.allowSelectCircuit() && aIndex == ccs.getCircuitSlot() && aStack != null) { mInventory[aIndex] = GT_Utility.copyAmount(0, aStack); return; @@ -1090,28 +1088,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac @Override public void doExplosion(long aExplosionPower) { - // spotless:off - float tStrength = - aExplosionPower < V[0] ? 1.0F : - aExplosionPower < V[1] ? 2.0F : - aExplosionPower < V[2] ? 3.0F : - aExplosionPower < V[3] ? 4.0F : - aExplosionPower < V[4] ? 5.0F : - aExplosionPower < V[4] * 2 ? 6.0F : - aExplosionPower < V[5] ? 7.0F : - aExplosionPower < V[6] ? 8.0F : - aExplosionPower < V[7] ? 9.0F : - aExplosionPower < V[8] ? 10.0F : - aExplosionPower < V[8] * 2 ? 11.0F : - aExplosionPower < V[9] ? 12.0F : - aExplosionPower < V[10] ? 13.0F : - aExplosionPower < V[11] ? 14.0F : - aExplosionPower < V[12] ? 15.0F : - aExplosionPower < V[12] * 2 ? 16.0F : - aExplosionPower < V[13] ? 17.0F : - aExplosionPower < V[14] ? 18.0F : - aExplosionPower < V[15] ? 19.0F : 20.0F; - // spotless:on + float tStrength = GT_Values.getExplosionPowerForVoltage(aExplosionPower); final int tX = getBaseMetaTileEntity().getXCoord(); final int tY = getBaseMetaTileEntity().getYCoord(); final int tZ = getBaseMetaTileEntity().getZCoord(); @@ -1201,9 +1178,8 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac ForgeDirection.getOrientation(mBaseMetaTileEntity.getFrontFacing()) .name())); - if (this instanceof IPowerChannelState) { + if (this instanceof IPowerChannelState state) { // adapted from PowerStateWailaDataProvider - final IPowerChannelState state = (IPowerChannelState) this; NBTTagCompound tag = accessor.getNBTData(); final boolean isActive = tag.getBoolean("isActive"); final boolean isPowered = tag.getBoolean("isPowered"); @@ -1224,9 +1200,8 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac @Override public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, int z) { - if (this instanceof IPowerChannelState) { + if (this instanceof IPowerChannelState state) { // adapted from PowerStateWailaDataProvider - final IPowerChannelState state = (IPowerChannelState) this; final boolean isActive = state.isActive(); final boolean isPowered = state.isPowered(); final boolean isBooting = state.isBooting(); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java index 790d4d6c1f..2a1ec3c22c 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java @@ -223,8 +223,7 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile public long transferElectricity(byte aSide, long aVoltage, long aAmperage, HashSet aAlreadyPassedSet) { if (!getBaseMetaTileEntity().isServerSide() || !isConnectedAtSide(aSide) && aSide != 6) return 0; final BaseMetaPipeEntity tBase = (BaseMetaPipeEntity) getBaseMetaTileEntity(); - if (!(tBase.getNode() instanceof PowerNode)) return 0; - final PowerNode tNode = (PowerNode) tBase.getNode(); + if (!(tBase.getNode() instanceof PowerNode tNode)) return 0; if (tNode != null) { int tPlace = 0; final Node[] tToPower = new Node[tNode.mConsumers.size()]; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java index a3e44640e8..b428d187d7 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java @@ -159,40 +159,24 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { } protected static ITexture getRestrictorTexture(byte aMask) { - switch (aMask) { - case 1: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UP); - case 2: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_DOWN); - case 3: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UD); - case 4: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_LEFT); - case 5: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UL); - case 6: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_DL); - case 7: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_NR); - case 8: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_RIGHT); - case 9: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UR); - case 10: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_DR); - case 11: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_NL); - case 12: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_LR); - case 13: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_ND); - case 14: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_NU); - case 15: - return TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR); - default: - return null; - } + return switch (aMask) { + case 1 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UP); + case 2 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_DOWN); + case 3 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UD); + case 4 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_LEFT); + case 5 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UL); + case 6 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_DL); + case 7 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_NR); + case 8 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_RIGHT); + case 9 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_UR); + case 10 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_DR); + case 11 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_NL); + case 12 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_LR); + case 13 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_ND); + case 14 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR_NU); + case 15 -> TextureFactory.of(Textures.BlockIcons.PIPE_RESTRICTOR); + default -> null; + }; } @Override @@ -349,22 +333,22 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { sendSound((byte) 9); if (tTemperature > 320) { try { - for (EntityLivingBase tLiving : (ArrayList) getBaseMetaTileEntity().getWorld() - .getEntitiesWithinAABB( - EntityLivingBase.class, - AxisAlignedBB.getBoundingBox( - getBaseMetaTileEntity().getXCoord() - - 2, - getBaseMetaTileEntity().getYCoord() - - 2, - getBaseMetaTileEntity().getZCoord() - - 2, - getBaseMetaTileEntity().getXCoord() - + 3, - getBaseMetaTileEntity().getYCoord() - + 3, - getBaseMetaTileEntity().getZCoord() - + 3))) { + for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() + .getEntitiesWithinAABB( + EntityLivingBase.class, + AxisAlignedBB.getBoundingBox( + getBaseMetaTileEntity().getXCoord() + - 2, + getBaseMetaTileEntity().getYCoord() + - 2, + getBaseMetaTileEntity().getZCoord() + - 2, + getBaseMetaTileEntity().getXCoord() + + 3, + getBaseMetaTileEntity().getYCoord() + + 3, + getBaseMetaTileEntity().getZCoord() + + 3))) { GT_Utility.applyHeatDamage(tLiving, (tTemperature - 300) / 25.0F); } } catch (Throwable e) { @@ -372,22 +356,22 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity { } } else if (tTemperature < 260) { try { - for (EntityLivingBase tLiving : (ArrayList) getBaseMetaTileEntity().getWorld() - .getEntitiesWithinAABB( - EntityLivingBase.class, - AxisAlignedBB.getBoundingBox( - getBaseMetaTileEntity().getXCoord() - - 2, - getBaseMetaTileEntity().getYCoord() - - 2, - getBaseMetaTileEntity().getZCoord() - - 2, - getBaseMetaTileEntity().getXCoord() - + 3, - getBaseMetaTileEntity().getYCoord() - + 3, - getBaseMetaTileEntity().getZCoord() - + 3))) { + for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() + .getEntitiesWithinAABB( + EntityLivingBase.class, + AxisAlignedBB.getBoundingBox( + getBaseMetaTileEntity().getXCoord() + - 2, + getBaseMetaTileEntity().getYCoord() + - 2, + getBaseMetaTileEntity().getZCoord() + - 2, + getBaseMetaTileEntity().getXCoord() + + 3, + getBaseMetaTileEntity().getYCoord() + + 3, + getBaseMetaTileEntity().getZCoord() + + 3))) { GT_Utility.applyFrostDamage(tLiving, (270 - tTemperature) / 12.5F); } } catch (Throwable e) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java index 7b2a4fa232..bae070f6dd 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java @@ -382,70 +382,62 @@ public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_Tier @Override public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { switch (mInventory.length) { - case 4: - builder.widget( - SlotGroup.ofItemHandler(inventoryHandler, 2) - .startFromSlot(0) - .endAtSlot(3) - .slotCreator(index -> new BaseSlot(inventoryHandler, index) { - - @Override - public int getSlotStackLimit() { - return 1; - } - }) - .background(getGUITextureSet().getItemSlot()) - .build() - .setPos(70, 25)); - break; - case 9: - builder.widget( - SlotGroup.ofItemHandler(inventoryHandler, 3) - .startFromSlot(0) - .endAtSlot(8) - .slotCreator(index -> new BaseSlot(inventoryHandler, index) { - - @Override - public int getSlotStackLimit() { - return 1; - } - }) - .background(getGUITextureSet().getItemSlot()) - .build() - .setPos(61, 16)); - break; - case 16: - builder.widget( - SlotGroup.ofItemHandler(inventoryHandler, 4) - .startFromSlot(0) - .endAtSlot(15) - .slotCreator(index -> new BaseSlot(inventoryHandler, index) { - - @Override - public int getSlotStackLimit() { - return 1; - } - }) - .background(getGUITextureSet().getItemSlot()) - .build() - .setPos(52, 7)); - break; - default: - builder.widget( - SlotGroup.ofItemHandler(inventoryHandler, 1) - .startFromSlot(0) - .endAtSlot(0) - .slotCreator(index -> new BaseSlot(inventoryHandler, index) { - - @Override - public int getSlotStackLimit() { - return 1; - } - }) - .background(getGUITextureSet().getItemSlot()) - .build() - .setPos(79, 34)); - break; + case 4 -> builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(0) + .endAtSlot(3) + .slotCreator(index -> new BaseSlot(inventoryHandler, index) { + + @Override + public int getSlotStackLimit() { + return 1; + } + }) + .background(getGUITextureSet().getItemSlot()) + .build() + .setPos(70, 25)); + case 9 -> builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(0) + .endAtSlot(8) + .slotCreator(index -> new BaseSlot(inventoryHandler, index) { + + @Override + public int getSlotStackLimit() { + return 1; + } + }) + .background(getGUITextureSet().getItemSlot()) + .build() + .setPos(61, 16)); + case 16 -> builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(0) + .endAtSlot(15) + .slotCreator(index -> new BaseSlot(inventoryHandler, index) { + + @Override + public int getSlotStackLimit() { + return 1; + } + }) + .background(getGUITextureSet().getItemSlot()) + .build() + .setPos(52, 7)); + default -> builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 1) + .startFromSlot(0) + .endAtSlot(0) + .slotCreator(index -> new BaseSlot(inventoryHandler, index) { + + @Override + public int getSlotStackLimit() { + return 1; + } + }) + .background(getGUITextureSet().getItemSlot()) + .build() + .setPos(79, 34)); } } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index a71b94b916..182b25fb92 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -302,8 +302,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity public long getFuelValue(FluidStack aLiquid, boolean aLong) { GT_Recipe_Map tRecipes = getRecipes(); - if (aLiquid == null || !(tRecipes instanceof GT_Recipe.GT_Recipe_Map_Fuel)) return 0; - GT_Recipe.GT_Recipe_Map_Fuel tFuels = (GT_Recipe.GT_Recipe_Map_Fuel) tRecipes; + if (aLiquid == null || !(tRecipes instanceof GT_Recipe.GT_Recipe_Map_Fuel tFuels)) return 0; GT_Recipe tFuel = tFuels.findFuel(aLiquid); if (tFuel == null) return 0; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 78fc68ee81..49b76b1579 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -237,14 +237,37 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return mTextures[mMainFacing < 2 - ? aSide == aFacing ? aActive ? 2 : 3 - : aSide == 0 ? aActive ? 6 : 7 : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1 - : aSide == mMainFacing ? aActive ? 2 : 3 - : (showPipeFacing() && aSide == aFacing) - ? aSide == 0 ? aActive ? 8 : 9 : aSide == 1 ? aActive ? 10 : 11 : aActive ? 12 : 13 - : aSide == 0 ? aActive ? 6 : 7 - : aSide == 1 ? aActive ? 4 : 5 : aActive ? 0 : 1][aColorIndex + 1]; + final int textureIndex; + if (mMainFacing < 2) { + if (aSide == aFacing) { + textureIndex = aActive ? 2 : 3; + } else { + textureIndex = switch (aSide) { + case 0 -> aActive ? 6 : 7; + case 1 -> aActive ? 4 : 5; + default -> aActive ? 0 : 1; + }; + } + } else { + if (aSide == mMainFacing) { + textureIndex = aActive ? 2 : 3; + } else { + if (showPipeFacing() && aSide == aFacing) { + textureIndex = switch (aSide) { + case 0 -> aActive ? 8 : 9; + case 1 -> aActive ? 10 : 11; + default -> aActive ? 12 : 13; + }; + } else { + textureIndex = switch (aSide) { + case 0 -> aActive ? 6 : 7; + case 1 -> aActive ? 4 : 5; + default -> aActive ? 0 : 1; + }; + } + } + } + return mTextures[textureIndex][aColorIndex + 1]; } @Override diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java index 934554dfbc..d2433e04e6 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java @@ -4,8 +4,6 @@ import static gregtech.api.enums.GT_Values.D1; import static gregtech.api.enums.Textures.BlockIcons.*; import static gregtech.api.objects.XSTR.XSTR_INSTANCE; -import java.util.ArrayList; - import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; @@ -173,31 +171,28 @@ public abstract class GT_MetaTileEntity_BasicMachine_Bronze extends GT_MetaTileE sendSound((byte) 9); mNeedsSteamVenting = false; try { - for (EntityLivingBase tLiving : (ArrayList) getBaseMetaTileEntity().getWorld() - .getEntitiesWithinAABB( - EntityLivingBase.class, - AxisAlignedBB.getBoundingBox( - getBaseMetaTileEntity().getOffsetX( - getBaseMetaTileEntity().getFrontFacing(), - 1), - getBaseMetaTileEntity().getOffsetY( - getBaseMetaTileEntity().getFrontFacing(), - 1), - getBaseMetaTileEntity().getOffsetZ( - getBaseMetaTileEntity().getFrontFacing(), - 1), - getBaseMetaTileEntity().getOffsetX( - getBaseMetaTileEntity().getFrontFacing(), - 1) - + 1, - getBaseMetaTileEntity().getOffsetY( - getBaseMetaTileEntity().getFrontFacing(), - 1) - + 1, - getBaseMetaTileEntity().getOffsetZ( - getBaseMetaTileEntity().getFrontFacing(), - 1) - + 1))) { + for (EntityLivingBase tLiving : getBaseMetaTileEntity().getWorld() + .getEntitiesWithinAABB( + EntityLivingBase.class, + AxisAlignedBB.getBoundingBox( + getBaseMetaTileEntity().getOffsetX( + getBaseMetaTileEntity().getFrontFacing(), + 1), + getBaseMetaTileEntity().getOffsetY( + getBaseMetaTileEntity().getFrontFacing(), + 1), + getBaseMetaTileEntity().getOffsetZ( + getBaseMetaTileEntity().getFrontFacing(), + 1), + getBaseMetaTileEntity().getOffsetX( + getBaseMetaTileEntity().getFrontFacing(), + 1) + 1, + getBaseMetaTileEntity().getOffsetY( + getBaseMetaTileEntity().getFrontFacing(), + 1) + 1, + getBaseMetaTileEntity().getOffsetZ( + getBaseMetaTileEntity().getFrontFacing(), + 1) + 1))) { GT_Utility.applyHeatDamage(tLiving, getSteamDamage()); } } catch (Throwable e) { diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java index 5331f67dca..bc756fa6a5 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java @@ -40,7 +40,6 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.api.util.WorldSpawnedEventBuilder; import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; import ic2.core.Ic2Items; @@ -231,673 +230,284 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_ if (aRecipe[i] == GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PLATE) { switch (this.mTier) { - case 0: - case 1: - aRecipe[i] = OrePrefixes.plate.get(Materials.Steel); - break; - case 2: - aRecipe[i] = OrePrefixes.plate.get(Materials.Aluminium); - break; - case 3: - aRecipe[i] = OrePrefixes.plate.get(Materials.StainlessSteel); - break; - case 4: - aRecipe[i] = OrePrefixes.plate.get(Materials.Titanium); - break; - case 5: - aRecipe[i] = OrePrefixes.plate.get(Materials.TungstenSteel); - break; - case 6: - aRecipe[i] = OrePrefixes.plate.get(Materials.HSSG); - break; - case 7: - aRecipe[i] = OrePrefixes.plate.get(Materials.HSSE); - break; - default: - aRecipe[i] = OrePrefixes.plate.get(Materials.Neutronium); - break; + case 0, 1 -> aRecipe[i] = OrePrefixes.plate.get(Materials.Steel); + case 2 -> aRecipe[i] = OrePrefixes.plate.get(Materials.Aluminium); + case 3 -> aRecipe[i] = OrePrefixes.plate.get(Materials.StainlessSteel); + case 4 -> aRecipe[i] = OrePrefixes.plate.get(Materials.Titanium); + case 5 -> aRecipe[i] = OrePrefixes.plate.get(Materials.TungstenSteel); + case 6 -> aRecipe[i] = OrePrefixes.plate.get(Materials.HSSG); + case 7 -> aRecipe[i] = OrePrefixes.plate.get(Materials.HSSE); + default -> aRecipe[i] = OrePrefixes.plate.get(Materials.Neutronium); } continue; } if (aRecipe[i] == GT_MetaTileEntity_BasicMachine_GT_Recipe.X.PIPE) { switch (this.mTier) { - case 0: - case 1: - aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Bronze); - break; - case 2: - aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Steel); - break; - case 3: - aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.StainlessSteel); - break; - case 4: - aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Titanium); - break; - case 5: - aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.TungstenSteel); - break; - case 6: - aRecipe[i] = OrePrefixes.pipeSmall.get(Materials.Ultimate); - break; - case 7: - aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Ultimate); - break; - case 8: - aRecipe[i] = OrePrefixes.pipeLarge.get(Materials.Ultimate); - break; - default: - aRecipe[i] = OrePrefixes.pipeHuge.get(Materials.Ultimate); - break; + case 0, 1 -> aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Bronze); + case 2 -> aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Steel); + case 3 -> aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.StainlessSteel); + case 4 -> aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Titanium); + case 5 -> aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.TungstenSteel); + case 6 -> aRecipe[i] = OrePrefixes.pipeSmall.get(Materials.Ultimate); + case 7 -> aRecipe[i] = OrePrefixes.pipeMedium.get(Materials.Ultimate); + case 8 -> aRecipe[i] = OrePrefixes.pipeLarge.get(Materials.Ultimate); + default -> aRecipe[i] = OrePrefixes.pipeHuge.get(Materials.Ultimate); } continue; } if (aRecipe[i] == GT_MetaTileEntity_BasicMachine_GT_Recipe.X.COIL_HEATING) { switch (this.mTier) { - case 0: - case 1: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.AnyCopper); - break; - case 2: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.Cupronickel); - break; - case 3: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.Kanthal); - break; - case 4: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.Nichrome); - break; - case 5: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.TPV); - break; - case 6: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.HSSG); - break; - case 7: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.Naquadah); - break; - case 8: - aRecipe[i] = OrePrefixes.wireGt02.get(Materials.NaquadahAlloy); - break; - case 9: - aRecipe[i] = OrePrefixes.wireGt04.get(Materials.NaquadahAlloy); - break; - default: - aRecipe[i] = OrePrefixes.wireGt08.get(Materials.NaquadahAlloy); - break; + case 0, 1 -> aRecipe[i] = OrePrefixes.wireGt02.get(Materials.AnyCopper); + case 2 -> aRecipe[i] = OrePrefixes.wireGt02.get(Materials.Cupronickel); + case 3 -> aRecipe[i] = OrePrefixes.wireGt02.get(Materials.Kanthal); +