From 50ebb989ebf429494acba1819df5819147430969 Mon Sep 17 00:00:00 2001 From: 90 Date: Sun, 17 Nov 2024 19:53:48 +0000 Subject: [PATCH] Remove Addons enum in preparation for 1.21 porting Assumed from here on out that the only first-hand integration from AppliedE will be with AE2WTLib and nothing else AE2-related. Also, AE2WTLib's API has hopefully been stabilised enough in current (1.21) versions to no longer require a mixin on AppliedE's end in order to register a custom terminal. AECapFix is specific only to 1.18-1.20 and hence would no longer be relevant. As a result, the Mixin plugin is also expected to be removed once 1.21 porting commences. --- .../java/gripe/_90/appliede/AppliedE.java | 12 ++++---- .../_90/appliede/integration/Addons.java | 28 ------------------- .../integration/DummyIntegrationItem.java | 6 ++-- .../ae2wtlib/AE2WTIntegration.java | 4 +-- .../java/gripe/_90/appliede/mixin/Plugin.java | 22 +++++++++++---- .../resources/assets/appliede/lang/en_us.json | 2 +- .../resources/assets/appliede/lang/zh_cn.json | 2 +- 7 files changed, 29 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/gripe/_90/appliede/integration/Addons.java diff --git a/src/main/java/gripe/_90/appliede/AppliedE.java b/src/main/java/gripe/_90/appliede/AppliedE.java index 1a2ed8c..a48f9d4 100644 --- a/src/main/java/gripe/_90/appliede/AppliedE.java +++ b/src/main/java/gripe/_90/appliede/AppliedE.java @@ -15,6 +15,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.client.event.RegisterColorHandlersEvent; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; @@ -57,7 +58,6 @@ import gripe._90.appliede.client.screen.EMCInterfaceScreen; import gripe._90.appliede.client.screen.EMCSetStockAmountScreen; import gripe._90.appliede.client.screen.TransmutationTerminalScreen; -import gripe._90.appliede.integration.Addons; import gripe._90.appliede.integration.DummyIntegrationItem; import gripe._90.appliede.integration.ae2wtlib.AE2WTIntegration; import gripe._90.appliede.me.key.EMCKey; @@ -128,9 +128,9 @@ public final class AppliedE { public static final RegistryObject DUMMY_EMC_ITEM = ITEMS.register("dummy_emc_item", () -> new Item(new Item.Properties())); - public static final RegistryObject WIRELESS_TRANSMUTATION_TERMINAL = ITEMS.register("wireless_transmutation_terminal", () -> Addons.AE2WTLIB.isLoaded() + public static final RegistryObject WIRELESS_TRANSMUTATION_TERMINAL = ITEMS.register("wireless_transmutation_terminal", () -> ModList.get().isLoaded("ae2wtlib") ? AE2WTIntegration.getWirelessTerminalItem() - : new DummyIntegrationItem(new Item.Properties().stacksTo(1), Addons.AE2WTLIB)); + : new DummyIntegrationItem(new Item.Properties().stacksTo(1), "AE2WTLib")); private static final String PROTOCOL_VERSION = Integer.toString(1); public static final SimpleChannel PACKET_HANDLER = NetworkRegistry.newSimpleChannel( @@ -150,7 +150,7 @@ public final class AppliedE { output.accept(LEARNING_CARD.get()); output.accept(WIRELESS_TRANSMUTATION_TERMINAL.get()); - if (Addons.AE2WTLIB.isLoaded()) { + if (ModList.get().isLoaded("ae2wtlib")) { output.accept(AE2WTIntegration.getChargedTerminal()); } }) @@ -196,7 +196,7 @@ public AppliedE() { registerEMC(AEParts.CABLE_ANCHOR, 32); }); - if (Addons.AE2WTLIB.isLoaded()) { + if (ModList.get().isLoaded("ae2wtlib")) { bus.addListener(AE2WTIntegration::registerTerminalMenu); bus.addListener(AE2WTIntegration::addTerminalToAE2WTLibTab); } @@ -255,7 +255,7 @@ private static void setup(IEventBus bus) { TransmutationTerminalScreen::new, "/screens/appliede/transmutation_terminal.json"); - if (Addons.AE2WTLIB.isLoaded()) { + if (ModList.get().isLoaded("ae2wtlib")) { AE2WTIntegration.Client.initScreen(); } })); diff --git a/src/main/java/gripe/_90/appliede/integration/Addons.java b/src/main/java/gripe/_90/appliede/integration/Addons.java deleted file mode 100644 index c819376..0000000 --- a/src/main/java/gripe/_90/appliede/integration/Addons.java +++ /dev/null @@ -1,28 +0,0 @@ -package gripe._90.appliede.integration; - -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.loading.LoadingModList; -import net.minecraftforge.forgespi.language.IModInfo; - -public enum Addons { - AE2WTLIB("ae2wtlib"), - AECAPFIX("aecapfix"); - - private final String modId; - - Addons(String modId) { - this.modId = modId; - } - - public String getModId() { - return modId; - } - - public boolean isLoaded() { - return ModList.get() != null - ? ModList.get().isLoaded(modId) - : LoadingModList.get().getMods().stream() - .map(IModInfo::getModId) - .anyMatch(modId::equals); - } -} diff --git a/src/main/java/gripe/_90/appliede/integration/DummyIntegrationItem.java b/src/main/java/gripe/_90/appliede/integration/DummyIntegrationItem.java index 650f1de..cce9b61 100644 --- a/src/main/java/gripe/_90/appliede/integration/DummyIntegrationItem.java +++ b/src/main/java/gripe/_90/appliede/integration/DummyIntegrationItem.java @@ -15,9 +15,9 @@ import gripe._90.appliede.AppliedE; public class DummyIntegrationItem extends Item { - private final Addons addon; + private final String addon; - public DummyIntegrationItem(Properties props, Addons addon) { + public DummyIntegrationItem(Properties props, String addon) { super(props); this.addon = addon; } @@ -25,7 +25,7 @@ public DummyIntegrationItem(Properties props, Addons addon) { @ParametersAreNonnullByDefault @Override public void appendHoverText(ItemStack stack, @Nullable Level level, List lines, TooltipFlag flag) { - lines.add(Component.translatable("tooltip." + AppliedE.MODID + ".not_installed." + addon.getModId()) + lines.add(Component.translatable("tooltip." + AppliedE.MODID + ".not_installed", addon) .withStyle(ChatFormatting.GRAY)); } } diff --git a/src/main/java/gripe/_90/appliede/integration/ae2wtlib/AE2WTIntegration.java b/src/main/java/gripe/_90/appliede/integration/ae2wtlib/AE2WTIntegration.java index bf3cc4b..287b594 100644 --- a/src/main/java/gripe/_90/appliede/integration/ae2wtlib/AE2WTIntegration.java +++ b/src/main/java/gripe/_90/appliede/integration/ae2wtlib/AE2WTIntegration.java @@ -13,8 +13,6 @@ import appeng.init.client.InitScreens; import appeng.items.tools.powered.WirelessTerminalItem; -import gripe._90.appliede.integration.Addons; - public class AE2WTIntegration { private static final Item TERMINAL = new WTTItem(); @@ -40,7 +38,7 @@ public static void registerTerminalMenu(RegisterEvent event) { } public static void addTerminalToAE2WTLibTab(BuildCreativeModeTabContentsEvent event) { - if (event.getTabKey().location().getNamespace().equals(Addons.AE2WTLIB.getModId())) { + if (event.getTabKey().location().getNamespace().equals("ae2wtlib")) { event.accept(TERMINAL); event.accept(AE2WTIntegration.getChargedTerminal()); } diff --git a/src/main/java/gripe/_90/appliede/mixin/Plugin.java b/src/main/java/gripe/_90/appliede/mixin/Plugin.java index 5437a41..698b1a5 100644 --- a/src/main/java/gripe/_90/appliede/mixin/Plugin.java +++ b/src/main/java/gripe/_90/appliede/mixin/Plugin.java @@ -7,15 +7,27 @@ import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import gripe._90.appliede.integration.Addons; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.loading.LoadingModList; +import net.minecraftforge.forgespi.language.IModInfo; public class Plugin implements IMixinConfigPlugin { + private static boolean isModLoaded(String modId) { + return ModList.get() != null + ? ModList.get().isLoaded(modId) + : LoadingModList.get().getMods().stream() + .map(IModInfo::getModId) + .anyMatch(modId::equals); + } + @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - for (var addon : Addons.values()) { - if (mixinClassName.contains(addon.getModId())) { - return addon.isLoaded(); - } + if (mixinClassName.contains("aecapfix")) { + return isModLoaded("aecapfix"); + } + + if (mixinClassName.contains("ae2wtlib")) { + return isModLoaded("ae2wtlib"); } return true; diff --git a/src/main/resources/assets/appliede/lang/en_us.json b/src/main/resources/assets/appliede/lang/en_us.json index b527f2e..de6adb4 100644 --- a/src/main/resources/assets/appliede/lang/en_us.json +++ b/src/main/resources/assets/appliede/lang/en_us.json @@ -22,5 +22,5 @@ "key.appliede.emc_tiered": "EMC^%s", "tooltip.appliede.transmutable": "Transmutable from EMC (Shift+Click/Scroll)", "tooltip.appliede.owner": "Owner: %s", - "tooltip.appliede.not_installed.ae2wtlib": "AE2WTLib not installed." + "tooltip.appliede.not_installed": "%s not installed." } diff --git a/src/main/resources/assets/appliede/lang/zh_cn.json b/src/main/resources/assets/appliede/lang/zh_cn.json index e9cdb4e..f7fd808 100644 --- a/src/main/resources/assets/appliede/lang/zh_cn.json +++ b/src/main/resources/assets/appliede/lang/zh_cn.json @@ -21,5 +21,5 @@ "key.appliede.emc_tiered": "EMC^%s", "tooltip.appliede.transmutable": "转化为EMC (Shift+点击/滚动)", "tooltip.appliede.owner": "所有者: %s", - "tooltip.appliede.not_installed.ae2wtlib": "AE2WTLib未安装。" + "tooltip.appliede.not_installed": "%s未安装。" }