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.