Skip to content

Commit

Permalink
cleanup: generics injection + jabel
Browse files Browse the repository at this point in the history
  • Loading branch information
mist475 committed Aug 19, 2023
1 parent 67597b5 commit a586462
Show file tree
Hide file tree
Showing 96 changed files with 460 additions and 592 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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
generateGradleTokenClass =
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/blockartistry/mod/DynSurround/ModOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,43 +356,43 @@ public static void load(final Configuration config) {
config.setCategoryRequiresMcRestart(CATEGORY_LOGGING_CONTROL, false);
config.setCategoryRequiresWorldRestart(CATEGORY_LOGGING_CONTROL, false);
config.setCategoryComment(CATEGORY_LOGGING_CONTROL, "Defines how Dynamic Surroundings logging will behave");
config.setCategoryPropertyOrder(CATEGORY_LOGGING_CONTROL, new ArrayList<String>(loggingSort));
config.setCategoryPropertyOrder(CATEGORY_LOGGING_CONTROL, new ArrayList<>(loggingSort));

// CATEGORY: Rain
config.setCategoryRequiresMcRestart(CATEGORY_RAIN, false);
config.setCategoryRequiresWorldRestart(CATEGORY_RAIN, false);
config.setCategoryComment(CATEGORY_RAIN, "Options that control rain effects in the client");
config.setCategoryPropertyOrder(CATEGORY_RAIN, new ArrayList<String>(rainSort));
config.setCategoryPropertyOrder(CATEGORY_RAIN, new ArrayList<>(rainSort));

// CATEGORY: General
config.setCategoryRequiresMcRestart(CATEGORY_GENERAL, false);
config.setCategoryRequiresWorldRestart(CATEGORY_GENERAL, false);
config.setCategoryComment(CATEGORY_GENERAL, "Miscellaneous settings");
config.setCategoryPropertyOrder(CATEGORY_GENERAL, new ArrayList<String>(generalSort));
config.setCategoryPropertyOrder(CATEGORY_GENERAL, new ArrayList<>(generalSort));

// CATEGORY: Player
config.setCategoryRequiresMcRestart(CATEGORY_PLAYER, false);
config.setCategoryRequiresWorldRestart(CATEGORY_PLAYER, false);
config.setCategoryComment(CATEGORY_PLAYER, "General options for defining sound and effects the player entity");
config.setCategoryPropertyOrder(CATEGORY_PLAYER, new ArrayList<String>(playerSort));
config.setCategoryPropertyOrder(CATEGORY_PLAYER, new ArrayList<>(playerSort));

// CATEGORY: Aurora
config.setCategoryRequiresMcRestart(CATEGORY_AURORA, false);
config.setCategoryRequiresWorldRestart(CATEGORY_AURORA, false);
config.setCategoryComment(CATEGORY_AURORA, "Options that control Aurora behavior and rendering");
config.setCategoryPropertyOrder(CATEGORY_AURORA, new ArrayList<String>(auroraSort));
config.setCategoryPropertyOrder(CATEGORY_AURORA, new ArrayList<>(auroraSort));

// CATEGORY: Fog
config.setCategoryRequiresMcRestart(CATEGORY_FOG, false);
config.setCategoryRequiresWorldRestart(CATEGORY_FOG, false);
config.setCategoryComment(CATEGORY_FOG, "Options that control the various fog effects in the client");
config.setCategoryPropertyOrder(CATEGORY_FOG, new ArrayList<String>(fogSort));
config.setCategoryPropertyOrder(CATEGORY_FOG, new ArrayList<>(fogSort));

// CATEGORY: Biomes
config.setCategoryRequiresMcRestart(CATEGORY_BIOMES, false);
config.setCategoryRequiresWorldRestart(CATEGORY_BIOMES, false);
config.setCategoryComment(CATEGORY_BIOMES, "Options for controlling biome sound/effects");
config.setCategoryPropertyOrder(CATEGORY_BIOMES, new ArrayList<String>(biomesSort));
config.setCategoryPropertyOrder(CATEGORY_BIOMES, new ArrayList<>(biomesSort));

// CATEGORY: Dimensions
config.setCategoryRequiresMcRestart(CATEGORY_DIMENSIONS, false);
Expand All @@ -409,13 +409,13 @@ public static void load(final Configuration config) {
config.setCategoryRequiresMcRestart(CATEGORY_SOUND, false);
config.setCategoryRequiresWorldRestart(CATEGORY_SOUND, false);
config.setCategoryComment(CATEGORY_SOUND, "General options for defining sound effects");
config.setCategoryPropertyOrder(CATEGORY_SOUND, new ArrayList<String>(soundsSort));
config.setCategoryPropertyOrder(CATEGORY_SOUND, new ArrayList<>(soundsSort));

// CATEGORY: player.potion hud
config.setCategoryRequiresMcRestart(CATEGORY_POTION_HUD, false);
config.setCategoryRequiresWorldRestart(CATEGORY_POTION_HUD, false);
config.setCategoryComment(CATEGORY_POTION_HUD, "Options for the Potion HUD overlay");
config.setCategoryPropertyOrder(CATEGORY_POTION_HUD, new ArrayList<String>(potionHudSort));
config.setCategoryPropertyOrder(CATEGORY_POTION_HUD, new ArrayList<>(potionHudSort));

// Iterate through the config list looking for properties without
// comments. These will
Expand All @@ -425,7 +425,7 @@ public static void load(final Configuration config) {
}

private static void scrubCategory(final ConfigCategory category) {
final List<String> killList = new ArrayList<String>();
final List<String> killList = new ArrayList<>();
for (final Entry<String, Property> entry : category.entrySet())
if (StringUtils.isEmpty(entry.getValue().comment))
killList.add(entry.getKey());
Expand Down
32 changes: 12 additions & 20 deletions src/main/java/org/blockartistry/mod/DynSurround/VersionCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class VersionCheck implements Runnable {
private static final int VERSION_CHECK_RETRIES = 3;
private static final int VERSION_CHECK_INTERVAL = 10000;

public static enum UpdateStatus {
public enum UpdateStatus {
UNKNOWN, CURRENT, OUTDATED, COMM_ERROR
}

Expand Down Expand Up @@ -230,24 +230,16 @@ public void run() {
e.printStackTrace();
}

switch (status) {
case COMM_ERROR:
ModLog.warn("Version check failed");
break;
case CURRENT:
ModLog.info("Dynamic Surroundings version [%s] is the same or newer than the current version [%s]",
modVersion, currentVersion);
break;
case OUTDATED:
ModLog.warn("Using outdated version [" + modVersion + "] for Minecraft " + mcVersion
+ ". Consider updating to " + currentVersion + ".");
break;
case UNKNOWN:
ModLog.warn("Unknown version check status!");
break;
default:
break;

}
switch (status) {
case COMM_ERROR -> ModLog.warn("Version check failed");
case CURRENT ->
ModLog.info("Dynamic Surroundings version [%s] is the same or newer than the current version [%s]",
modVersion, currentVersion);
case OUTDATED -> ModLog.warn("Using outdated version [" + modVersion + "] for Minecraft " + mcVersion
+ ". Consider updating to " + currentVersion + ".");
case UNKNOWN -> ModLog.warn("Unknown version check status!");
default -> {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public boolean transmorgrify(final ClassNode cn) {

boolean failed = false;

final String names1[] = { "func_78484_h", "addRainParticles" };
final String[] names1 = { "func_78484_h", "addRainParticles" };
final String sigs1 = "()V";

final String names2[] = { "func_78474_d", "renderRainSnow" };
final String[] names2 = { "func_78474_d", "renderRainSnow" };
final String sigs2 = "(F)V";

MethodNode m = findMethod(cn, sigs1, names1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String name() {

@Override
public boolean transmorgrify(final ClassNode cn) {
final String names[] = { "getURLForSoundResource", "func_148612_a" };
final String[] names = { "getURLForSoundResource", "func_148612_a" };
final String sig = "(Lnet/minecraft/util/ResourceLocation;)Ljava/net/URL;";

final MethodNode m = findMethod(cn, sig, names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String name() {

@Override
public boolean transmorgrify(final ClassNode cn) {
final String names[] = { "getNormalizedPitch", "func_148606_a" };
final String[] names = { "getNormalizedPitch", "func_148606_a" };
final String sig = "(Lnet/minecraft/client/audio/ISound;Lnet/minecraft/client/audio/SoundPoolEntry;)F";

final MethodNode m = findMethod(cn, sig, names);
Expand All @@ -55,14 +55,14 @@ public boolean transmorgrify(final ClassNode cn) {

final String owner = "org/blockartistry/mod/DynSurround/client/sound/SoundManager";
final String targetName = "getNormalizedPitch";

final InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 1));
list.add(new VarInsnNode(ALOAD, 2));
list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, targetName, sig, false));
list.add(new InsnNode(Opcodes.FRETURN));
m.instructions = list;

return true;
} else {
Transformer.log().error("Unable to locate method {}{}", names[0], sig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String name() {

@Override
public boolean transmorgrify(final ClassNode cn) {
final String names[] = { "getNormalizedVolume", "func_148594_a" };
final String[] names = { "getNormalizedVolume", "func_148594_a" };
final String sig = "(Lnet/minecraft/client/audio/ISound;Lnet/minecraft/client/audio/SoundPoolEntry;Lnet/minecraft/client/audio/SoundCategory;)F";

final MethodNode m = findMethod(cn, sig, names);
Expand All @@ -55,15 +55,15 @@ public boolean transmorgrify(final ClassNode cn) {

final String owner = "org/blockartistry/mod/DynSurround/client/sound/SoundManager";
final String targetName = "getNormalizedVolume";

final InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 1));
list.add(new VarInsnNode(ALOAD, 2));
list.add(new VarInsnNode(ALOAD, 3));
list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, targetName, sig, false));
list.add(new InsnNode(Opcodes.FRETURN));
m.instructions = list;

return true;
} else {
Transformer.log().error("Unable to locate method {}{}", names[0], sig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String name() {

@Override
public boolean transmorgrify(final ClassNode cn) {
final String names[] = { "playSound", "func_148611_c" };
final String[] names = { "playSound", "func_148611_c" };
final String sig = "(Lnet/minecraft/client/audio/ISound;)V";

final MethodNode m = findMethod(cn, sig, names);
Expand All @@ -51,9 +51,8 @@ public boolean transmorgrify(final ClassNode cn) {

for (int i = 0; i < m.instructions.size(); i++) {
final AbstractInsnNode node = m.instructions.get(i);
if (node instanceof IntInsnNode) {
final IntInsnNode intNode = (IntInsnNode) node;
if (intNode.operand == 20) {
if (node instanceof IntInsnNode intNode) {
if (intNode.operand == 20) {
m.instructions.set(node, new IntInsnNode(Opcodes.BIPUSH, 0));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean isEnabled() {
@Override
public boolean transmorgrify(final ClassNode cn) {

final String names[] = { "func_73051_P", "resetRainAndThunder" };
final String[] names = { "func_73051_P", "resetRainAndThunder" };
final String sigs = "()V";

final MethodNode m = findMethod(cn, sigs, names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String name() {

@Override
public boolean transmorgrify(final ClassNode cn) {
final String names[] = { "playSound", "func_148611_c" };
final String[] names = { "playSound", "func_148611_c" };
final String sig = "(Lnet/minecraft/client/audio/ISound;)V";

final MethodNode m = findMethod(cn, sig, names);
Expand All @@ -65,9 +65,8 @@ public boolean transmorgrify(final ClassNode cn) {

for (final Iterator<?> iterator = m.instructions.iterator(); iterator.hasNext();) {
final AbstractInsnNode insn = (AbstractInsnNode) iterator.next();
if (insn instanceof MethodInsnNode) {
final MethodInsnNode mn = (MethodInsnNode) insn;
if (mn.owner.equals("net/minecraft/client/audio/SoundManager$SoundSystemStarterThread")
if (insn instanceof MethodInsnNode mn) {
if (mn.owner.equals("net/minecraft/client/audio/SoundManager$SoundSystemStarterThread")
&& mn.name.equals("play")) {
m.instructions.insert(insn, list);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ protected MethodNode findMethod(@Nonnull final ClassNode cn, @Nonnull final Stri
@Nullable
protected MethodNode findMethod(@Nonnull final ClassNode cn, @Nonnull final String signature,
@Nonnull final String... names) {
for (int i = 0; i < names.length; i++) {
final MethodNode m = findMethod(cn, signature, names[i]);
if (m != null)
return m;
}
for (String name : names) {
final MethodNode m = findMethod(cn, signature, name);
if (m != null)
return m;
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class AuroraEffectHandler implements IClientEffectHandler {

// Aurora information
private static int auroraDimension = 0;
private static final Set<AuroraData> auroras = new HashSet<AuroraData>();
private static final Set<AuroraData> auroras = new HashSet<>();
public static Aurora currentAurora;

public static void addAurora(final AuroraData data) {
Expand Down Expand Up @@ -98,7 +98,7 @@ private Aurora getClosestAurora(final World world) {
if (ad == null) {
currentAurora = null;
} else if (currentAurora == null || (currentAurora.posX != ad.posX && currentAurora.posZ != ad.posZ)) {
ModLog.debug("New aurora: " + ad.toString());
ModLog.debug("New aurora: " + ad);
currentAurora = new Aurora(ad);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class BiomeSurveyHandler implements IClientEffectHandler {
private static final int BIOME_SURVEY_RANGE = 6;

private static int area;
private static final TObjectIntHashMap<BiomeGenBase> weights = new TObjectIntHashMap<BiomeGenBase>();
private static final TObjectIntHashMap<BiomeGenBase> weights = new TObjectIntHashMap<>();

private static BiomeGenBase lastPlayerBiome = null;
private static int lastDimension = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@SideOnly(Side.CLIENT)
public class ClientEffectHandler {

private static final List<IClientEffectHandler> effectHandlers = new ArrayList<IClientEffectHandler>();
private static final List<IClientEffectHandler> effectHandlers = new ArrayList<>();

public static void register(final IClientEffectHandler handler) {
effectHandlers.add(handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,13 @@ public void onLivingHurt(final LivingHurtEvent event) {
boolean isCrit = false;
if (event.source instanceof EntityDamageSourceIndirect) {
final EntityDamageSourceIndirect dmgSource = (EntityDamageSourceIndirect) event.source;
if (dmgSource.getSourceOfDamage() instanceof EntityArrow) {
final EntityArrow arrow = (EntityArrow) dmgSource.getSourceOfDamage();
isCrit = arrow.getIsCritical();
if (dmgSource.getSourceOfDamage() instanceof EntityArrow arrow) {
isCrit = arrow.getIsCritical();
}
} else if (event.source instanceof EntityDamageSource) {
final EntityDamageSource dmgSource = (EntityDamageSource) event.source;
if (dmgSource.getSourceOfDamage() instanceof EntityPlayer) {
final EntityPlayer player = (EntityPlayer) dmgSource.getSourceOfDamage();
isCrit = isCritical(player, event.entityLiving);
if (dmgSource.getSourceOfDamage() instanceof EntityPlayer player) {
isCrit = isCritical(player, event.entityLiving);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static String getBiomeName() {
public static DimensionRegistry getDimensionInfo() {
return dimensionInfo;
}

public static int getDimensionId() {
return dimensionId;
}
Expand All @@ -254,9 +254,8 @@ public static EntityPlayer getPlayer() {
}

public static boolean isPlayer(final Entity entity) {
if (entity instanceof EntityPlayer) {
final EntityPlayer ep = (EntityPlayer) entity;
return ep.getUniqueID().equals(getPlayer().getUniqueID());
if (entity instanceof EntityPlayer ep) {
return ep.getUniqueID().equals(getPlayer().getUniqueID());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ public void fogColorEvent(final EntityViewRenderEvent.FogColors event) {
final Material material = event.block.getMaterial();
if (material != Material.lava && material != Material.water) {
final Color color = this.fogColor.calculate(event);
if (color != null) {
event.red = color.red;
event.green = color.green;
event.blue = color.blue;
}
}
event.red = color.red;
event.green = color.green;
event.blue = color.blue;
}
}
}

Expand All @@ -96,11 +94,9 @@ public void fogRenderEvent(final EntityViewRenderEvent.RenderFogEvent event) {
final Material material = event.block.getMaterial();
if (material != Material.lava && material != Material.water) {
final FogResult result = this.fogRange.calculate(event);
if (result != null) {
GL11.glFogf(GL11.GL_FOG_START, result.getStart());
GL11.glFogf(GL11.GL_FOG_END, result.getEnd());
}
}
GL11.glFogf(GL11.GL_FOG_START, result.getStart());
GL11.glFogf(GL11.GL_FOG_END, result.getEnd());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
@SideOnly(Side.CLIENT)
public interface IAtmosRenderer {

public void render(final EntityRenderer renderer, final float partialTicks);
void render(final EntityRenderer renderer, final float partialTicks);

}
Loading

0 comments on commit a586462

Please sign in to comment.