Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

To do something after all mods have been loaded

Featured Replies

Posted

Hello.

In my mod I need run method after all mods have been loaded, the reason is EntityType.byKey method.

Briefly, mod is rendering mob's icons, where and why doesn't matter. Generation of these icons is not the fastest thing, so mod generate them once and save as files, and using IResourcePack implementation then.

For rendering icons im using hashmap with EntityType as a key (to check should I render it or not), I tested and it is faster than using some sort of EntityType string as a key.

So, I was trying to load all those icons in init state, but EntityTypes doesn't exists until mod is loaded (we are talking about external mods), I can't add mods in dependecies because it is a dynimic thing (excepts there is a way to add dependecies in mod constructor).

 

My solution is not perfect at all, but it works at least, and I'm trying to find something better. (As I said before: way to add dependecies in constructor, for example).

 

My solution:

public class FirstMainMenuOpenEvent {
    @SubscribeEvent
    public void onGuiOpen(GuiOpenEvent event){
        if(event.getGui()instanceof MainMenuScreen){
            HeadUtils.loadModHeads();
            MinecraftForge.EVENT_BUS.unregister(this);
        }
    }
}

 

So I register it once in init state, then it runs once and remove itself.

Edited by DmitryLovin

  • Author
10 hours ago, lupicus said:

Maybe try using FMLLoadCompleteEvent

As I know, it calls when fml (forge mod loader) finish to load itself, so even before mods start to load.

  • Author
23 hours ago, DmitryLovin said:
On 3/4/2021 at 4:18 AM, lupicus said:

Maybe try using FMLLoadCompleteEvent

As I know, it calls when fml (forge mod loader) finish to load itself, so even before mods start to load.

Sorry I was wrong.

 

13 hours ago, diesieben07 said:

Do not use this method. Use ForgeRegistries.ENTITIES to access the entity type registry

This thing works fine, thanks, but now my IResourcePack implementation method doesn't work. I guess I do it absolutely wrong:

 

for(HeadPack pack:ipack){
    ((SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addResourcePack(pack);
}
((SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addReloadListener((s,rM,pP,rP,bE,gE)->{
    return CompletableFuture.
            supplyAsync(() ->{return null;}, bE).
            thenCompose(s::markCompleteAwaitingOthers).
            thenAcceptAsync((p_215269_3_) -> {reloadPack(rM);}, gE);});

Edited by DmitryLovin

  • Author

Well, I kinda fixed it:

for(HeadPack pack:ipack){
    Minecraft.getInstance().getResourcePackList().addPackFinder(
            (infoConsumer, infoFactory) -> {
                infoConsumer.accept(infoFactory.create(pack.getName(), true,()->pack,pack, new PackMetadataSection(new StringTextComponent(pack.getName()),6),ResourcePackInfo.Priority.BOTTOM,IPackNameDecorator.BUILTIN));
            }
    );
}

But it works only after I reload packs or something, keep looking what I did wrong.

 

upd:

I guess I still need to add it in ResourceManager manually like before as well:

((SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addResourcePack(pack);

because minecraft do it only when you reload resourcepacks or change them.

Can be closed.

Edited by DmitryLovin

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.