mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-28 15:56:02 +00:00
Well, it works, for a game, now.
This commit is contained in:
1 parent
06b16aaa19
commit
d0ab0e166c
208 files changed
+2328
-5883
No files matched your search
@@ -92,7 +92,7 @@ public class FMLJavaModLanguageProvider implements IModLanguageProvider
|
||||
return scanResult -> {
|
||||
final Map<String, FMLModTarget> modTargetMap = scanResult.getAnnotations().stream()
|
||||
.filter(ad -> ad.getAnnotationType().equals(MODANNOTATION))
|
||||
.peek(ad -> fmlLog.debug(SCAN, "Found @Mod class {} with id {}", ad.getClassType().getClassName(), ad.getAnnotationData().get("modid")))
|
||||
.peek(ad -> fmlLog.debug(SCAN, "Found @Mod class {} with id {}", ad.getClassType().getClassName(), ad.getAnnotationData().get("value")))
|
||||
.map(ad -> new FMLModTarget(ad.getClassType().getClassName(), (String)ad.getAnnotationData().get("value")))
|
||||
.collect(Collectors.toMap(FMLModTarget::getModId, Function.identity()));
|
||||
scanResult.addLanguageLoader(modTargetMap);
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.IEventListener;
|
||||
import net.minecraftforge.fml.LifecycleEventProvider;
|
||||
import net.minecraftforge.fml.ModThreadContext;
|
||||
import net.minecraftforge.fml.common.event.ModLifecycleEvent;
|
||||
import net.minecraftforge.fml.AutomaticEventSubscriber;
|
||||
import net.minecraftforge.fml.ModLoadingStage;
|
||||
@@ -84,19 +85,21 @@ public class FMLModContainer extends ModContainer
|
||||
private void onEventFailed(IEventBus iEventBus, Event event, IEventListener[] iEventListeners, int i, Throwable throwable)
|
||||
{
|
||||
LOGGER.error(new EventBusErrorMessage(event, i, iEventListeners, throwable));
|
||||
modLoadingError.add(throwable);
|
||||
}
|
||||
|
||||
private void beforeEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
||||
ModLoadingContext.get().activeContainer = this;
|
||||
ModLoadingContext.get().setActiveContainer(this);
|
||||
ModThreadContext.get().setActiveContainer(this);
|
||||
}
|
||||
|
||||
private void fireEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
||||
final ModLifecycleEvent event = lifecycleEvent.buildModEvent(this);
|
||||
LOGGER.debug(LOADING, "Firing event {} for modid {}", event, this.getModId());
|
||||
LOGGER.debug(LOADING, "Firing event for modid {} : {} @ {}", this.getModId(), event, System.identityHashCode(event.getClass()));
|
||||
try
|
||||
{
|
||||
eventBus.post(event);
|
||||
LOGGER.debug(LOADING, "Fired event {} for modid {}", event, this.getModId());
|
||||
LOGGER.debug(LOADING, "Fired event for modid {} : {}", this.getModId(), event);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
@@ -107,7 +110,8 @@ public class FMLModContainer extends ModContainer
|
||||
}
|
||||
|
||||
private void afterEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
||||
ModLoadingContext.get().activeContainer = null;
|
||||
ModThreadContext.get().setActiveContainer(null);
|
||||
ModLoadingContext.get().setActiveContainer(null);
|
||||
if (getCurrentState() == ModLoadingStage.ERROR) {
|
||||
LOGGER.error(LOADING,"An error occurred while dispatching event {} to {}", lifecycleEvent.fromStage(), getModId());
|
||||
}
|
||||
|
||||
@@ -20,27 +20,34 @@
|
||||
package net.minecraftforge.fml.javafmlmod;
|
||||
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.ExtensionPoint;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ModLoadingContext
|
||||
{
|
||||
private static ThreadLocal<ModLoadingContext> context = ThreadLocal.withInitial(ModLoadingContext::new);
|
||||
FMLModContainer activeContainer;
|
||||
private FMLModContainer activeContainer;
|
||||
public static ModLoadingContext get() {
|
||||
return context.get();
|
||||
}
|
||||
|
||||
public <T> void registerExtensionPoint(ExtensionPoint<T> point, Supplier<T> extension) {
|
||||
activeContainer.registerExtensionPoint(point, extension);
|
||||
getActiveContainer().registerExtensionPoint(point, extension);
|
||||
}
|
||||
|
||||
public IEventBus getModEventBus()
|
||||
{
|
||||
return activeContainer.getEventBus();
|
||||
return getActiveContainer().getEventBus();
|
||||
}
|
||||
|
||||
public FMLModContainer getActiveContainer()
|
||||
{
|
||||
return activeContainer;
|
||||
}
|
||||
|
||||
public void setActiveContainer(FMLModContainer activeContainer)
|
||||
{
|
||||
this.activeContainer = activeContainer;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user