Skip to content

Commit

Permalink
Enable generics injection & Jabel & code cleanup (#307)
Browse files Browse the repository at this point in the history
* Enable Jabel and generic injection

* Use RoundingMode enum values

* Use enhanced for loops

* Use diamond operator where appropriate

* Deprecate ChainedIterator

* spotless

* Collapse identical catch blocks

* Use try with resources

* Use List.sort where possible

* Anonymous type->lambda

* Loop -> removeIf

* Simplifiable map operations

* Use enhanced instanceof

* Use enhanced switch

* Use bulk operations

* Use zero-sized arrays in toArray

* Add early exits

* Remove redundant addAll

* Fix missing reflection generic types

* More missed language migration aids

* Redundant type arguments

* Redundant type casts

* Fix compilation errors

* Use Arrays.fill

* Fix some missing generic types
  • Loading branch information
eigenraven authored May 2, 2023
1 parent d49fa7a commit 1967607
Show file tree
Hide file tree
Showing 305 changed files with 2,235 additions and 3,220 deletions.
1 change: 1 addition & 0 deletions addon.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ configurations { configs ->
// Keep all dependencies from the main mod in the functional test mod
named(functionalTestSet.compileClasspathConfigurationName).configure {it.extendsFrom(named("compileClasspath").get())}
named(functionalTestSet.runtimeClasspathConfigurationName).configure {it.extendsFrom(named("runtimeClasspath").get())}
named(functionalTestSet.annotationProcessorConfigurationName).configure {it.extendsFrom(named("annotationProcessor").get())}
}

tasks.register(functionalTestSet.jarTaskName, Jar) {
Expand Down
74 changes: 67 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ forgeVersion = 10.13.4.1614
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
developmentEnvironmentUserName = Developer

# Define a source file of your project with:
# 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 = 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 = true

# Generate a class with String fields for the mod id, name, version and group name named with the fields below
generateGradleTokenClass = appeng.core.BuildTags
gradleTokenModId =
gradleTokenModName =
gradleTokenVersion = VERSION
gradleTokenGroupName =
# [DEPRECATED]
# Multiple source files can be defined here by providing a comma-seperated list: Class1.java,Class2.java,Class3.java
# public static final String VERSION = "GRADLETOKEN_VERSION";
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...])
# Leave these properties empty to skip individual token replacements
replaceGradleTokenInFile = AEConfig.java
gradleTokenModId =
gradleTokenModName =
gradleTokenVersion = GRADLETOKEN_VERSION
gradleTokenGroupName =
replaceGradleTokenInFile =

# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
Expand Down Expand Up @@ -58,9 +69,58 @@ containsMixinsAndOrCoreModOnly = false
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
forceEnableMixins = true

# If enabled, you may use 'shadowImplementation' for dependencies. They will be integrated in your jar. It is your

# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
# responsibility check the licence and request permission for distribution, if required.
usesShadowedDependencies = false
# If disabled, won't remove unused classes from shaded dependencies. Some libraries use reflection to access
# their own classes, making the minimization unreliable.
minimizeShadowedDependencies = true
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true

# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories
includeWellKnownRepositories = true

# Publishing to modrinth requires you to set the MODRINTH_TOKEN environment variable to your current modrinth API token.

# The project's ID on Modrinth. Can be either the slug or the ID.
# Leave this empty if you don't want to publish on Modrinth.
modrinthProjectId =

# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
# Syntax: scope1-type1:name1;scope2-type2:name2;...
# Where scope can be one of [required, optional, incompatible, embedded],
# type can be one of [project, version],
# and the name is the Modrinth project or version slug/id of the other mod.
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
modrinthRelations =


# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.

# The project's numeric ID on CurseForge. You can find this in the About Project box.
# Leave this empty if you don't want to publish on CurseForge.
curseForgeProjectId =

# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
# Syntax: type1:name1;type2:name2;...
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
# and the name is the CurseForge project slug of the other mod.
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
curseForgeRelations =


# Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older
# projects. New projects should not use this parameter.
# customArchiveBaseName =

# Optional parameter to prevent the source code from being published
# noPublishedSources =

# Uncomment this to disable spotless checks
# This should only be uncommented to keep it easier to sync with upstream/other forks.
# That is, if there is no other active fork/upstream, NEVER change this.
# disableSpotless = true
17 changes: 6 additions & 11 deletions src/main/java/appeng/api/config/AccessRestriction.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ public AccessRestriction restrictPermissions(final AccessRestriction ar) {
}

private AccessRestriction getPermByBit(final int bit) {
switch (bit) {
default:
case 0:
return NO_ACCESS;
case 1:
return READ;
case 2:
return WRITE;
case 3:
return READ_WRITE;
}
return switch (bit) {
default -> NO_ACCESS;
case 1 -> READ;
case 2 -> WRITE;
case 3 -> READ_WRITE;
};
}

public AccessRestriction addPermissions(final AccessRestriction ar) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/api/config/Upgrades.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum Upgrades {
* @deprecated use {@link Upgrades#getSupported()}
*/
@Deprecated
private final Map<ItemStack, Integer> supportedMax = new HashMap<ItemStack, Integer>();
private final Map<ItemStack, Integer> supportedMax = new HashMap<>();

Upgrades(final int tier) {
this.tier = tier;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/api/storage/MEMonitorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MEMonitorHandler<StackType extends IAEStack> implements IMEMonitor<

private final IMEInventoryHandler<StackType> internalHandler;
private final IItemList<StackType> cachedList;
private final HashMap<IMEMonitorHandlerReceiver<StackType>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<StackType>, Object>();
private final HashMap<IMEMonitorHandlerReceiver<StackType>, Object> listeners = new HashMap<>();

protected boolean hasChanged = true;

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/appeng/block/AEBaseBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature {
private BlockRenderInfo renderInfo;

protected AEBaseBlock(final Material mat) {
this(mat, Optional.<String>absent());
this(mat, Optional.absent());
this.setLightOpacity(255);
this.setLightLevel(0);
this.setHardness(2.2F);
Expand Down Expand Up @@ -115,7 +115,7 @@ public BlockRenderInfo getRendererInstance() {
*/
@SideOnly(Side.CLIENT)
protected BaseBlockRender<? extends AEBaseBlock, ? extends AEBaseTile> getRenderer() {
return new BaseBlockRender<AEBaseBlock, AEBaseTile>();
return new BaseBlockRender<>();
}

IIcon unmappedGetIcon(final IBlockAccess w, final int x, final int y, final int z, final int s) {
Expand Down Expand Up @@ -178,11 +178,11 @@ protected ICustomCollision getCustomCollision(final World w, final int x, final
@SuppressWarnings("unchecked")
// NOTE: WAS FINAL, changed for Immibis
public void addCollisionBoxesToList(final World w, final int x, final int y, final int z, final AxisAlignedBB bb,
final List out, final Entity e) {
final List<AxisAlignedBB> out, final Entity e) {
final ICustomCollision collisionHandler = this.getCustomCollision(w, x, y, z);

if (collisionHandler != null && bb != null) {
final List<AxisAlignedBB> tmp = new ArrayList<AxisAlignedBB>();
final List<AxisAlignedBB> tmp = new ArrayList<>();
collisionHandler.addCollidingBlockToList(w, x, y, z, bb, tmp, e);
for (final AxisAlignedBB b : tmp) {
b.minX += x;
Expand Down Expand Up @@ -331,8 +331,7 @@ public boolean onActivated(final World w, final int x, final int y, final int z,

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public final void getSubBlocks(final Item item, final CreativeTabs tabs, final List itemStacks) {
public final void getSubBlocks(final Item item, final CreativeTabs tabs, final List<ItemStack> itemStacks) {
this.getCheckedSubBlocks(item, tabs, itemStacks);
}

Expand Down
24 changes: 7 additions & 17 deletions src/main/java/appeng/block/AEBaseItemBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public int getMetadata(final int dmg) {

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public final void addInformation(final ItemStack itemStack, final EntityPlayer player, final List toolTip,
public final void addInformation(final ItemStack itemStack, final EntityPlayer player, final List<String> toolTip,
final boolean advancedTooltips) {
this.addCheckedInformation(itemStack, player, toolTip, advancedTooltips);
}
Expand Down Expand Up @@ -106,21 +105,12 @@ public boolean placeBlockAt(final ItemStack stack, final EntityPlayer player, fi

final byte rotation = (byte) (MathHelper.floor_double((player.rotationYaw * 4F) / 360F + 2.5D) & 3);

switch (rotation) {
default:
case 0:
forward = ForgeDirection.SOUTH;
break;
case 1:
forward = ForgeDirection.WEST;
break;
case 2:
forward = ForgeDirection.NORTH;
break;
case 3:
forward = ForgeDirection.EAST;
break;
}
forward = switch (rotation) {
default -> ForgeDirection.SOUTH;
case 1 -> ForgeDirection.WEST;
case 2 -> ForgeDirection.NORTH;
case 3 -> ForgeDirection.EAST;
};

if (player.rotationPitch > 65) {
up = forward.getOpposite();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/block/AEBaseStairBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class AEBaseStairBlock extends BlockStairs implements IAEFeature
protected AEBaseStairBlock(final Block block, final int meta, final EnumSet<AEFeature> features) {
super(block, meta);

this.features = new StairBlockFeatureHandler(features, this, Optional.<String>absent());
this.features = new StairBlockFeatureHandler(features, this, Optional.absent());
this.setBlockName(block.getUnlocalizedName());

this.setLightOpacity(0);
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/appeng/block/AEBaseTileBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public final TileEntity createNewTileEntity(final World var1, final int var2) {
public void breakBlock(final World w, final int x, final int y, final int z, final Block a, final int b) {
final AEBaseTile te = this.getTileEntity(w, x, y, z);
if (te != null) {
final ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
final ArrayList<ItemStack> drops = new ArrayList<>();
if (te.dropItems()) {
te.getDrops(w, x, y, z, drops);
} else {
Expand Down Expand Up @@ -161,8 +161,7 @@ public boolean recolourBlock(final World world, final int x, final int y, final
final int colour) {
final TileEntity te = this.getTileEntity(world, x, y, z);

if (te instanceof IColorableTile) {
final IColorableTile ct = (IColorableTile) te;
if (te instanceof IColorableTile ct) {
final AEColor c = ct.getColor();
final AEColor newColor = AEColor.values()[colour];

Expand Down Expand Up @@ -249,8 +248,7 @@ public boolean onBlockActivated(final World w, final int x, final int y, final i
return false;
}

if (is.getItem() instanceof IMemoryCard && !(this instanceof BlockCableBus)) {
final IMemoryCard memoryCard = (IMemoryCard) is.getItem();
if (is.getItem() instanceof IMemoryCard memoryCard && !(this instanceof BlockCableBus)) {
if (player.isSneaking()) {
final AEBaseTile t = this.getTileEntity(w, x, y, z);
if (t != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,27 @@ public BlockAdvancedCraftingStorage() {

@Override
public IIcon getIcon(final int direction, final int metadata) {
switch (metadata & (~4)) {
default:
return super.getIcon(0, -1);
case 0:
return ExtraBlockTextures.BlockCraftingStorage256k.getIcon();
case 1:
return ExtraBlockTextures.BlockCraftingStorage1024k.getIcon();
case 2:
return ExtraBlockTextures.BlockCraftingStorage4096k.getIcon();
case 3:
return ExtraBlockTextures.BlockCraftingStorage16384k.getIcon();

case FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingStorage256kFit.getIcon();
case 1 | FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingStorage1024kFit.getIcon();
case 2 | FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingStorage4096kFit.getIcon();
case 3 | FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingStorage16384kFit.getIcon();
}
return switch (metadata & (~4)) {
default -> super.getIcon(0, -1);
case 0 -> ExtraBlockTextures.BlockCraftingStorage256k.getIcon();
case 1 -> ExtraBlockTextures.BlockCraftingStorage1024k.getIcon();
case 2 -> ExtraBlockTextures.BlockCraftingStorage4096k.getIcon();
case 3 -> ExtraBlockTextures.BlockCraftingStorage16384k.getIcon();
case FLAG_FORMED -> ExtraBlockTextures.BlockCraftingStorage256kFit.getIcon();
case 1 | FLAG_FORMED -> ExtraBlockTextures.BlockCraftingStorage1024kFit.getIcon();
case 2 | FLAG_FORMED -> ExtraBlockTextures.BlockCraftingStorage4096kFit.getIcon();
case 3 | FLAG_FORMED -> ExtraBlockTextures.BlockCraftingStorage16384kFit.getIcon();
};
}

@Override
public String getUnlocalizedName(final ItemStack is) {
switch (is.getItemDamage()) {
case 0:
return "tile.appliedenergistics2.BlockCraftingStorage256k";
case 1:
return "tile.appliedenergistics2.BlockCraftingStorage1024k";
case 2:
return "tile.appliedenergistics2.BlockCraftingStorage4096k";
case 3:
return "tile.appliedenergistics2.BlockCraftingStorage16384k";
default:
return this.getItemUnlocalizedName(is);
}
return switch (is.getItemDamage()) {
case 0 -> "tile.appliedenergistics2.BlockCraftingStorage256k";
case 1 -> "tile.appliedenergistics2.BlockCraftingStorage1024k";
case 2 -> "tile.appliedenergistics2.BlockCraftingStorage4096k";
case 3 -> "tile.appliedenergistics2.BlockCraftingStorage16384k";
default -> this.getItemUnlocalizedName(is);
};
}
}
29 changes: 10 additions & 19 deletions src/main/java/appeng/block/crafting/BlockAdvancedCraftingUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@ public class BlockAdvancedCraftingUnit extends BlockCraftingUnit {

@Override
public IIcon getIcon(final int direction, final int metadata) {
switch (metadata) {
default:
case 0:
return ExtraBlockTextures.BlockCraftingAccelerator64x.getIcon();
case FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingAccelerator64xFit.getIcon();
case 1:
return ExtraBlockTextures.BlockCraftingAccelerator256x.getIcon();
case 1 | FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingAccelerator256xFit.getIcon();
case 2:
return ExtraBlockTextures.BlockCraftingAccelerator1024x.getIcon();
case 2 | FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingAccelerator1024xFit.getIcon();
case 3:
return ExtraBlockTextures.BlockCraftingAccelerator4096x.getIcon();
case 3 | FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingAccelerator4096xFit.getIcon();
}
return switch (metadata) {
default -> ExtraBlockTextures.BlockCraftingAccelerator64x.getIcon();
case FLAG_FORMED -> ExtraBlockTextures.BlockCraftingAccelerator64xFit.getIcon();
case 1 -> ExtraBlockTextures.BlockCraftingAccelerator256x.getIcon();
case 1 | FLAG_FORMED -> ExtraBlockTextures.BlockCraftingAccelerator256xFit.getIcon();
case 2 -> ExtraBlockTextures.BlockCraftingAccelerator1024x.getIcon();
case 2 | FLAG_FORMED -> ExtraBlockTextures.BlockCraftingAccelerator1024xFit.getIcon();
case 3 -> ExtraBlockTextures.BlockCraftingAccelerator4096x.getIcon();
case 3 | FLAG_FORMED -> ExtraBlockTextures.BlockCraftingAccelerator4096xFit.getIcon();
};
}

@Override
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/appeng/block/crafting/BlockCraftingMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ public IIcon getIcon(final int direction, final int metadata) {
}
}

switch (metadata) {
default:
case 0:
return super.getIcon(0, 0);
case FLAG_FORMED:
return ExtraBlockTextures.BlockCraftingMonitorFit_Light.getIcon();
}
return switch (metadata) {
default -> super.getIcon(0, 0);
case FLAG_FORMED -> ExtraBlockTextures.BlockCraftingMonitorFit_Light.getIcon();
};
}

@Override
Expand Down
Loading

0 comments on commit 1967607

Please sign in to comment.