|
| 1 | +package org.embeddedt.modernfix.forge.mixin.feature.registry_event_progress; |
| 2 | + |
| 3 | +import net.minecraftforge.eventbus.api.Event; |
| 4 | +import net.minecraftforge.fml.ModList; |
| 5 | +import net.minecraftforge.fml.ModLoader; |
| 6 | +import net.minecraftforge.fml.ModLoadingContext; |
| 7 | +import net.minecraftforge.fml.StartupMessageManager; |
| 8 | +import net.minecraftforge.fml.event.IModBusEvent; |
| 9 | +import net.minecraftforge.registries.GameData; |
| 10 | +import net.minecraftforge.registries.RegisterEvent; |
| 11 | +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; |
| 12 | +import org.embeddedt.modernfix.forge.util.AsyncLoadingScreen; |
| 13 | +import org.spongepowered.asm.mixin.Mixin; |
| 14 | +import org.spongepowered.asm.mixin.injection.At; |
| 15 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 16 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | + |
| 19 | +@Mixin(value = GameData.class, remap = false) |
| 20 | +@ClientOnlyMixin |
| 21 | +public class GameDataMixin { |
| 22 | + |
| 23 | + private static AsyncLoadingScreen mfix$asyncScreen; |
| 24 | + |
| 25 | + @Inject(method = "postRegisterEvents", at = @At(value = "INVOKE", target = "Ljava/util/Set;iterator()Ljava/util/Iterator;", ordinal = 0)) |
| 26 | + private static void createAsyncScreen(CallbackInfo ci) { |
| 27 | + mfix$asyncScreen = new AsyncLoadingScreen(); |
| 28 | + } |
| 29 | + |
| 30 | + @Inject(method = "postRegisterEvents", at = @At(value = "INVOKE", target = "Ljava/lang/RuntimeException;getSuppressed()[Ljava/lang/Throwable;", ordinal = 0)) |
| 31 | + private static void closeAsyncScreen(CallbackInfo ci) { |
| 32 | + mfix$asyncScreen.close(); |
| 33 | + mfix$asyncScreen = null; |
| 34 | + } |
| 35 | + |
| 36 | + @Redirect(method = "postRegisterEvents", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/ModLoader;postEventWrapContainerInModOrder(Lnet/minecraftforge/eventbus/api/Event;)V")) |
| 37 | + private static <T extends Event & IModBusEvent> void swapThreadAndPost(ModLoader loader, T event) { |
| 38 | + 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(); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments