mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
[1.21.1] Optionally supply FMLJavaModLoadingContext as a param to mod constructors (#10074)
Also made `FMLJavaModLoadingContext` extend `ModLoadingContext`. See the PR description for example usage.
This commit is contained in:
1 parent
26d0f7282f
commit
419c349a1f
21 files changed
+138
-79
No files matched your search
@@ -63,6 +63,7 @@ import net.minecraftforge.fluids.ForgeFlowingFluid;
|
||||
import net.minecraftforge.fml.*;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.lifecycle.*;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.*;
|
||||
import net.minecraftforge.registries.holdersets.AndHolderSet;
|
||||
import net.minecraftforge.registries.holdersets.AnyHolderSet;
|
||||
@@ -72,7 +73,6 @@ import net.minecraftforge.registries.holdersets.OrHolderSet;
|
||||
import net.minecraftforge.network.NetworkInitialization;
|
||||
import net.minecraftforge.network.tasks.ForgeNetworkConfigurationHandler;
|
||||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
import net.minecraftforge.server.command.ModIdArgument;
|
||||
@@ -370,7 +370,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();
|
||||
@@ -387,7 +387,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);
|
||||
@@ -404,13 +404,13 @@ public class ForgeMod {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -30,13 +30,12 @@ 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 +84,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -8,6 +8,10 @@ package net.minecraftforge.fml.event.lifecycle;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
|
||||
/**
|
||||
* Supplied as a param to your mod's constructor to get access
|
||||
* to the mod EventBus and various mod-specific objects.
|
||||
*/
|
||||
public class FMLConstructModEvent extends ParallelDispatchEvent {
|
||||
public FMLConstructModEvent(final ModContainer container, final ModLoadingStage stage) {
|
||||
super(container, stage);
|
||||
|
||||
Reference in new issue
Block a user