Modify how ModLoadingStage handles dispatch to Registry Events. Stops the objectholder spam and generally improves performance on larger packs.

Signed-off-by: cpw <[email protected]>
This commit is contained in:
cpw committed 2020-10-04 15:50:15 -04:00
1 parent 9b421b54a7
commit 935cb6782d
4 files changed
+52 -45

No files matched your search

@@ -19,6 +19,7 @@
package net.minecraftforge.fml;
import cpw.mods.modlauncher.api.LamdbaExceptionUtils;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
@@ -102,14 +103,13 @@ public abstract class ModContainer
public static <T extends Event & IModBusEvent> CompletableFuture<Void> buildTransitionHandler(
final ModContainer target,
final ModLoadingStage.EventGenerator<T> eventGenerator,
final ModLoadingStage.EventDispatcher<T> eventDispatcher,
final BiFunction<ModLoadingStage, Throwable, ModLoadingStage> stateChangeHandler,
final Executor executor) {
return CompletableFuture
.runAsync(() -> {
ModLoadingContext.get().setActiveContainer(target, target.contextExtension.get());
target.activityMap.getOrDefault(target.modLoadingStage, ()->{}).run();
eventDispatcher.apply(target::acceptEvent).accept(eventGenerator.apply(target));
target.acceptEvent(eventGenerator.apply(target));
}, executor)
.whenComplete((mc, exception) -> {
target.modLoadingStage = stateChangeHandler.apply(target.modLoadingStage, exception);