Search in sources :

Example 1 with SteppedTask

use of me.shedaniel.betterloadingscreen.api.step.SteppedTask in project BetterLoadingScreen by shedaniel.

the class MixinForgeHooksClient method postEvent.

@Redirect(method = "onModelBake", remap = false, at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/ModLoader;postEvent(Lnet/minecraftforge/eventbus/api/Event;)V"))
private static void postEvent(ModLoader modLoader, Event event) {
    ((MinecraftStub) Minecraft.getInstance()).moveRenderOut();
    if (!ModLoader.isLoadingStateValid()) {
        return;
    }
    SteppedTask task = LoadGameSteps.finalizeModel();
    try {
        Method method = ModContainer.class.getDeclaredMethod("acceptEvent", Event.class);
        method.setAccessible(true);
        ModList list = ModList.get();
        int[] count = { 0 };
        list.forEachModContainer((s, container) -> {
            count[0]++;
        });
        task.setTotalSteps(count[0]);
        list.forEachModContainer((id, mc) -> {
            task.setCurrentStepInfo(list.getModContainerById(mc.getModId()).map(ModContainer::getModInfo).map(IModInfo::getDisplayName).orElse(id));
            try {
                method.invoke(mc, event);
            } catch (Throwable e) {
                e.printStackTrace();
            } finally {
                task.incrementStep();
            }
        });
    } catch (Throwable e) {
        e.printStackTrace();
    }
    ((MinecraftStub) Minecraft.getInstance()).moveRenderIn();
}
Also used : SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Method(java.lang.reflect.Method) MinecraftStub(me.shedaniel.betterloadingscreen.impl.mixinstub.MinecraftStub) ModList(net.minecraftforge.fml.ModList) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with SteppedTask

use of me.shedaniel.betterloadingscreen.api.step.SteppedTask in project BetterLoadingScreen by shedaniel.

the class MixinGameData method syncRegistry.

@Inject(method = "freezeData", remap = false, at = @At(value = "INVOKE", target = "Lnet/minecraftforge/registries/GameData;loadRegistry(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraftforge/registries/RegistryManager;Lnet/minecraftforge/registries/RegistryManager;Ljava/lang/Class;Z)V"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void syncRegistry(CallbackInfo ci, Iterator iterator, Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> entry) {
    ParentTask task = LoadGameSteps.finalizeRegistry();
    SteppedTask syncTask = task.stepped(LoadGameSteps.FinalizeRegistry.SYNC);
    syncTask.setCurrentStepInfo(entry.getValue().getRegistryName().toString());
}
Also used : ParentTask(me.shedaniel.betterloadingscreen.api.step.ParentTask) SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with SteppedTask

use of me.shedaniel.betterloadingscreen.api.step.SteppedTask in project BetterLoadingScreen by shedaniel.

the class MixinGameData method onFreezeData.

@Inject(method = "freezeData", remap = false, at = @At("HEAD"))
private static void onFreezeData(CallbackInfo ci) {
    MinecraftStub stub = (MinecraftStub) Minecraft.getInstance();
    stub.moveRenderOut();
    ParentTask task = LoadGameSteps.finalizeRegistry();
    try {
        Field field = RegistryManager.class.getDeclaredField("registries");
        field.setAccessible(true);
        BiMap<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> frozenRegistries = (BiMap<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>>) field.get(RegistryManager.FROZEN);
        BiMap<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> registries = (BiMap<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>>) field.get(RegistryManager.ACTIVE);
        SteppedTask syncTask = task.stepped(LoadGameSteps.FinalizeRegistry.SYNC);
        syncTask.setTotalSteps(registries.size());
        SteppedTask freezeTask = task.stepped(LoadGameSteps.FinalizeRegistry.FREEZE);
        freezeTask.setTotalSteps(frozenRegistries.size() + registries.size());
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : ForgeRegistry(net.minecraftforge.registries.ForgeRegistry) Field(java.lang.reflect.Field) IForgeRegistryEntry(net.minecraftforge.registries.IForgeRegistryEntry) ParentTask(me.shedaniel.betterloadingscreen.api.step.ParentTask) SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) ResourceLocation(net.minecraft.resources.ResourceLocation) BiMap(com.google.common.collect.BiMap) MinecraftStub(me.shedaniel.betterloadingscreen.impl.mixinstub.MinecraftStub) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with SteppedTask

use of me.shedaniel.betterloadingscreen.api.step.SteppedTask in project BetterLoadingScreen by shedaniel.

the class MixinGameData method freezeDataPost.

@Inject(method = { "lambda$freezeData$4", "lambda$freezeData$5", "lambda$freezeData$8", "lambda$freezeData$9" }, remap = false, at = @At(value = "RETURN"))
private static void freezeDataPost(ResourceLocation id, ForgeRegistry registry, CallbackInfo ci) {
    ParentTask task = LoadGameSteps.finalizeRegistry();
    SteppedTask freezeTask = task.stepped(LoadGameSteps.FinalizeRegistry.FREEZE);
    freezeTask.incrementStep();
}
Also used : ParentTask(me.shedaniel.betterloadingscreen.api.step.ParentTask) SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with SteppedTask

use of me.shedaniel.betterloadingscreen.api.step.SteppedTask in project BetterLoadingScreen by shedaniel.

the class MixinMinecraft method init.

@Redirect(at = @At(value = "INVOKE", target = "Lnet/fabricmc/loader/impl/game/minecraft/Hooks;startClient(Ljava/io/File;Ljava/lang/Object;)V"), method = "<init>")
private void init(File runDir, Object gameInstance) {
    if (runDir == null) {
        runDir = new File(".");
    }
    FabricLoaderImpl.INSTANCE.prepareModInit(runDir.toPath(), gameInstance);
    SteppedTask common = LoadGameSteps.initMods().stepped(LoadGameSteps.InitMods.COMMON);
    SteppedTask client = LoadGameSteps.initMods().stepped(LoadGameSteps.InitMods.CLIENT);
    Supplier<RuntimeException> commonRun = invoke("main", ModInitializer.class, LoadGameSteps.InitMods.COMMON, count -> {
        if (count == 0) {
            common.setTotalSteps(1);
            common.setCurrentStep(1);
        } else {
            common.setTotalSteps(count);
        }
    }, (mod, init) -> {
        init.onInitialize();
    });
    Supplier<RuntimeException> clientRun = invoke("client", ClientModInitializer.class, LoadGameSteps.InitMods.CLIENT, count -> {
        if (count == 0) {
            client.setTotalSteps(1);
            client.setCurrentStep(1);
        } else {
            client.setTotalSteps(count);
        }
    }, (mod, init) -> {
        init.onInitializeClient();
    });
    RuntimeException throwable = commonRun.get();
    if (throwable != null) {
        throw throwable;
    }
    throwable = clientRun.get();
    if (throwable != null) {
        throw throwable;
    }
}
Also used : SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) File(java.io.File) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

SteppedTask (me.shedaniel.betterloadingscreen.api.step.SteppedTask)18 Inject (org.spongepowered.asm.mixin.injection.Inject)12 ParentTask (me.shedaniel.betterloadingscreen.api.step.ParentTask)8 Field (java.lang.reflect.Field)4 Map (java.util.Map)3 MinecraftStub (me.shedaniel.betterloadingscreen.impl.mixinstub.MinecraftStub)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 File (java.io.File)2 LoadGameSteps (me.shedaniel.betterloadingscreen.api.step.LoadGameSteps)2 ModelBakeryStub (me.shedaniel.betterloadingscreen.impl.mixinstub.ModelBakeryStub)2 Minecraft (net.minecraft.client.Minecraft)2 Block (net.minecraft.world.level.block.Block)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 ModList (net.minecraftforge.fml.ModList)2 IModInfo (net.minecraftforge.forgespi.language.IModInfo)2 Mixin (org.spongepowered.asm.mixin.Mixin)2 At (org.spongepowered.asm.mixin.injection.At)2 BiMap (com.google.common.collect.BiMap)1 Iterables (com.google.common.collect.Iterables)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1