Skip to content

Commit

Permalink
Jabel, Generic injection and mostly automatic code cleanup (#1829)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eigenraven authored Apr 1, 2023
1 parent e52cd9c commit b088958
Show file tree
Hide file tree
Showing 278 changed files with 3,094 additions and 4,729 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ developmentEnvironmentUserName = Developer

# Enables using modern java syntax (up to version 17) via Jabel, while still targetting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true

# Enables injecting missing generics into the decompiled source code for a better coding experience
# Turns most publically visible List, Map, etc. into proper List<Type>, Map<K, V> types
enableGenericInjection = false
enableGenericInjection = true


# Generate a class with String fields for the mod id, name, version and group name named with the fields below
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/gregtech/GT_Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void onLoad(FMLInitializationEvent aEvent) {

gregtechproxy.onLoad();

registerCircuitProgrammer(new Predicate<ItemStack>() {
registerCircuitProgrammer(new Predicate<>() {

private final int screwdriverOreId = OreDictionary.getOreID("craftingToolScrewdriver");

Expand Down Expand Up @@ -711,14 +711,14 @@ public void onServerStarting(FMLServerStartingEvent aEvent) {
FurnaceRecipes.smelting()
.getSmeltingList()
.values()
.forEach(k -> tStacks.add((ItemStack) k));
.forEach(tStacks::add);

if (gregtechproxy.mCraftingUnification) {
GT_Log.out.println("GT_Mod: Crafting Recipes");
for (Object tRecipe : CraftingManager.getInstance()
.getRecipeList()) {
for (IRecipe tRecipe : CraftingManager.getInstance()
.getRecipeList()) {
if ((tRecipe instanceof IRecipe)) {
tStacks.add(((IRecipe) tRecipe).getRecipeOutput());
tStacks.add(tRecipe.getRecipeOutput());
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/gregtech/api/enums/ConfigCategories.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public enum ConfigCategories {

public enum IDs {
crops,
enchantments;
enchantments
}

public enum Materials {
heatdamage,
oreprocessingoutputmultiplier,
blastfurnacerequirements,
blastinductionsmelter,;
blastinductionsmelter,
}

public enum Recipes {
Expand All @@ -27,7 +27,7 @@ public enum Recipes {
recipereplacements,
storageblockcrafting,
storageblockdecrafting,
crops;
crops
}

public enum Machines {
Expand All @@ -47,11 +47,11 @@ public enum Machines {
massfabamplifier,
maceration,
rockcrushing,
pulverization;
pulverization
}

public enum Fuels {
boilerfuels;
boilerfuels
}

public enum Tools {
Expand All @@ -62,6 +62,6 @@ public enum Tools {
hammertripleplate,
hammerquadrupleplate,
hammerquintupleplate,
scoop;
scoop
}
}
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/enums/Dyes.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum Dyes implements IColorModulationContainer {
public final String mName;
public final short[] mRGBa;
public final short[] mOriginalRGBa;
private final ArrayList<Fluid> mFluidDyes = new GT_ArrayList<Fluid>(false, 1);
private final ArrayList<Fluid> mFluidDyes = new GT_ArrayList<>(false, 1);

Dyes(int aIndex, int aR, int aG, int aB, String aName) {
mIndex = (byte) aIndex;
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/gregtech/api/enums/GT_Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,10 @@ public class GT_Values {
EnumChatFormatting.DARK_GREEN.toString(), // UV, 8
EnumChatFormatting.DARK_RED.toString(), // UHV, 9
EnumChatFormatting.DARK_PURPLE.toString(), // UEV, 10
EnumChatFormatting.DARK_BLUE.toString() + EnumChatFormatting.BOLD.toString(), // UIV, 11
EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD.toString()
+ EnumChatFormatting.UNDERLINE.toString(), // UMV, 12
EnumChatFormatting.DARK_RED.toString() + EnumChatFormatting.BOLD.toString()
+ EnumChatFormatting.UNDERLINE.toString(), // UXV, 13
EnumChatFormatting.WHITE.toString() + EnumChatFormatting.BOLD.toString()
+ EnumChatFormatting.UNDERLINE.toString(), // MAX, 14
EnumChatFormatting.DARK_BLUE.toString() + EnumChatFormatting.BOLD, // UIV, 11
EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD + EnumChatFormatting.UNDERLINE, // UMV, 12
EnumChatFormatting.DARK_RED.toString() + EnumChatFormatting.BOLD + EnumChatFormatting.UNDERLINE, // UXV, 13
EnumChatFormatting.WHITE.toString() + EnumChatFormatting.BOLD + EnumChatFormatting.UNDERLINE, // MAX, 14
EnumChatFormatting.OBFUSCATED.toString() // ~~~, 15
};

Expand Down Expand Up @@ -547,4 +544,18 @@ public static void calculateMaxPlasmaTurbineEfficiency() {
public static double getMaxPlasmaTurbineEfficiency() {
return maxPlasmaTurbineEfficiency;
}

private static final long[] EXPLOSION_LOOKUP_V = new long[] { V[0], V[1], V[2], V[3], V[4], V[4] * 2, V[5], V[6],
V[7], V[8], V[8] * 2, V[9], V[10], V[11], V[12], V[12] * 2, V[13], V[14], V[15] };
private static final float[] EXPLOSION_LOOKUP_POWER = new float[] { 1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, 8.0F,
9.0F, 10.0F, 11.0F, 12.0F, 13.0F, 14.0F, 15.0F, 16.0F, 17.0F, 18.0F, 19.0F, 20.0F };

public static float getExplosionPowerForVoltage(long voltage) {
for (int i = 0; i < EXPLOSION_LOOKUP_V.length; i++) {
if (voltage < EXPLOSION_LOOKUP_V[i]) {
return EXPLOSION_LOOKUP_POWER[i];
}
}
return EXPLOSION_LOOKUP_POWER[EXPLOSION_LOOKUP_POWER.length - 1];
}
}
Loading

0 comments on commit b088958

Please sign in to comment.