Skip to content

Commit

Permalink
Deprecate FMLJavaModLoadingContext for removal (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep authored Dec 8, 2023
1 parent 198f30c commit 3447c36
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -76,7 +77,7 @@ enum Bus {
FORGE(Bindings.getForgeBus()),
/**
* The mod specific Event bus.
* @see FMLJavaModLoadingContext#getModEventBus()
* @see ModContainer#getEventBus()
*/
MOD(()-> FMLJavaModLoadingContext.get().getModEventBus());

Expand All @@ -86,6 +87,7 @@ enum Bus {
this.busSupplier = eventBusSupplier;
}

@Deprecated(forRemoval = true)
public Supplier<IEventBus> bus() {
return busSupplier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit 3447c36

Please sign in to comment.