Skip to content

Commit

Permalink
Remove unnecessary reflection (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru authored Nov 16, 2024
1 parent 0c0ac4f commit 0f9710a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
51 changes: 22 additions & 29 deletions src/main/java/mcp/mobius/waila/client/KeyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
}

}
9 changes: 2 additions & 7 deletions src/main/java/mcp/mobius/waila/client/ProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}
Expand Down

0 comments on commit 0f9710a

Please sign in to comment.