Jump to content

1.8: Registering textures for metadata-based items


endreman0

Recommended Posts

I am attempting to create an item that will have a different texture for each metadata value.

ItemBase

(the item):

 

 

package io.github.endreman0.endermagnetics.item;

public class ItemBase extends ItemMetadataEM{
public ItemBase(){
	super("machineBase", "tier1", "tier2");
}
}

 

 

ItemMetadataEM

(base class for every item that uses metadata):

 

 

package io.github.endreman0.endermagnetics.item;

import java.util.List;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemMetadataEM extends ItemEM{
protected final String[] variants;
public ItemMetadataEM(String name, String... variants){
	super(name);
	this.variants = variants;
	setHasSubtypes(true);
}
public ItemMetadataEM(String name, int stackSize, String... variants){
	super(name, stackSize);
	this.variants = variants;
}
public int variants(){return variants.length;}
public String variant(int index){return variants[index];}
@Override public String getUnlocalizedName(ItemStack stack){return super.getUnlocalizedName(stack) + "_" + variants[stack.getItemDamage()];}
@Override @SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list){
	for(int i=0; i<variants.length; i++) list.add(new ItemStack(item, 1, i));
}
}

 

 

ItemEM

(base class for all items in the mod):

 

 

package io.github.endreman0.endermagnetics.item;

import io.github.endreman0.endermagnetics.EnderMagnetics;
import io.github.endreman0.endermagnetics.util.Utility;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class ItemEM extends Item{
protected final String name;
public ItemEM(String name){this(name, 64);}
public ItemEM(String name, int stackSize){
	super();
	this.name = name;
	setUnlocalizedName(EnderMagnetics.MOD_ID + ":" + name);
	this.maxStackSize = stackSize;
	setCreativeTab(Utility.CREATIVE_TAB);
}
public String getName(){return name;}
}

 

 

ItemsEM

(holds the item instance and registers items in preinit phase):

 

 

package io.github.endreman0.endermagnetics.item;

import net.minecraft.client.resources.model.ModelBakery;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ItemsEM{
public static final ItemWrench wrench = new ItemWrench();
public static final ItemBase base = new ItemBase();
public static void init(){
	register(wrench);
	register(base);
}
private static void register(ItemEM item){
	GameRegistry.registerItem(item, item.getName());
	if(item instanceof ItemMetadataEM){
		ItemMetadataEM metaItem = (ItemMetadataEM)item;
		String[] variants = new String[metaItem.variants()];
		for(int i=0; i<variants.length; i++) variants[i] = metaItem.getUnlocalizedName() + "_" + metaItem.variant(i);
		ModelBakery.addVariantName(metaItem, variants);
	}
}
}

 

 

ClientProxy

(registers item renders in init phase):

 

 

package io.github.endreman0.endermagnetics;

import io.github.endreman0.endermagnetics.block.BlockEM;
import io.github.endreman0.endermagnetics.block.BlocksEM;
import io.github.endreman0.endermagnetics.item.ItemEM;
import io.github.endreman0.endermagnetics.item.ItemMetadataEM;
import io.github.endreman0.endermagnetics.item.ItemsEM;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;

public class ClientProxy extends CommonProxy{
@Override
public void renders(){
	render(ItemsEM.wrench);
	render(ItemsEM.base);
	render(BlocksEM.blockPearl);
}
private void render(ItemEM item){
	if(item instanceof ItemMetadataEM){
		ItemMetadataEM itemMeta = (ItemMetadataEM)item;
		for(int i=0; i<itemMeta.variants(); i++){
			EnderMagnetics.logger().info("Registering texture for {}#{}", EnderMagnetics.MOD_ID + ":" + item.getName() + "_" + itemMeta.variant(i), "inventory");
			Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, i,
					new ModelResourceLocation(EnderMagnetics.MOD_ID + ":" + item.getName() + "_" + itemMeta.variant(i), "inventory"));
			EnderMagnetics.logger().info("Texture registered");
		}
	}else{
		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0,//Item, metadata,
				new ModelResourceLocation(EnderMagnetics.MOD_ID + ":" + item.getName(), "inventory"));//location (file name, render type)
	}
}
private void render(BlockEM block){
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0,
			new ModelResourceLocation(EnderMagnetics.MOD_ID + ":" + block.getName(), "inventory"));
}
}

 

 

machineBase_tier1.json

(in

assets/endermagnetics/models/item

):

 

 

{
"parent": "builtin/generated",
"textures": {
	"layer0": "endermagnetics:items/machineBase_tier1"
},
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 1.7, 1.7, 1.7 ]
        }
    }
}

 

 

machineBase_tier2.json

is the same, except the texture link is to

machineBase_tier2

. Both textures exist in

assets/endermagnetics/textures/items

, and are named exactly as their JSON counterparts are (not including the extension, of course).

When the game loads, the log shows my texture registration happening immediately after Minecraft searches for (and can't find the textures). Here's that section of the log:

 

 

[12:14:37] [Client thread/ERROR] [FML]: Model definition for location item.endermagnetics:machineBase_tier1#inventory not found

[12:14:37] [Client thread/ERROR] [FML]: Model definition for location item.endermagnetics:machineBase_tier2#inventory not found

[12:14:38] [Client thread/INFO] [endermagnetics]: Registering texture for endermagnetics:machineBase_tier1#inventory

[12:14:38] [Client thread/INFO] [endermagnetics]: Texture registered

[12:14:38] [Client thread/INFO] [endermagnetics]: Registering texture for endermagnetics:machineBase_tier2#inventory

[12:14:38] [Client thread/INFO] [endermagnetics]: Texture registered

 

 

The two "not found" lines are also shown farther down in the log.

 

 

[12:14:43] [Client thread/INFO] [FML]: Max texture size: 8192

[12:14:44] [Client thread/INFO]: Created: 512x512 textures-atlas

[12:14:44] [Client thread/ERROR] [FML]: Model definition for location item.endermagnetics:machineBase_tier1#inventory not found

[12:14:44] [Client thread/ERROR] [FML]: Model definition for location item.endermagnetics:machineBase_tier2#inventory not found

 

 

Am I registering the textures at the wrong time? The wrong way?

Link to comment
Share on other sites

Sorry to not give straight answer, but that's a lot of text to go through.

 

Since you know your code it might be faster to just give example:

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe11_item_variants

 

Check out resources:

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/resources/assets/minecraftbyexample

 

You sure you got all variants in json files? Hm, just look at example, pretty much perfect one.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Thanks, that helped me fix it! The issue was using

item.getUnlocalizedName()

. This prepends

"item."

to the actual name, which isn't supposed to be there for model registry. I swapped it for

MOD_ID + ":" + item.getName()

and it worked.

 

Also, that looks like a great reference. Thanks for showing it to me!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sup,i use forge 47.2.30 for 1.20.1 and i got this crash error :  https://pastebin.com/SMxVrV3E May someone help me ? Thank you !
    • 🎰 Mainkan Slot Online dengan Hanya 5 Ribu Via Dana, Proses Cepat! 🎰 Buka pintu ke dunia hiburan tanpa batas di UANG69 Slot Online! Bersiaplah untuk merasakan sensasi kemenangan di ujung jari Anda dengan taruhan serendah 5 ribu rupiah saja, melalui metode pembayaran yang mudah via Dana! ⚡ Proses Cepat, Nikmati Keuntungan dalam Sekejap ⚡ Bergabunglah dengan komunitas slot paling dinamis dan terpanas, dengan puluhan permainan slot yang menakjubkan, serta kesempatan untuk memenangkan jackpot besar! Rasakan gemerlapnya Las Vegas langsung dari kenyamanan rumah Anda sendiri. 🔥 Keunggulan UANG69 Slot Online: 🔥 ✅ Taruhan Serendah 5 Ribu Rupiah ✅ Metode Pembayaran Mudah via Dana ✅ Proses Cepat, Penarikan Lancar ✅ Puluhan Permainan Slot Terbaik ✅ Jackpot Besar Menanti untuk Dimenangkan Bergabunglah dengan UANG69 hari ini dan jadilah bagian dari petualangan slot yang tak terlupakan. Nikmati keseruan, kemenangan, dan hiburan di ujung jari Anda! Jangan lewatkan kesempatan ini, bergabunglah sekarang dan mulailah memenangkan hadiah besar! 💰💎🎉
    • Hello, I am trying to play Minecraft (premium version) with the All Of Create mod from CurseForge. When I launch it from the Minecraft launcher I get an error "The game has stopped working" Error code: 1. I tried to create a modpack, without mods, and launch it (in case there was any incompatibility) but it doesn't work either.... Error with mod: https://paste.ee/p/zzvJY I hope someone can help me. Thanks in advance.
    • Jika Anda mencari maxwin secepat kilat, maka Slot Kilat77 adalah tempatnya! Dengan koleksi slot terbaik yang dirancang untuk memberikan kemenangan instan, setiap putaran di Slot Kilat77 adalah kesempatan untuk memenangkan hadiah besar dalam sekejap. Bergabunglah sekarang dan rasakan sensasi kemenangan kilat di setiap gulungan. Jadi, jangan ragu lagi, mari bergabung dan raih maxwin secepat kilat hanya di Slot Kilat77!
    • Jos77 adalah pilihan terbaik untuk meraih maxwin hari ini! Dengan koleksi permainan slot terbaik dan peluang kemenangan yang tinggi, setiap putaran di Jos77 adalah kesempatan untuk memenangkan hadiah besar. Bergabunglah sekarang dan rasakan sensasi kemenangan yang luar biasa di setiap gulungan. Jadi, jangan lewatkan kesempatan untuk menjadi pemenang hari ini di Jos77 Mulailah petualangan slot Anda sekarang di Jos77 dan temukan sendiri mengapa kami adalah pilihan utama para pencari maxwin. Dengan grafis yang memukau, fitur bonus yang menggiurkan, dan dukungan pelanggan yang luar biasa, kami siap membawa pengalaman bermain Anda ke level berikutnya. Tidak peduli apakah Anda seorang pemula atau ahli slot, Jos77 menyediakan lingkungan yang ramah dan menyenangkan bagi semua pemain. Jadi, bersiaplah untuk meraih maxwin dan nikmati kesuksesan Anda di Jos77 hari ini!  
  • Topics

×
×
  • Create New...

Important Information

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