Revert "Properly shutdown FMLModContainer's event bus when an error in a lifecycle event is detected."
This reverts commit 30bad1e2
Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
parent
19a38f5cb9
commit
ff752ab14b
2 changed files with 12 additions and 46 deletions
|
@ -23,16 +23,22 @@ import net.minecraft.entity.ai.attributes.Attribute;
|
||||||
import net.minecraft.entity.ai.attributes.RangedAttribute;
|
import net.minecraft.entity.ai.attributes.RangedAttribute;
|
||||||
import net.minecraft.util.SoundEvent;
|
import net.minecraft.util.SoundEvent;
|
||||||
import net.minecraft.world.storage.IServerConfiguration;
|
import net.minecraft.world.storage.IServerConfiguration;
|
||||||
|
import net.minecraft.world.storage.IWorldInfo;
|
||||||
import net.minecraft.world.storage.SaveFormat;
|
import net.minecraft.world.storage.SaveFormat;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.*;
|
import net.minecraftforge.fml.*;
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
import net.minecraftforge.fml.config.ModConfig;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLModIdMappingEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLModIdMappingEvent;
|
||||||
|
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||||
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import net.minecraftforge.fml.loading.progress.StartupMessageManager;
|
import net.minecraftforge.fml.loading.progress.StartupMessageManager;
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.server.command.ConfigCommand;
|
||||||
|
import net.minecraftforge.server.command.ForgeCommand;
|
||||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||||
import net.minecraftforge.versions.mcp.MCPVersion;
|
import net.minecraftforge.versions.mcp.MCPVersion;
|
||||||
|
|
||||||
|
@ -106,7 +112,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
|
||||||
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
modEventBus.addListener(this::preInit);
|
modEventBus.addListener(this::preInit);
|
||||||
modEventBus.addListener(this::gatherData);
|
modEventBus.addListener(this::gatherData);
|
||||||
modEventBus.addGenericListener(IRecipeSerializer.class, this::registerRecipeSerialziers);
|
modEventBus.register(this);
|
||||||
ATTRIBUTES.register(modEventBus);
|
ATTRIBUTES.register(modEventBus);
|
||||||
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
|
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
|
||||||
MinecraftForge.EVENT_BUS.addGenericListener(SoundEvent.class, this::missingSoundMapping);
|
MinecraftForge.EVENT_BUS.addGenericListener(SoundEvent.class, this::missingSoundMapping);
|
||||||
|
@ -119,6 +125,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.addListener(VillagerTradingManager::loadTrades);
|
MinecraftForge.EVENT_BUS.addListener(VillagerTradingManager::loadTrades);
|
||||||
MinecraftForge.EVENT_BUS.register(MinecraftForge.INTERNAL_HANDLER);
|
MinecraftForge.EVENT_BUS.register(MinecraftForge.INTERNAL_HANDLER);
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preInit(FMLCommonSetupEvent evt)
|
public void preInit(FMLCommonSetupEvent evt)
|
||||||
|
@ -208,6 +215,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent //ModBus, can't use addListener due to nested genetics.
|
||||||
public void registerRecipeSerialziers(RegistryEvent.Register<IRecipeSerializer<?>> event)
|
public void registerRecipeSerialziers(RegistryEvent.Register<IRecipeSerializer<?>> event)
|
||||||
{
|
{
|
||||||
CraftingHelper.register(AndCondition.Serializer.INSTANCE);
|
CraftingHelper.register(AndCondition.Serializer.INSTANCE);
|
||||||
|
|
|
@ -30,15 +30,13 @@ import net.minecraftforge.fml.ModContainer;
|
||||||
import net.minecraftforge.fml.ModLoadingException;
|
import net.minecraftforge.fml.ModLoadingException;
|
||||||
import net.minecraftforge.fml.ModLoadingStage;
|
import net.minecraftforge.fml.ModLoadingStage;
|
||||||
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
|
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.ModLifecycleEvent;
|
||||||
import net.minecraftforge.forgespi.language.IModInfo;
|
import net.minecraftforge.forgespi.language.IModInfo;
|
||||||
import net.minecraftforge.forgespi.language.ModFileScanData;
|
import net.minecraftforge.forgespi.language.ModFileScanData;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@ -92,7 +90,7 @@ public class FMLModContainer extends ModContainer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<LifecycleEventProvider.LifecycleEvent> dummy() { return new ErroringConsumer<>(); }
|
private Consumer<LifecycleEventProvider.LifecycleEvent> dummy() { return (s) -> {}; }
|
||||||
|
|
||||||
private void onEventFailed(IEventBus iEventBus, Event event, IEventListener[] iEventListeners, int i, Throwable throwable)
|
private void onEventFailed(IEventBus iEventBus, Event event, IEventListener[] iEventListeners, int i, Throwable throwable)
|
||||||
{
|
{
|
||||||
|
@ -120,7 +118,6 @@ public class FMLModContainer extends ModContainer
|
||||||
private void afterEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
private void afterEvent(LifecycleEventProvider.LifecycleEvent lifecycleEvent) {
|
||||||
if (getCurrentState() == ModLoadingStage.ERROR) {
|
if (getCurrentState() == ModLoadingStage.ERROR) {
|
||||||
LOGGER.error(LOADING,"An error occurred while dispatching event {} to {}", lifecycleEvent.fromStage(), getModId());
|
LOGGER.error(LOADING,"An error occurred while dispatching event {} to {}", lifecycleEvent.fromStage(), getModId());
|
||||||
this.eventBus.shutdown();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,46 +166,7 @@ public class FMLModContainer extends ModContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void acceptEvent(final Event e)
|
protected void acceptEvent(final Event e) {
|
||||||
{
|
|
||||||
this.eventBus.post(e);
|
this.eventBus.post(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ErroringConsumer<T> implements Consumer<T>
|
|
||||||
{
|
|
||||||
private List<Consumer<? super T>> children = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accept(T t)
|
|
||||||
{
|
|
||||||
Throwable error = null;
|
|
||||||
for (Consumer<? super T> child : children)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
child.accept(t);
|
|
||||||
}
|
|
||||||
catch (Throwable e)
|
|
||||||
{
|
|
||||||
FMLModContainer.this.modLoadingStage = ModLoadingStage.ERROR;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error != null)
|
|
||||||
{
|
|
||||||
if (error instanceof RuntimeException)
|
|
||||||
throw (RuntimeException)error;
|
|
||||||
throw new RuntimeException(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ErroringConsumer<T> andThen(Consumer<? super T> after)
|
|
||||||
{
|
|
||||||
Objects.requireNonNull(after);
|
|
||||||
children.add(after);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue