Optionally supply FMLJavaModLoadingContext as a param to mod constructors (backport of #10074 to 1.20.6) (#10083)

This commit is contained in:
Paint_Ninja authored and GitHub committed 2024-09-12 14:01:15 +01:00
1 parent 976d710c10
commit dd8e7ffd16
12 files changed
+85 -66

No files matched your search

@@ -374,7 +374,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());
INSTANCE = this;
MinecraftForge.initialize();
@@ -391,7 +391,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);
@@ -406,13 +406,13 @@ public class ForgeMod {
registries.forEach(r -> r.register(modEventBus));
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
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);
@@ -31,12 +31,10 @@ import java.util.function.Supplier;
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();
@@ -85,36 +83,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);
}
}
}
*/
}
@@ -1,3 +1,8 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.common.util;
@@ -1,3 +1,8 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event;
import net.minecraft.core.component.DataComponentMap;