Jump to content

[1.9][SOLVED] Why registering models only in pre init?


Elix_x

Recommended Posts

Good day everybody.

I stumbled upon a problem today: why must we register models in pre init?

Due to how my code works, i cannot register them in pre init. And if i register them in init, they don't work.

I have a structure of dynamicaly generated items, depending on configuration and installed mods (including ones that use API to add different types of tool). Any mod can provide tool provider in pre-init and materials are loaded from jsons. Then in init, item for each tool for each material is generated and registered. (Up to this point, everything works). But when i try to register models in init, they don't work. If i move all item registries, and models in pre init, they work... But then nobody can use API, because it is setup and used entirely in pre init.

 

So, why registering item models in init does not work? And what should i do?

 

Note: while i can move materials from item instance to NBT, i cannot move tool types to NBT, as each tool may have different possible usage, thus different classes are needed.

 

Thanks for help!

If you have any questions - just ask!

Link to comment
Share on other sites

I have something similar to this mostly working but the process is somewhat convoluted.

You can look at my code here.

 

You can see most of it in common/draftcore/..., helpers/..., api/

I can try to come up with a path for you to follow to help you understand what is going on.

 

Edit:

this is more or less the path you can follow for looking through the code:

 

*helpers/CommonProxy #preInit, #registerLuxin, #registerCores, #registerParts, #registerItems

They lead to my registries in the API for other mods to use,

a good practice is to use your own api's to accomplish create things.

If something can't be done with your api then expand it so it can be done.

*helpers/ClientProxy #init, you can see me registering my models here

*client/itemrenderers/DraftableModelLoader you will want to use something like this

*client/itemrenderers/DraftableModel yours should be similar to this

*client/itemrenderers/DraftableBakedModel #Quads yours you should be able to almost copy from the default one

*client/itemrenderers/DraftableOverrideList #handleItemState is where you can parse nbt info

 

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

I have something similar to this mostly working but the process is somewhat convoluted.

You can look at my code here.

 

You can see most of it in common/draftcore/..., helpers/..., api/

I can try to come up with a path for you to follow to help you understand what is going on.

 

Edit:

this is more or less the path you can follow for looking through the code:

 

*helpers/CommonProxy #preInit, #registerLuxin, #registerCores, #registerParts, #registerItems

They lead to my registries in the API for other mods to use,

a good practice is to use your own api's to accomplish create things.

If something can't be done with your api then expand it so it can be done.

*helpers/ClientProxy #init, you can see me registering my models here

*client/itemrenderers/DraftableModelLoader you will want to use something like this

*client/itemrenderers/DraftableModel yours should be similar to this

*client/itemrenderers/DraftableBakedModel #Quads yours you should be able to almost copy from the default one

*client/itemrenderers/DraftableOverrideList #handleItemState is where you can parse nbt info

Thanks, i'll take a look at that.

 

One thing though: my models are in jsons (because vanilla is enough).

Link to comment
Share on other sites

I will just say that adding

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, def);

fixed everything (before i was using only

ModelLoader.setCustomModelResourceLocation(item, 0, def);

).

Now models work in init correctly.

Thanks anyways!

Link to comment
Share on other sites

You should not need

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, def)

. What is your code for

ModelLoader.setCustomModelResourceLocation(item, 0, def)

?

	public void init(FMLInitializationEvent event){
	MinecraftForge.EVENT_BUS.register(new LastRenderWorldEvent());

	for(ColoringToolProvider provider : ColoringToolsManager.getProviders()){
		ModelResourceLocation def = provider.getDefaultModel();
		if(def != null){
			for(Item item : (Collection<Item>) ColoringToolsManager.getAllItems(provider)){
				ModelLoader.setCustomModelResourceLocation(item, 0, def);
				Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, def);
				Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new StandartColoringToolItemColor(0, 1), item);
			}
		}
	}
}

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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