Optionally supply FMLJavaModLoadingContext as a param to mod constructors (backport of #10074 to 1.20.1) (#10100)

Co-authored-by: RealMangoRage <andrew333awesome@outlook.com>
This commit is contained in:
Paint_NinjaandRealMangoRage authored and GitHub committed 2024-09-12 14:06:42 +01:00
1 parent e615774a0e
commit 29986615fe
6 files changed
+59 -65

No files matched your search

@@ -414,7 +414,7 @@ public class ForgeMod
enableMilkFluid = true;
}
public ForgeMod()
public ForgeMod(FMLJavaModLoadingContext context)
{
LOGGER.info(FORGEMOD,"Forge mod loading, version {}, for MC {} with MCP {}", ForgeVersion.getVersion(), MCPVersion.getMCVersion(), MCPVersion.getMCPVersion());
ForgeSnapshotsMod.logStartupWarning();
@@ -430,7 +430,7 @@ public class ForgeMod
CrashReportCallables.registerCrashCallable("FML", ForgeVersion::getSpec);
CrashReportCallables.registerCrashCallable("Forge", ()->ForgeVersion.getGroup()+":"+ForgeVersion.getVersion());
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
final IEventBus modEventBus = context.getModEventBus();
// Forge-provided datapack registries
modEventBus.addListener((DataPackRegistryEvent.NewRegistry event) -> {
event.dataPackRegistry(ForgeRegistries.Keys.BIOME_MODIFIERS, BiomeModifier.DIRECT_CODEC);
@@ -452,13 +452,13 @@ public class ForgeMod
VANILLA_FLUID_TYPES.register(modEventBus);
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
MinecraftForge.EVENT_BUS.addListener(this::missingSoundMapping);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ForgeConfig.clientSpec);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ForgeConfig.serverSpec);
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ForgeConfig.commonSpec);
context.registerConfig(ModConfig.Type.CLIENT, ForgeConfig.clientSpec);
context.registerConfig(ModConfig.Type.SERVER, ForgeConfig.serverSpec);
context.registerConfig(ModConfig.Type.COMMON, ForgeConfig.commonSpec);
modEventBus.register(ForgeConfig.class);
ForgeDeferredRegistriesSetup.setup(modEventBus);
// Forge does not display problems when the remote is not matching.
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, ()->new IExtensionPoint.DisplayTest(()->"ANY", (remote, isServer)-> true));
context.registerDisplayTest(IExtensionPoint.DisplayTest.IGNORE_ALL_VERSION);
StartupMessageManager.addModMessage("Forge version "+ForgeVersion.getVersion());
MinecraftForge.EVENT_BUS.addListener(VillagerTradingManager::loadTrades);
@@ -27,12 +27,10 @@ import java.util.function.Function;
public class MinecraftForge
{
/**
* The core Forge EventBusses, all events for Forge will be fired on these,
* you should use this to register all your listeners.
* This replaces every register*Handler() function in the old version of Forge.
* TERRAIN_GEN_BUS for terrain gen events
* ORE_GEN_BUS for ore gen events
* EVENT_BUS for everything else
* The EventBus for all the Forge Events.
*
* Events marked with {@link net.minecraftforge.fml.event.IModBusEvent}
* belong on the ModBus and not this bus
*/
public static final IEventBus EVENT_BUS = BusBuilder.builder().startShutdown().useModLauncher().build();
@@ -82,36 +80,4 @@ public class MinecraftForge
() -> new ConfigScreenHandler.ConfigScreenFactory(screenFunction)
);
}
/*
public static void preloadCrashClasses(ASMDataTable table, String modID, Set<String> classes)
{
//Find all ICrashReportDetail's handlers and preload them.
List<String> all = Lists.newArrayList();
for (ASMData asm : table.getAll(ICrashReportDetail.class.getName().replace('.', '/')))
all.add(asm.getClassName());
for (ASMData asm : table.getAll(ICrashCallable.class.getName().replace('.', '/')))
all.add(asm.getClassName());
all.retainAll(classes);
if (all.size() == 0)
return;
ForgeMod.log.debug("Preloading CrashReport Classes");
Collections.sort(all); //Sort it because I like pretty output ;)
for (String name : all)
{
ForgeMod.log.debug("\t{}", name);
try
{
Class.forName(name.replace('/', '.'), false, MinecraftForge.class.getClassLoader());
}
catch (Exception e)
{
LOGGER.error("Could not find class for name '{}'.", name, e);
}
}
}
*/
}