Suppress firing events at load time if an error has already occurred (#4801)
This commit is contained in:
parent
76591f7245
commit
d0566ebadc
4 changed files with 21 additions and 1 deletions
|
@ -952,6 +952,8 @@ public final class ModelLoader extends ModelBakery
|
|||
*/
|
||||
public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry)
|
||||
{
|
||||
if (!isLoading) return;
|
||||
|
||||
IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING);
|
||||
Map<String, Integer> modelErrors = Maps.newHashMap();
|
||||
Set<ResourceLocation> printedBlockStateErrors = Sets.newHashSet();
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.TextTable;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
|
||||
|
@ -185,6 +186,7 @@ public class LoadController
|
|||
if (errors.size() > 0)
|
||||
{
|
||||
FMLLog.log.fatal("Fatal errors were detected during {}. Loading cannot continue.", state);
|
||||
MinecraftForge.EVENT_BUS.shutdown();
|
||||
state = state.transition(true);
|
||||
throw throwStoredErrors();
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public class EventBus implements IEventExceptionHandler
|
|||
private Map<Object,ModContainer> listenerOwners = new MapMaker().weakKeys().weakValues().makeMap();
|
||||
private final int busID = maxID++;
|
||||
private IEventExceptionHandler exceptionHandler;
|
||||
private boolean shutdown;
|
||||
|
||||
public EventBus()
|
||||
{
|
||||
|
@ -170,6 +171,8 @@ public class EventBus implements IEventExceptionHandler
|
|||
|
||||
public boolean post(Event event)
|
||||
{
|
||||
if (shutdown) return false;
|
||||
|
||||
IEventListener[] listeners = event.getListenerList().getListeners(busID);
|
||||
int index = 0;
|
||||
try
|
||||
|
@ -185,7 +188,13 @@ public class EventBus implements IEventExceptionHandler
|
|||
Throwables.throwIfUnchecked(throwable);
|
||||
throw new RuntimeException(throwable);
|
||||
}
|
||||
return (event.isCancelable() ? event.isCanceled() : false);
|
||||
return event.isCancelable() && event.isCanceled();
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
FMLLog.log.warn("EventBus {} shutting down - future events will not be posted.", busID);
|
||||
shutdown = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ package net.minecraftforge.debug.mod;
|
|||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.client.CustomModLoadingErrorDisplayException;
|
||||
|
@ -58,6 +59,12 @@ public class ClientLoadingExceptionTest
|
|||
throw new RuntimeException("This should not be called because the mod threw an exception earlier in Pre-Init and is in a broken state.");
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBake(ModelBakeEvent e)
|
||||
{
|
||||
throw new RuntimeException("This should not be called because the mod threw an exception earlier in Pre-Init and is in a broken state.");
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onInit(FMLInitializationEvent e)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue