From b56eff7fd9958d2db3c3cf3c6727a46abc765dc6 Mon Sep 17 00:00:00 2001 From: Mari023 <38946771+Mari023@users.noreply.github.com> Date: Fri, 27 Dec 2024 23:27:27 +0100 Subject: [PATCH] use ae2's new method of menu initialization that doesn't rely on magic classloading --- gradle.properties | 2 +- src/main/java/de/mari_023/ae2wtlib/AE2wtlib.java | 13 +++++-------- .../java/de/mari_023/ae2wtlib/AE2wtlibForge.java | 5 ++++- src/main/java/de/mari_023/ae2wtlib/wat/WATMenu.java | 3 ++- .../java/de/mari_023/ae2wtlib/wct/TrashMenu.java | 3 ++- src/main/java/de/mari_023/ae2wtlib/wct/WCTMenu.java | 3 ++- .../ae2wtlib/wct/magnet_card/MagnetMenu.java | 2 +- src/main/java/de/mari_023/ae2wtlib/wet/WETMenu.java | 3 ++- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/gradle.properties b/gradle.properties index e1b63785..142214ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ neoForge.parchment.mappingsVersion=2024.07.28 mavenGroup=de.mari_023 modID=ae2wtlib -ae2Version=19.0.23-beta +ae2Version=19.1.2-beta curiosVersion=8.0.0-beta.4+1.20.6 reiVersion=16.0.783 diff --git a/src/main/java/de/mari_023/ae2wtlib/AE2wtlib.java b/src/main/java/de/mari_023/ae2wtlib/AE2wtlib.java index cf42e86a..a3c29c76 100644 --- a/src/main/java/de/mari_023/ae2wtlib/AE2wtlib.java +++ b/src/main/java/de/mari_023/ae2wtlib/AE2wtlib.java @@ -75,15 +75,12 @@ static void addToCreativeTab() { AE2wtlibCreativeTab.add(AE2wtlibItems.MAGNET_CARD); } - @SuppressWarnings("unused") static void registerMenus() { - // TODO find a better way to do this. - // classloading causes this to be registered by ae2, but I don't know how reliable this is - var a = WCTMenu.TYPE; - var b = WETMenu.TYPE; - var c = WATMenu.TYPE; - var d = MagnetMenu.TYPE; - var e = TrashMenu.TYPE; + Registry.register(BuiltInRegistries.MENU, WCTMenu.ID, WCTMenu.TYPE); + Registry.register(BuiltInRegistries.MENU, WETMenu.ID, WETMenu.TYPE); + Registry.register(BuiltInRegistries.MENU, WATMenu.ID, WATMenu.TYPE); + Registry.register(BuiltInRegistries.MENU, MagnetMenu.ID, MagnetMenu.TYPE); + Registry.register(BuiltInRegistries.MENU, TrashMenu.ID, TrashMenu.TYPE); } public static void registerScreens(RegisterMenuScreensEvent event) { diff --git a/src/main/java/de/mari_023/ae2wtlib/AE2wtlibForge.java b/src/main/java/de/mari_023/ae2wtlib/AE2wtlibForge.java index 889b4f74..dbd906e6 100644 --- a/src/main/java/de/mari_023/ae2wtlib/AE2wtlibForge.java +++ b/src/main/java/de/mari_023/ae2wtlib/AE2wtlibForge.java @@ -39,15 +39,18 @@ public class AE2wtlibForge { public AE2wtlibForge(IEventBus modEventBus, ModContainer modContainer) { new AE2wtlibAPIImplementation(); CommonHooks.markComponentClassAsValid(ItemStack.class);// TODO figure out if there is a better way - AE2wtlib.registerMenus(); modContainer.registerConfig(ModConfig.Type.COMMON, AE2wtlibConfig.SPEC, AE2wtlibAPI.MOD_NAME + ".toml"); modEventBus.addListener((RegisterEvent e) -> { + if (e.getRegistryKey().equals(Registries.MENU)) { + AE2wtlib.registerMenus(); + } if (!e.getRegistryKey().equals(Registries.ITEM)) return; AE2wtlibItems.init(); AE2wtlib.onAe2Initialized(); AE2wtlibCreativeTab.init(); + }); modEventBus.addListener((BuildCreativeModeTabContentsEvent e) -> AE2wtlib.addToCreativeTab()); modEventBus.addListener((RegisterPayloadHandlersEvent event) -> { diff --git a/src/main/java/de/mari_023/ae2wtlib/wat/WATMenu.java b/src/main/java/de/mari_023/ae2wtlib/wat/WATMenu.java index 769a3fb2..ce378584 100644 --- a/src/main/java/de/mari_023/ae2wtlib/wat/WATMenu.java +++ b/src/main/java/de/mari_023/ae2wtlib/wat/WATMenu.java @@ -20,7 +20,8 @@ public class WATMenu extends PatternAccessTermMenu { public static final ResourceLocation ID = id("wireless_pattern_access_terminal"); - public static final MenuType TYPE = MenuTypeBuilder.create(WATMenu::new, WATMenuHost.class).build(ID); + public static final MenuType TYPE = MenuTypeBuilder.create(WATMenu::new, WATMenuHost.class) + .buildUnregistered(ID); private final WATMenuHost watMenuHost; private final ToolboxMenu toolboxMenu; diff --git a/src/main/java/de/mari_023/ae2wtlib/wct/TrashMenu.java b/src/main/java/de/mari_023/ae2wtlib/wct/TrashMenu.java index 8383d561..5d56d728 100644 --- a/src/main/java/de/mari_023/ae2wtlib/wct/TrashMenu.java +++ b/src/main/java/de/mari_023/ae2wtlib/wct/TrashMenu.java @@ -16,7 +16,8 @@ public class TrashMenu extends AEBaseMenu implements ISubMenu { public static final ResourceLocation ID = id("trash"); - public static final MenuType TYPE = MenuTypeBuilder.create(TrashMenu::new, WCTMenuHost.class).build(ID); + public static final MenuType TYPE = MenuTypeBuilder.create(TrashMenu::new, WCTMenuHost.class) + .buildUnregistered(ID); private final WCTMenuHost host; diff --git a/src/main/java/de/mari_023/ae2wtlib/wct/WCTMenu.java b/src/main/java/de/mari_023/ae2wtlib/wct/WCTMenu.java index 7b97a83f..acdd3752 100644 --- a/src/main/java/de/mari_023/ae2wtlib/wct/WCTMenu.java +++ b/src/main/java/de/mari_023/ae2wtlib/wct/WCTMenu.java @@ -25,7 +25,8 @@ public class WCTMenu extends CraftingTermMenu { public static final ResourceLocation ID = id("wireless_crafting_terminal"); - public static final MenuType TYPE = MenuTypeBuilder.create(WCTMenu::new, WCTMenuHost.class).build(ID); + public static final MenuType TYPE = MenuTypeBuilder.create(WCTMenu::new, WCTMenuHost.class) + .buildUnregistered(ID); public static final String MAGNET_MODE = "magnetMode"; public static final String MAGNET_MENU = "magnetMenu"; diff --git a/src/main/java/de/mari_023/ae2wtlib/wct/magnet_card/MagnetMenu.java b/src/main/java/de/mari_023/ae2wtlib/wct/magnet_card/MagnetMenu.java index 9db62f69..9c7b0af1 100644 --- a/src/main/java/de/mari_023/ae2wtlib/wct/magnet_card/MagnetMenu.java +++ b/src/main/java/de/mari_023/ae2wtlib/wct/magnet_card/MagnetMenu.java @@ -24,7 +24,7 @@ public class MagnetMenu extends AEBaseMenu implements ISubMenu { public static final ResourceLocation ID = id("magnet"); public static final MenuType TYPE = MenuTypeBuilder.create(MagnetMenu::new, WCTMenuHost.class) - .build(ID); + .buildUnregistered(ID); private final WCTMenuHost host; @Nullable diff --git a/src/main/java/de/mari_023/ae2wtlib/wet/WETMenu.java b/src/main/java/de/mari_023/ae2wtlib/wet/WETMenu.java index e0a7f7fd..8cb4eb19 100644 --- a/src/main/java/de/mari_023/ae2wtlib/wet/WETMenu.java +++ b/src/main/java/de/mari_023/ae2wtlib/wet/WETMenu.java @@ -17,7 +17,8 @@ public class WETMenu extends PatternEncodingTermMenu { public static final ResourceLocation ID = id("wireless_pattern_encoding_terminal"); - public static final MenuType TYPE = MenuTypeBuilder.create(WETMenu::new, WETMenuHost.class).build(ID); + public static final MenuType TYPE = MenuTypeBuilder.create(WETMenu::new, WETMenuHost.class) + .buildUnregistered(ID); private final WETMenuHost wetMenuHost;