From 531e33765e84057b0eb6310d9adf5499b3058572 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Wed, 8 Feb 2023 21:11:39 +0100 Subject: [PATCH] cache some Loader.isModLoaded calls (#72) --- src/main/java/tconstruct/armor/ArmorProxyClient.java | 10 +++++----- src/main/java/tconstruct/client/ArmorControls.java | 6 ++++-- .../java/tconstruct/weaponry/weapons/Crossbow.java | 6 +----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/tconstruct/armor/ArmorProxyClient.java b/src/main/java/tconstruct/armor/ArmorProxyClient.java index 9f72e7de..5cfb88d2 100644 --- a/src/main/java/tconstruct/armor/ArmorProxyClient.java +++ b/src/main/java/tconstruct/armor/ArmorProxyClient.java @@ -8,7 +8,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.IAttributeInstance; @@ -66,6 +65,9 @@ public class ArmorProxyClient extends ArmorProxyCommon { public static KnapsackInventory knapsack = new KnapsackInventory(); public static ArmorExtended armorExtended = new ArmorExtended(); + private final boolean isRpghudLoaded = Loader.isModLoaded("rpghud"); + private final boolean isTukmc_vzLoaded = Loader.isModLoaded("tukmc_Vz"); + private final boolean isBorderlandsModLoaded = Loader.isModLoaded("borderlands"); @Override public void preInit() { @@ -236,8 +238,6 @@ public class ArmorProxyClient extends ArmorProxyCommon { Random rand = new Random(); int updateCounter = 0; - GameSettings gs = Minecraft.getMinecraft().gameSettings; - @SubscribeEvent public void goggleZoom(FOVUpdateEvent event) { if (ArmorControls.zoom) { @@ -259,11 +259,11 @@ public class ArmorProxyClient extends ArmorProxyCommon { } // uses different display, displays health correctly by itself. - if (Loader.isModLoaded("rpghud")) { + if (isRpghudLoaded) { return; } - if (Loader.isModLoaded("tukmc_Vz") && !Loader.isModLoaded("borderlands")) { + if (isTukmc_vzLoaded && !isBorderlandsModLoaded) { // Loader check to avoid conflicting // with a GUI mod (thanks Vazkii!) return; diff --git a/src/main/java/tconstruct/client/ArmorControls.java b/src/main/java/tconstruct/client/ArmorControls.java index ee1dd8f2..b2d54d18 100644 --- a/src/main/java/tconstruct/client/ArmorControls.java +++ b/src/main/java/tconstruct/client/ArmorControls.java @@ -51,6 +51,7 @@ public class ArmorControls { // boolean onStilts = false; private final KeyBinding[] keys; + private boolean isNotEnoughKeysLoaded; public ArmorControls() { getVanillaKeyBindings(); @@ -64,7 +65,8 @@ public class ArmorControls { ClientRegistry.registerKeyBinding(key); } } - if (Loader.isModLoaded("notenoughkeys")) { + isNotEnoughKeysLoaded = Loader.isModLoaded("notenoughkeys"); + if (isNotEnoughKeysLoaded) { Api.registerMod(TConstruct.modID, keyDescs); } // Add mc keys @@ -80,7 +82,7 @@ public class ArmorControls { @SubscribeEvent public void keyEvent(KeyInputEvent event) { - if (!Loader.isModLoaded("notenoughkeys")) { + if (!isNotEnoughKeysLoaded) { checkAndPerformKeyActions(null, false); } } diff --git a/src/main/java/tconstruct/weaponry/weapons/Crossbow.java b/src/main/java/tconstruct/weaponry/weapons/Crossbow.java index d19e408f..f205d19a 100644 --- a/src/main/java/tconstruct/weaponry/weapons/Crossbow.java +++ b/src/main/java/tconstruct/weaponry/weapons/Crossbow.java @@ -146,11 +146,7 @@ public class Crossbow extends ProjectileWeapon { // remove loaded item if (ammo.getItem() instanceof IAmmo) ((IAmmo) ammo.getItem()).consumeAmmo(1, ammo); else { - if (Loader.isModLoaded("battlegear2")) { - player.inventory.consumeInventoryItem(ammo.getItem()); - } else { - player.inventory.consumeInventoryItem(ammo.getItem()); - } + player.inventory.consumeInventoryItem(ammo.getItem()); } playReloadSound(world, player, weapon, ammo);