Jump to content

[1.12.2] [Solved] Registering Renders for NBT Item Variants


ChampionAsh5357

Recommended Posts

I recently started using nbt data to hold item variants. However, when using ModelLoader.setCustomMeshDefinition and ModelBakery.registerItemVariants, the textures do not render whatsoever. The text that says "modid:location#inventory" does not appear on the not rendered item either. Any help is much appreciated.

 

Render register class:

package com.championash5357.tabletop.event;

import com.championash5357.tabletop.client.Namespace;
import com.championash5357.tabletop.init.Items;
import com.championash5357.tabletop.init.Items.ItemRegistration;
import com.championash5357.tabletop.registry.CardType;
import com.championash5357.tabletop.util.CardUtil;

import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod.EventBusSubscriber(modid = Namespace.ID)
public class Events {

	@SubscribeEvent
	public static void registerModels(final ModelRegistryEvent event) {
		final NonNullList<Item> items = NonNullList.<Item>create();
		items.addAll(ItemRegistration.ITEMS);
		
		for(Item item : items)
			ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
		
		ModelLoader.setCustomMeshDefinition(Items.CARD, new ItemMeshDefinition() {

			@Override
			public ModelResourceLocation getModelLocation(ItemStack stack) {
				String name = CardUtil.getRegistryNameFromNBT(stack);
				return new ModelResourceLocation(stack.getItem().getRegistryName() + "_" + name.split("\\.")[1], "inventory");
			}
			
		});
	}
	
	@SubscribeEvent
	public static void registerVariants(final ModelBakeEvent event) {
		for(CardType card : GameRegistry.findRegistry(CardType.class).getValuesCollection())
			ModelBakery.registerItemVariants(Items.CARD, new ResourceLocation(Namespace.ID, "card_" + card.getRegistryName().getResourcePath().split("\\.")[1]));
	}
}

 

Edited by ChampionAsh5357
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.