diff options
| author | Raven Szewczyk <git@eigenraven.me> | 2023-04-01 20:06:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-01 19:06:12 +0000 |
| commit | b088958c9f6935d356b6c087c8e8106b400aa24f (patch) | |
| tree | be608fac08ba158f1226a4fb9f5b1ed459bac2a9 /src/main/java/gregtech/api/metatileentity/implementations | |
| parent | e52cd9c3458584e58073df5cd9cde1302994f266 (diff) | |
| download | GT5-Unofficial-b088958c9f6935d356b6c087c8e8106b400aa24f.tar.gz GT5-Unofficial-b088958c9f6935d356b6c087c8e8106b400aa24f.tar.bz2 GT5-Unofficial-b088958c9f6935d356b6c087c8e8106b400aa24f.zip | |
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
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/implementations')
17 files changed, 474 insertions, 901 deletions
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<TileEntity> 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<EntityLivingBase>) 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<EntityLivingBase>) 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<EntityLivingBase>) 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 -> |
