From 0f9710a9f97890be9bcff4934d3680965ef5a6f3 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 16 Nov 2024 02:48:17 +0100 Subject: [PATCH] Remove unnecessary reflection (#24) --- .../mcp/mobius/waila/client/KeyEvent.java | 51 ++++++++----------- .../mcp/mobius/waila/client/ProxyClient.java | 9 +--- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/main/java/mcp/mobius/waila/client/KeyEvent.java b/src/main/java/mcp/mobius/waila/client/KeyEvent.java index 175a26c..e23a548 100644 --- a/src/main/java/mcp/mobius/waila/client/KeyEvent.java +++ b/src/main/java/mcp/mobius/waila/client/KeyEvent.java @@ -12,6 +12,7 @@ import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent; import mcp.mobius.waila.api.impl.ConfigHandler; import mcp.mobius.waila.gui.screens.config.ScreenConfig; +import mcp.mobius.waila.handlers.nei.NEIHandler; import mcp.mobius.waila.utils.Constants; public class KeyEvent { @@ -43,38 +44,30 @@ public void onKeyEvent(KeyInputEvent event) { if (mc.currentScreen == null) { mc.displayGuiScreen(new ScreenConfig(null)); } - } else if (showKey && ConfigHandler.instance() + return; + } + if (showKey && ConfigHandler.instance() .getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_MODE, false)) { - boolean status = ConfigHandler.instance() - .getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); - ConfigHandler.instance() - .setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, !status); + boolean status = ConfigHandler.instance() + .getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); + ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, !status); + } else if (showKey && !ConfigHandler.instance() + .getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_MODE, false)) { + ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); } else - if (showKey && !ConfigHandler.instance() - .getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_MODE, false)) { - ConfigHandler.instance() - .setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); - } else - if (key_liquid.isPressed()) { - boolean status = ConfigHandler.instance() - .getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, true); - ConfigHandler.instance() - .setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, !status); - } else if (key_recipe.isPressed()) { - if (Loader.isModLoaded("NotEnoughItems")) { - try { - Class.forName("mcp.mobius.waila.handlers.nei.NEIHandler") - .getDeclaredMethod("openRecipeGUI", boolean.class).invoke(null, true); - } catch (Exception ignored) {} - } - } else if (key_usage.isPressed()) { - if (Loader.isModLoaded("NotEnoughItems")) { - try { - Class.forName("mcp.mobius.waila.handlers.nei.NEIHandler") - .getDeclaredMethod("openRecipeGUI", boolean.class).invoke(null, false); - } catch (Exception ignored) {} - } + if (key_liquid.isPressed()) { + boolean status = ConfigHandler.instance() + .getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, true); + ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, !status); + } else if (key_recipe.isPressed()) { + if (Loader.isModLoaded("NotEnoughItems")) { + NEIHandler.openRecipeGUI(true); + } + } else if (key_usage.isPressed()) { + if (Loader.isModLoaded("NotEnoughItems")) { + NEIHandler.openRecipeGUI(false); } + } } } diff --git a/src/main/java/mcp/mobius/waila/client/ProxyClient.java b/src/main/java/mcp/mobius/waila/client/ProxyClient.java index cb4466a..8cda936 100644 --- a/src/main/java/mcp/mobius/waila/client/ProxyClient.java +++ b/src/main/java/mcp/mobius/waila/client/ProxyClient.java @@ -8,7 +8,6 @@ import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import mcp.mobius.waila.Waila; import mcp.mobius.waila.api.impl.DataAccessorCommon; import mcp.mobius.waila.api.impl.ModuleRegistrar; import mcp.mobius.waila.cbcore.LangUtil; @@ -17,6 +16,7 @@ import mcp.mobius.waila.handlers.HUDHandlerBlocks; import mcp.mobius.waila.handlers.HUDHandlerEntities; import mcp.mobius.waila.handlers.VanillaTooltipHandler; +import mcp.mobius.waila.handlers.nei.NEIHandler; import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderHealth; import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderProgressBar; import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderStack; @@ -34,12 +34,7 @@ public void registerHandlers() { LangUtil.loadLangDir("waila"); if (Loader.isModLoaded("NotEnoughItems")) { - try { - Class.forName("mcp.mobius.waila.handlers.nei.NEIHandler").getDeclaredMethod("register").invoke(null); - } catch (Exception e) { - Waila.log.error("Failed to hook into NEI properly. Reverting to Vanilla tooltip handler"); - MinecraftForge.EVENT_BUS.register(new VanillaTooltipHandler()); - } + NEIHandler.register(); } else { MinecraftForge.EVENT_BUS.register(new VanillaTooltipHandler()); }