Skip to content

Commit

Permalink
Jabel, Generic injection and automatic code cleanup (#21)
Browse files Browse the repository at this point in the history
* Enable jabel&generic injection, fix generic injection errors

* Enhanced for loops

* Add missing generics part 1

* Add missing generics part 2: getSubBlocks

* Add missing generics part 3: structure components

* Add missing generics part 4: addInformation

* MapGenTFHollowTree cleanup

* Replace an unreadable do-while loop with a stream filter-find

* Fix unnecessary boxing

* Fix unnecessary unboxing

* While->Enhanced for loop

* Use diamond operator where appropriate

* Collapse identical catch blocks

* String switch

* Use enhanced switch

* Fix compilation error after added generics

* Use instanceof pattern matching

* More missed generic parameters

* Use Java-style array declarations

* Unnecessary String conversions

* Unnecessary modifiers

* Unnecessary semicolons

* Unchecked warnings fixes

* Explicit array filling

* Manual min/max calculations

* Redundant vararg array creation

* Redundant type casts

* Unnecessary StringBuilder

* Remove redundant suppressions

* Apply spotless

* Fix ambiguous method call error

* Update baubles to fix runObfClient
  • Loading branch information
eigenraven authored Apr 1, 2023
1 parent 899666b commit d3d3e2a
Show file tree
Hide file tree
Showing 307 changed files with 3,027 additions and 4,041 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
dependencies {
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {transitive = false}

runtimeOnly("com.github.GTNewHorizons:Baubles:1.0.1.14:dev")
runtimeOnly("com.github.GTNewHorizons:Baubles:1.0.1.16:dev")
}
23 changes: 17 additions & 6 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 = twilightforest.Tags
gradleTokenModId = MODID
gradleTokenModName = MODNAME
gradleTokenVersion = VERSION
gradleTokenGroupName = GROUPNAME
# [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 = TwilightForestMod.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
21 changes: 10 additions & 11 deletions src/main/java/twilightforest/CommandTFFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ public void processCommand(ICommandSender sender, String[] args) {
int dz = MathHelper.floor_double(player.posZ);

if (!(player.worldObj.provider instanceof WorldProviderTwilightForest)) {
throw new WrongUsageException("commands.tffeature.not_in_twilight_forest", new Object[0]);
throw new WrongUsageException("commands.tffeature.not_in_twilight_forest");
} else {
// nearest feature
TFFeature nearbyFeature = ((TFWorldChunkManager) player.worldObj.provider.worldChunkMgr)
.getFeatureAt(dx, dz, player.worldObj);

sender.addChatMessage(
new ChatComponentTranslation(
"The nearest feature is %s",
new Object[] { nearbyFeature.name }));
new ChatComponentTranslation("The nearest feature is %s", nearbyFeature.name));

// are you in a structure?
ChunkProviderTwilightForest chunkProvider = ((WorldProviderTwilightForest) player.worldObj.provider)
Expand All @@ -59,7 +57,7 @@ public void processCommand(ICommandSender sender, String[] args) {
sender.addChatMessage(
new ChatComponentTranslation(
"Structure conquer flag = %s.",
new Object[] { chunkProvider.isStructureConquered(dx, dy, dz) }));
chunkProvider.isStructureConquered(dx, dy, dz)));

// are you in a room?

Expand Down Expand Up @@ -92,14 +90,14 @@ public void processCommand(ICommandSender sender, String[] args) {
TFWorldChunkManager wcm = (TFWorldChunkManager) player.worldObj.provider.worldChunkMgr;

boolean fc = wcm.isInFeatureChunk(player.worldObj, dx, dz);
sender.addChatMessage(new ChatComponentTranslation("Center of feature = %s.", new Object[] { cc }));
sender.addChatMessage(new ChatComponentTranslation("Are in feature chunk = %s.", new Object[] { fc }));
sender.addChatMessage(new ChatComponentTranslation("Center of feature = %s.", cc));
sender.addChatMessage(new ChatComponentTranslation("Are in feature chunk = %s.", fc));
} else {
throw new WrongUsageException("commands.tffeature.usage", new Object[0]);
throw new WrongUsageException("commands.tffeature.usage");
}

} else {
throw new WrongUsageException("commands.tffeature.usage", new Object[0]);
throw new WrongUsageException("commands.tffeature.usage");
}
}

Expand All @@ -112,7 +110,7 @@ private void changeStructureActivity(ICommandSender sender, boolean flag) throws
int dz = MathHelper.floor_double(player.posZ);

if (!(player.worldObj.provider instanceof WorldProviderTwilightForest)) {
throw new WrongUsageException("commands.tffeature.not_in_twilight_forest", new Object[0]);
throw new WrongUsageException("commands.tffeature.not_in_twilight_forest");
} else {
// are you in a structure?
ChunkProviderTwilightForest chunkProvider = ((WorldProviderTwilightForest) player.worldObj.provider)
Expand All @@ -122,7 +120,8 @@ private void changeStructureActivity(ICommandSender sender, boolean flag) throws
sender.addChatMessage(
new ChatComponentTranslation(
"Structure conquer flag was %s. Changing to %s.",
new Object[] { chunkProvider.isStructureConquered(dx, dy, dz), flag }));
chunkProvider.isStructureConquered(dx, dy, dz),
flag));

chunkProvider.setStructureConquered(dx, dy, dz, flag);
} else {
Expand Down
50 changes: 19 additions & 31 deletions src/main/java/twilightforest/CommandTFProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int getRequiredPermissionLevel() {
@Override
public void processCommand(ICommandSender sender, String[] args) {
if (args.length < 2) {
throw new WrongUsageException("tfprogress <player> <boss>", new Object[0]);
throw new WrongUsageException("tfprogress <player> <boss>");
} else {
EntityPlayerMP player = getPlayer(sender, args[0]);
int bossIndex = getBossIndex(args[1]);
Expand All @@ -42,7 +42,8 @@ public void processCommand(ICommandSender sender, String[] args) {
sender,
this,
"Setting player %s progress to past boss %s.",
new Object[] { player.getCommandSenderName(), bosses[bossIndex] });
player.getCommandSenderName(),
bosses[bossIndex]);

setProgress(player, bossIndex);
}
Expand All @@ -59,47 +60,34 @@ private void setProgress(EntityPlayerMP player, int bossIndex) {

// give achievements
switch (bossIndex) {
case 0:
default:
break;
case 1:
case 1 -> {
player.triggerAchievement(TFAchievementPage.twilightPortal);
player.triggerAchievement(TFAchievementPage.twilightArrival);
player.triggerAchievement(TFAchievementPage.twilightHunter);
player.triggerAchievement(TFAchievementPage.twilightKillNaga);
player.triggerAchievement(TFAchievementPage.twilightProgressNaga);
break;
case 2:
}
case 2 -> {
player.triggerAchievement(TFAchievementPage.twilightKillLich);
player.triggerAchievement(TFAchievementPage.twilightProgressLich);
break;
case 3:
player.triggerAchievement(TFAchievementPage.twilightProgressLabyrinth);
break;
case 4:
}
case 3 -> player.triggerAchievement(TFAchievementPage.twilightProgressLabyrinth);
case 4 -> {
player.triggerAchievement(TFAchievementPage.twilightKillHydra);
player.triggerAchievement(TFAchievementPage.twilightProgressHydra);
break;
case 5:
}
case 5 -> {
player.triggerAchievement(TFAchievementPage.twilightProgressTrophyPedestal);
player.triggerAchievement(TFAchievementPage.twilightProgressKnights);
break;
case 6:
player.triggerAchievement(TFAchievementPage.twilightProgressUrghast);
break;
case 7:
player.triggerAchievement(TFAchievementPage.twilightProgressYeti);
break;
case 8:
player.triggerAchievement(TFAchievementPage.twilightProgressGlacier);
break;
case 9:
player.triggerAchievement(TFAchievementPage.twilightProgressTroll);
break;
case 10:
}
case 6 -> player.triggerAchievement(TFAchievementPage.twilightProgressUrghast);
case 7 -> player.triggerAchievement(TFAchievementPage.twilightProgressYeti);
case 8 -> player.triggerAchievement(TFAchievementPage.twilightProgressGlacier);
case 9 -> player.triggerAchievement(TFAchievementPage.twilightProgressTroll);
case 10 -> {
player.triggerAchievement(TFAchievementPage.twilightProgressThorns);
player.triggerAchievement(TFAchievementPage.twilightProgressCastle);
break;
}
}
}

Expand All @@ -116,7 +104,7 @@ private int getBossIndex(String string) {
/**
* Adds the strings available in this command to the given list of tab completion options.
*/
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {
return args.length == 1 ? getListOfStringsMatchingLastWord(args, this.getListOfPlayers())
: (args.length == 2 ? getListOfStringsMatchingLastWord(args, bosses) : null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/twilightforest/TFAchievementPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TFAchievementPage extends net.minecraftforge.common.AchievementPage
-2,
1,
TFBlocks.portal,
(Achievement) null)).setSpecial().registerStat();
null)).setSpecial().registerStat();
public static Achievement twilightArrival = (new Achievement(
TwilightForestMod.ID + 2,
"twilightArrival",
Expand Down
34 changes: 11 additions & 23 deletions src/main/java/twilightforest/TFEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
*/
public class TFEventListener {

protected HashMap<String, InventoryPlayer> playerKeepsMap = new HashMap<String, InventoryPlayer>();
protected HashMap<String, InventoryPlayer> playerKeepsMap = new HashMap<>();
private boolean isBreakingWithGiantPick = false;
private boolean shouldMakeGiantCobble = false;
private int amountOfCobbleToReplace = 0;
Expand All @@ -93,21 +93,11 @@ public void pickupItem(EntityItemPickupEvent event) {
// trophy gives kill achievement
} else if (item == TFItems.trophy) {
switch (event.item.getEntityItem().getItemDamage()) {
case 0:
event.entityPlayer.triggerAchievement(TFAchievementPage.twilightKillHydra);
break;
case 1:
event.entityPlayer.triggerAchievement(TFAchievementPage.twilightKillNaga);
break;
case 2:
event.entityPlayer.triggerAchievement(TFAchievementPage.twilightKillLich);
break;
case 3:
event.entityPlayer.triggerAchievement(TFAchievementPage.twilightProgressUrghast);
break;
case 4:
event.entityPlayer.triggerAchievement(TFAchievementPage.twilightProgressGlacier);
break;
case 0 -> event.entityPlayer.triggerAchievement(TFAchievementPage.twilightKillHydra);
case 1 -> event.entityPlayer.triggerAchievement(TFAchievementPage.twilightKillNaga);
case 2 -> event.entityPlayer.triggerAchievement(TFAchievementPage.twilightKillLich);
case 3 -> event.entityPlayer.triggerAchievement(TFAchievementPage.twilightProgressUrghast);
case 4 -> event.entityPlayer.triggerAchievement(TFAchievementPage.twilightProgressGlacier);
}
// mazebreaker
} else if (item == TFItems.mazebreakerPick) {
Expand Down Expand Up @@ -258,8 +248,8 @@ public void harvestDrops(HarvestDropsEvent event) {
if (event.harvester != null && event.harvester.inventory.getCurrentItem() != null
&& event.harvester.inventory.getCurrentItem().getItem().func_150897_b(event.block)) {
if (event.harvester.inventory.getCurrentItem().getItem() == TFItems.fieryPick) {
ArrayList<ItemStack> removeThese = new ArrayList<ItemStack>(1);
ArrayList<ItemStack> addThese = new ArrayList<ItemStack>(1);
ArrayList<ItemStack> removeThese = new ArrayList<>(1);
ArrayList<ItemStack> addThese = new ArrayList<>(1);

for (ItemStack input : event.drops) {
// does it smelt?
Expand Down Expand Up @@ -496,9 +486,8 @@ public void bonemealUsed(BonemealEvent event) {
*/
@SubscribeEvent
public void livingDies(LivingDeathEvent event) {
if (event.entityLiving instanceof EntityPlayer
if (event.entityLiving instanceof EntityPlayer player
&& !event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
EntityPlayer player = (EntityPlayer) event.entityLiving;

// TODO: Add support for keeping Bauble slot items on all tiers
if (player.inventory.consumeInventoryItem(TFItems.charmOfKeeping3)) {
Expand Down Expand Up @@ -749,8 +738,7 @@ && isBlockProtectedFromBreaking(event.world, event.x, event.y, event.z)) {
&& blockThere == event.block
&& metaThere == event.blockMetadata) {
// try to break that block too!
if (event.getPlayer() instanceof EntityPlayerMP) {
EntityPlayerMP playerMP = (EntityPlayerMP) event.getPlayer();
if (event.getPlayer() instanceof EntityPlayerMP playerMP) {

playerMP.theItemInWorldManager.tryHarvestBlock(bx + dx, by + dy, bz + dz);
}
Expand Down Expand Up @@ -999,7 +987,7 @@ public void worldLoaded(WorldEvent.Load event) {
public void commandSent(CommandEvent event) {
if (event.command instanceof CommandGameRule && event.parameters.length > 1
&& TwilightForestMod.ENFORCED_PROGRESSION_RULE.equals(event.parameters[0])) {
boolean isEnforced = Boolean.valueOf(event.parameters[1]);
boolean isEnforced = Boolean.parseBoolean(event.parameters[1]);
TwilightForestMod.genericChannel
.sendToAll(TFGenericPacketHandler.makeEnforcedProgressionStatusPacket(isEnforced));
}
Expand Down
Loading

0 comments on commit d3d3e2a

Please sign in to comment.