diff --git a/languages/java/src/main/java/net/neoforged/fml/common/Mod.java b/languages/java/src/main/java/net/neoforged/fml/common/Mod.java index f0f42ae67..c91dde7f5 100644 --- a/languages/java/src/main/java/net/neoforged/fml/common/Mod.java +++ b/languages/java/src/main/java/net/neoforged/fml/common/Mod.java @@ -14,6 +14,7 @@ import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.Bindings; +import net.neoforged.fml.ModContainer; import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; /** @@ -76,7 +77,7 @@ enum Bus { FORGE(Bindings.getForgeBus()), /** * The mod specific Event bus. - * @see FMLJavaModLoadingContext#getModEventBus() + * @see ModContainer#getEventBus() */ MOD(()-> FMLJavaModLoadingContext.get().getModEventBus()); @@ -86,6 +87,7 @@ enum Bus { this.busSupplier = eventBusSupplier; } + @Deprecated(forRemoval = true) public Supplier bus() { return busSupplier; } diff --git a/languages/java/src/main/java/net/neoforged/fml/javafmlmod/AutomaticEventSubscriber.java b/languages/java/src/main/java/net/neoforged/fml/javafmlmod/AutomaticEventSubscriber.java index d22f00feb..499ec66fd 100644 --- a/languages/java/src/main/java/net/neoforged/fml/javafmlmod/AutomaticEventSubscriber.java +++ b/languages/java/src/main/java/net/neoforged/fml/javafmlmod/AutomaticEventSubscriber.java @@ -6,6 +6,8 @@ package net.neoforged.fml.javafmlmod; import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.Bindings; import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; import net.neoforged.neoforgespi.language.ModFileScanData; @@ -57,8 +59,16 @@ public static void inject(final ModContainer mod, final ModFileScanData scanData if (Objects.equals(mod.getModId(), modId) && sides.contains(FMLEnvironment.dist)) { try { - LOGGER.debug(LOADING, "Auto-subscribing {} to {}", ad.clazz().getClassName(), busTarget); - busTarget.bus().get().register(Class.forName(ad.clazz().getClassName(), true, loader)); + IEventBus bus = switch (busTarget) { + case FORGE -> Bindings.getForgeBus().get(); + case MOD -> mod.getEventBus(); + }; + + if (bus != null) { + LOGGER.debug(LOADING, "Auto-subscribing {} to {}", ad.clazz().getClassName(), busTarget); + + bus.register(Class.forName(ad.clazz().getClassName(), true, loader)); + } } catch (ClassNotFoundException e) { diff --git a/languages/java/src/main/java/net/neoforged/fml/javafmlmod/FMLJavaModLoadingContext.java b/languages/java/src/main/java/net/neoforged/fml/javafmlmod/FMLJavaModLoadingContext.java index 68a5129b7..37865e33a 100644 --- a/languages/java/src/main/java/net/neoforged/fml/javafmlmod/FMLJavaModLoadingContext.java +++ b/languages/java/src/main/java/net/neoforged/fml/javafmlmod/FMLJavaModLoadingContext.java @@ -8,6 +8,7 @@ import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModLoadingContext; +@Deprecated(forRemoval = true) public class FMLJavaModLoadingContext { private final FMLModContainer container; @@ -17,6 +18,7 @@ public class FMLJavaModLoadingContext } /** + * @deprecated You can directly receive the event bus as a mod constructor argument. * @return The mod's event bus, to allow subscription to Mod specific events */ public IEventBus getModEventBus()