Speed up forge event registration (#186)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexdoru <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-07-17 23:45:05 +02:00
1 parent 121a0ce23b
commit 94022962b9
11 files changed
+375 -349

No files matched your search

@@ -5,10 +5,12 @@ import net.minecraft.client.settings.KeyBinding;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -55,6 +57,9 @@ public class ArmorControls {
public ArmorControls() {
getVanillaKeyBindings();
keys = new KeyBinding[] { armorKey, toggleGoggles, beltSwap, zoomKey, null, null };
EventHandler handler = new EventHandler();
FMLCommonHandler.instance().bus().register(handler);
MinecraftForge.EVENT_BUS.register(handler);
}
public void registerKeys() {
@@ -79,21 +84,6 @@ public class ArmorControls {
invKey = mc.gameSettings.keyBindInventory;
}
@SubscribeEvent
public void keyEvent(KeyInputEvent event) {
if (!isNotEnoughKeysLoaded) {
checkAndPerformKeyActions(null, false);
}
}
@Optional.Method(modid = "notenoughkeys")
@SubscribeEvent
public void keyEventSpecial(KeyBindingPressedEvent event) {
if (event.keyBinding != null && event.isKeyBindingPressed) {
checkAndPerformKeyActions(event.keyBinding, true);
}
}
private void checkAndPerformKeyActions(KeyBinding keyBinding, boolean inputFromNotEnoughKeys) {
if (inputFromNotEnoughKeys ? keyBinding == armorKey : armorKey.isPressed()) {
openArmorGui();
@@ -208,4 +198,22 @@ public class ArmorControls {
static void updateServer(AbstractPacket abstractPacket) {
TConstruct.packetPipeline.sendToServer(abstractPacket);
}
public class EventHandler {
@SubscribeEvent
public void keyEvent(KeyInputEvent event) {
if (!isNotEnoughKeysLoaded) {
checkAndPerformKeyActions(null, false);
}
}
@Optional.Method(modid = "notenoughkeys")
@SubscribeEvent
public void keyEventSpecial(KeyBindingPressedEvent event) {
if (event.keyBinding != null && event.isKeyBindingPressed) {
checkAndPerformKeyActions(event.keyBinding, true);
}
}
}
}
@@ -26,21 +26,6 @@ public class TabRegistry {
return tabList;
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void guiPostInit(GuiScreenEvent.InitGuiEvent.Post event) {
if ((event.gui instanceof GuiInventory)) {
int xSize = 176;
int ySize = 166;
int guiLeft = (event.gui.width - xSize) / 2;
int guiTop = (event.gui.height - ySize) / 2;
guiLeft += getPotionOffset();
updateTabValues(guiLeft, guiTop, InventoryTabVanilla.class);
addTabsToList(event.gui.buttonList);
}
}
private static final Minecraft mc = FMLClientHandler.instance().getClient();
public static void openInventoryGui() {
@@ -95,4 +80,22 @@ public class TabRegistry {
// No potions, no offset needed
return 0;
}
public static class EventHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void guiPostInit(GuiScreenEvent.InitGuiEvent.Post event) {
if ((event.gui instanceof GuiInventory)) {
int xSize = 176;
int ySize = 166;
int guiLeft = (event.gui.width - xSize) / 2;
int guiTop = (event.gui.height - ySize) / 2;
guiLeft += getPotionOffset();
updateTabValues(guiLeft, guiTop, InventoryTabVanilla.class);
addTabsToList(event.gui.buttonList);
}
}
}
}