Suppress firing events at load time if an error has already occurred (#4801)

This commit is contained in:
Ben Staddon authored and mezz committed 2018-04-12 17:18:43 -07:00
1 parent 76591f7245
commit d0566ebadc
4 files changed
+21 -1

No files matched your search

@@ -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