|
1 | 1 | package org.embeddedt.modernfix.neoforge.mixin.feature.registry_event_progress; |
2 | 2 |
|
3 | 3 | import net.neoforged.bus.api.Event; |
| 4 | +import net.neoforged.bus.api.EventPriority; |
4 | 5 | import net.neoforged.fml.ModList; |
5 | 6 | import net.neoforged.fml.ModLoader; |
6 | 7 | import net.neoforged.fml.ModLoadingContext; |
@@ -36,17 +37,25 @@ private static void closeAsyncScreen(CallbackInfo ci) { |
36 | 37 | @Redirect(method = "postRegisterEvents", at = @At(value = "INVOKE", target = "Lnet/neoforged/fml/ModLoader;postEventWrapContainerInModOrder(Lnet/neoforged/bus/api/Event;)V")) |
37 | 38 | private static <T extends Event & IModBusEvent> void swapThreadAndPost(ModLoader loader, T event) { |
38 | 39 | RegisterEvent registryEvent = (RegisterEvent)event; |
39 | | - var pb = StartupMessageManager.addProgressBar(registryEvent.getRegistryKey().location().toString(), ModList.get().size()); |
40 | | - try { |
41 | | - loader.postEventWithWrapInModOrder(event, (mc, e) -> { |
42 | | - ModLoadingContext.get().setActiveContainer(mc); |
43 | | - pb.label(pb.name() + " - " + mc.getModInfo().getDisplayName()); |
44 | | - pb.increment(); |
45 | | - }, (mc, e) -> { |
46 | | - ModLoadingContext.get().setActiveContainer(null); |
47 | | - }); |
48 | | - } finally { |
49 | | - pb.complete(); |
| 40 | + // We control phases ourselves so we can make a separate progress bar for each phase. |
| 41 | + String registryName = registryEvent.getRegistryKey().location().toString(); |
| 42 | + for(EventPriority phase : EventPriority.values()) { |
| 43 | + var pb = StartupMessageManager.addProgressBar(registryName, ModList.get().size()); |
| 44 | + try { |
| 45 | + ModList.get().forEachModInOrder(mc -> { |
| 46 | + ModLoadingContext.get().setActiveContainer(mc); |
| 47 | + pb.label(pb.name() + " - " + mc.getModInfo().getDisplayName()); |
| 48 | + pb.increment(); |
| 49 | + var bus = mc.getEventBus(); |
| 50 | + if(bus != null) { |
| 51 | + bus.post(phase, event); |
| 52 | + } |
| 53 | + ModLoadingContext.get().setActiveContainer(null); |
| 54 | + }); |
| 55 | + } finally { |
| 56 | + pb.complete(); |
| 57 | + } |
50 | 58 | } |
| 59 | + |
51 | 60 | } |
52 | 61 | } |
0 commit comments