Search in sources :

Example 1 with ParentTask

use of me.shedaniel.betterloadingscreen.api.step.ParentTask 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 2 with ParentTask

use of me.shedaniel.betterloadingscreen.api.step.ParentTask 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 3 with ParentTask

use of me.shedaniel.betterloadingscreen.api.step.ParentTask 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 4 with ParentTask

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

the class MixinMinecraft method invoke.

@Unique
private static <T> Supplier<RuntimeException> invoke(String name, Class<T> type, StatusIdentifier<SteppedTask> taskId, IntConsumer total, BiConsumer<ModContainer, ? super T> invoker) {
    ParentTask initMods = LoadGameSteps.initMods();
    Collection<EntrypointContainer<T>> entrypoints = FabricLoader.getInstance().getEntrypointContainers(name, type);
    Multimap<String, EntrypointContainer<T>> map = LinkedHashMultimap.create();
    SteppedTask task = initMods.stepped(taskId);
    for (EntrypointContainer<T> container : entrypoints) {
        ModMetadata metadata = container.getProvider().getMetadata();
        map.put(metadata.getId(), container);
    }
    total.accept(map.keySet().size());
    return () -> {
        RuntimeException exception = null;
        for (Map.Entry<String, Collection<EntrypointContainer<T>>> entry : map.asMap().entrySet()) {
            task.setCurrentStepInfo(Iterables.getFirst(entry.getValue(), null).getProvider().getMetadata().getName());
            for (EntrypointContainer<T> container : entry.getValue()) {
                try {
                    invoker.accept(container.getProvider(), container.getEntrypoint());
                } catch (Throwable t) {
                    exception = ExceptionUtil.gatherExceptions(t, exception, exc -> new RuntimeException(String.format("Could not execute entrypoint stage '%s' due to errors, provided by '%s'!", name, container.getProvider().getMetadata().getId()), exc));
                }
            }
            task.incrementStep();
        }
        return exception;
    };
}
Also used : FabricLoader(net.fabricmc.loader.api.FabricLoader) Iterables(com.google.common.collect.Iterables) EntrypointContainer(net.fabricmc.loader.api.entrypoint.EntrypointContainer) Unique(org.spongepowered.asm.mixin.Unique) IntConsumer(java.util.function.IntConsumer) Multimap(com.google.common.collect.Multimap) Supplier(java.util.function.Supplier) Minecraft(net.minecraft.client.Minecraft) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) ModContainer(net.fabricmc.loader.api.ModContainer) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) LoadGameSteps(me.shedaniel.betterloadingscreen.api.step.LoadGameSteps) ExceptionUtil(net.fabricmc.loader.impl.util.ExceptionUtil) At(org.spongepowered.asm.mixin.injection.At) ClientModInitializer(net.fabricmc.api.ClientModInitializer) Redirect(org.spongepowered.asm.mixin.injection.Redirect) Collection(java.util.Collection) ModInitializer(net.fabricmc.api.ModInitializer) File(java.io.File) ParentTask(me.shedaniel.betterloadingscreen.api.step.ParentTask) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) FabricLoaderImpl(net.fabricmc.loader.impl.FabricLoaderImpl) StatusIdentifier(me.shedaniel.betterloadingscreen.api.StatusIdentifier) Shadow(org.spongepowered.asm.mixin.Shadow) SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) EntrypointContainer(net.fabricmc.loader.api.entrypoint.EntrypointContainer) ParentTask(me.shedaniel.betterloadingscreen.api.step.ParentTask) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) Unique(org.spongepowered.asm.mixin.Unique)

Example 5 with ParentTask

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

the class MixinModelBakeryFabric method init.

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V", ordinal = 0))
private void init(ResourceManager resourceManager, BlockColors blockColors, ProfilerFiller profilerFiller, int i, CallbackInfo ci) {
    int stateCount = 0, itemCount = Registry.ITEM.size();
    for (Block block : Registry.BLOCK) {
        stateCount += block.getStateDefinition().getPossibleStates().size();
    }
    ParentTask task = LoadGameSteps.loadModel();
    SteppedTask blockTask = task.stepped(LoadGameSteps.LoadModel.BLOCK);
    blockTask.setTotalSteps(stateCount);
    SteppedTask itemTask = task.stepped(LoadGameSteps.LoadModel.ITEM);
    itemTask.setTotalSteps(itemCount);
    ((ModelBakeryStub) this).betterloadingscreen$setBlockTask(blockTask);
    ((ModelBakeryStub) this).betterloadingscreen$setItemTask(itemTask);
}
Also used : ParentTask(me.shedaniel.betterloadingscreen.api.step.ParentTask) SteppedTask(me.shedaniel.betterloadingscreen.api.step.SteppedTask) ModelBakeryStub(me.shedaniel.betterloadingscreen.impl.mixinstub.ModelBakeryStub) Block(net.minecraft.world.level.block.Block) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ParentTask (me.shedaniel.betterloadingscreen.api.step.ParentTask)11 Inject (org.spongepowered.asm.mixin.injection.Inject)9 SteppedTask (me.shedaniel.betterloadingscreen.api.step.SteppedTask)8 ModelBakeryStub (me.shedaniel.betterloadingscreen.impl.mixinstub.ModelBakeryStub)2 StitcherStub (me.shedaniel.betterloadingscreen.impl.mixinstub.StitcherStub)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Block (net.minecraft.world.level.block.Block)2 Unique (org.spongepowered.asm.mixin.Unique)2 BiMap (com.google.common.collect.BiMap)1 Iterables (com.google.common.collect.Iterables)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Multimap (com.google.common.collect.Multimap)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 Map (java.util.Map)1 BiConsumer (java.util.function.BiConsumer)1 IntConsumer (java.util.function.IntConsumer)1 Supplier (java.util.function.Supplier)1 StatusIdentifier (me.shedaniel.betterloadingscreen.api.StatusIdentifier)1