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();
}
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());
}
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();
}
}
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();
}
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;
}
}
Aggregations