mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-25 14:34:28 +00:00
Clean up the mod loading context objects. There is only one ThreadLocal now.
**BREAKING CHANGE** FMLModLoadingContext is renamed to FMLJavaModLoadingContext. LanguageProviders can setup additional contextual data. Signed-off-by: cpw <[email protected]>
This commit is contained in:
8 files changed
+100
-95
No files matched your search
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.javafmlmod;
|
||||
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
|
||||
public class FMLJavaModLoadingContext
|
||||
{
|
||||
private final FMLModContainer container;
|
||||
|
||||
FMLJavaModLoadingContext(FMLModContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The mod's event bus, to allow subscription to Mod specific events
|
||||
*/
|
||||
public IEventBus getModEventBus()
|
||||
{
|
||||
return container.getEventBus();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper to get the right instance from the {@link ModLoadingContext} correctly.
|
||||
* @return The FMLJavaMod language specific extension from the ModLoadingContext
|
||||
*/
|
||||
public static FMLJavaModLoadingContext get() {
|
||||
return ModLoadingContext.get().extension();
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,8 @@ public class FMLModContainer extends ModContainer
|
||||
triggerMap.put(ModLoadingStage.COMPLETE, dummy().andThen(this::beforeEvent).andThen(this::completeLoading).andThen(this::fireEvent).andThen(this::afterEvent));
|
||||
this.eventBus = IEventBus.create(this::onEventFailed);
|
||||
this.configHandler = Optional.of(event -> this.eventBus.post(event));
|
||||
final FMLJavaModLoadingContext contextExtension = new FMLJavaModLoadingContext(this);
|
||||
this.contextExtension = () -> contextExtension;
|
||||
try
|
||||
{
|
||||
modClass = Class.forName(className, true, modClassLoader);
|
||||
@@ -93,8 +95,6 @@ public class FMLModContainer extends ModContainer
|
||||
}
|
||||
|
||||
private void beforeEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
||||
FMLModLoadingContext.get().setActiveContainer(this);
|
||||
ModLoadingContext.get().setActiveContainer(this);
|
||||
}
|
||||
|
||||
private void fireEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
||||
@@ -113,8 +113,6 @@ public class FMLModContainer extends ModContainer
|
||||
}
|
||||
|
||||
private void afterEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
||||
ModLoadingContext.get().setActiveContainer(null);
|
||||
FMLModLoadingContext.get().setActiveContainer(null);
|
||||
if (getCurrentState() == ModLoadingStage.ERROR) {
|
||||
LOGGER.error(LOADING,"An error occurred while dispatching event {} to {}", lifecycleEvent.fromStage(), getModId());
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.javafmlmod;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.ExtensionPoint;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class FMLModLoadingContext
|
||||
{
|
||||
private static ThreadLocal<FMLModLoadingContext> context = ThreadLocal.withInitial(FMLModLoadingContext::new);
|
||||
private FMLModContainer activeContainer;
|
||||
public static FMLModLoadingContext get() {
|
||||
return context.get();
|
||||
}
|
||||
|
||||
public void registerConfig(ModConfig.Type type, ForgeConfigSpec spec) {
|
||||
getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer()));
|
||||
}
|
||||
|
||||
public void registerConfig(ModConfig.Type type, ForgeConfigSpec spec, String fileName) {
|
||||
getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer(), fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The mod's event bus, to allow subscription to Mod specific events
|
||||
*/
|
||||
public IEventBus getModEventBus()
|
||||
{
|
||||
return getActiveContainer().getEventBus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Only valid during {@link net.minecraftforge.fml.event.lifecycle.ModLifecycleEvent} dispatch and Mod construction
|
||||
* @return the active FML container
|
||||
*/
|
||||
public FMLModContainer getActiveContainer()
|
||||
{
|
||||
return activeContainer;
|
||||
}
|
||||
|
||||
public void setActiveContainer(FMLModContainer activeContainer)
|
||||
{
|
||||
this.activeContainer = activeContainer;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user