Jump to content

[1.12.2] [SOLVED] A problem with assigning textures to more than 1 item


Recommended Posts

Posted (edited)

So I managed to add a texture to one item, but then I added a second item and its texture isnt displayed while the first items texture changed.

 

The trouble code is this:

@SideOnly(Side.CLIENT)
	public static void initClient()
	{
		ModelLoader.setCustomModelResourceLocation(Items.Bs[0], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[0], "inventory"));
		ModelLoader.setCustomModelResourceLocation(Items.Bs[1], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[1], "inventory"));
	}

All the lines work as intended if I comment out the other line, but together they just do not.

To clarify:

if I have first line on, my first item has a correct texture [second, obviously, has none (the purple/black one)]

If I have the second one on, the second item has a correct texture while the first has none.

If I have both lines on, the first item has the second items texture.

Items.Bs[] is a list of custom Items with an overriden line for toolTips.

Items class is not Minecraft.init.items, its a custom class

I create my items in this function:

public static void setProperties(int stacksize, CreativeTabs ct)
	{
		permafrost_mod_item B = new permafrost_mod_item();
		B.setUnlocalizedName(Names.item_B[Items.idcounter]);
		B.setMaxStackSize(stacksize);
		B.setCreativeTab(ct);
		B.setRegistryName(new ResourceLocation(Permafrost.MOD_ID, Names.item_B[Items.idcounter]));
		B.id = Items.idcounter;
		Items.Bs[Items.idcounter] = B;
		
		Items.idcounter++;
	}

The method is invoked in preInit at ClientProxy.

 

 

Please help, I just do not see anything that could be wrong...

 

 

Fixed!

Problem still unknown, but using another method works:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Items.Bs[0], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[0], "inventory"));
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Items.Bs[1], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[1], "inventory"));

 

Edited by Flutterish
Posted (edited)

When I create a ModelResourceLocation, I pass in the registry name:

		ModelResourceLocation location = new ModelResourceLocation(item.getRegistryName(), id);
		System.out.println("setting resource location for model " +  item.getUnlocalizedName());
		ModelLoader.setCustomModelResourceLocation(item, metadata, location);

 

The name, unlocalized name and registry name are all the same value:   The name of the json without extension.

setRegistryName already modifies the name to avoid collisions.

 

Edit:  I should clarify

	public ItemBase(String name)
	{
		this.name = name;
		setUnlocalizedName(name);
		setRegistryName(name);

 

Edited by jhdoran
Clarification with an example
Posted (edited)
24 minutes ago, jhdoran said:

When I create a ModelResourceLocation, I pass in the registry name:


		ModelResourceLocation location = new ModelResourceLocation(item.getRegistryName(), id);
		System.out.println("setting resource location for model " +  item.getUnlocalizedName());
		ModelLoader.setCustomModelResourceLocation(item, metadata, location);

 

The name, unlocalized name and registry name are all the same value:   The name of the json without extension.

setRegistryName already modifies the name to avoid collisions.

 

Edit:  I should clarify


	public ItemBase(String name)
	{
		this.name = name;
		setUnlocalizedName(name);
		setRegistryName(name);

 

Why would I want to get what model is loading tho? All models work correctly alone, its just that they dont work together.

Let me show you:

only first item loaded:

Spoiler

EAnT87Z.png

second item loaded:

Spoiler

5Ns9XAB.png

both loaded:

Spoiler

Jn9SX9Y.png

Also, yes I did try to set the names to be the same, nothing changed.

Edited by Flutterish
Posted

You are describing a problem with model loading (the textures are associated with the models).  Loading a second model damages the first.  So I look to see how you are
loading the models, and see that the names don't look right.  The names must match the JSON.

 

So for example, if I am adding a stick:

 

The item constructor sets the name to "stick",  calls setUnlocalizedName("stick"), and setRegistryName("stick").  These values will be adjusted as needed.

My stick.json is then used.

 

If I mess up the name, then a number of things can happen, and will be reflected in the log file.  Do you see JSON load exceptions?    I'm just reacting to what seems excessive manipulation of the item name.  Put a breakpoint before the call to setCustomModelResourceLocation and see what the location is.

Posted
9 minutes ago, jhdoran said:

You are describing a problem with model loading (the textures are associated with the models).  Loading a second model damages the first.  So I look to see how you are
loading the models, and see that the names don't look right.  The names must match the JSON.

 

So for example, if I am adding a stick:

 

The item constructor sets the name to "stick",  calls setUnlocalizedName("stick"), and setRegistryName("stick").  These values will be adjusted as needed.

My stick.json is then used.

 

If I mess up the name, then a number of things can happen, and will be reflected in the log file.  Do you see JSON load exceptions?    I'm just reacting to what seems excessive manipulation of the item name.  Put a breakpoint before the call to setCustomModelResourceLocation and see what the location is.

They do match the json file, how else would they load? Did you look at the pictures I provided?

Posted

Yes I did look at the pictures, but I would rather look at code.  I commented on the code you posted.  And since setRegistryName creates a resource location, creating one yourself before setting the name is going to create a rather messed up JSON name.  But you said it is correct.  And you didn't mention looking at the logs for exceptions.  Or printing out the name.  Or setting a breakpoint and checking...

Posted (edited)
24 minutes ago, jhdoran said:

Yes I did look at the pictures, but I would rather look at code.  I commented on the code you posted.  And since setRegistryName creates a resource location, creating one yourself before setting the name is going to create a rather messed up JSON name.  But you said it is correct.  And you didn't mention looking at the logs for exceptions.  Or printing out the name.  Or setting a breakpoint and checking...

Thats because there were no exceptions. I printed out the name, it was exacly as I set it. I did the checking earlier, I said it works when either one is commented out, but not when both are called.

 

ok, also there are two methods:

public static void init() 
	{
		Items.idcounter = 0;
		setProperties(69, Permafrost.MOD_ID + ":B_tab", 0);
		setProperties(16, CreativeTab.B_tab[0]);
		
		//CreativeTab.makeTab(Permafrost.MOD_ID + ":B_tab", new ItemStack(Bs[0]));
		GameRegistry.addShapedRecipe(new ResourceLocation(Permafrost.MOD_ID, Names.item_B[0]), null, new ItemStack(Bs[0], 1), "AAA", "AAA", "AAA", 'A', Blocks.DIAMOND_BLOCK);
		GameRegistry.addShapedRecipe(new ResourceLocation(Permafrost.MOD_ID, Names.item_B[0]+"b"), null, new ItemStack(Blocks.DIAMOND_BLOCK, 9), "A", 'A', Bs[0]);
	}
	
	@SideOnly(Side.CLIENT)
	public static void initClient()
	{
		ModelLoader.setCustomModelResourceLocation(Items.Bs[0], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[0], "inventory"));
		ModelLoader.setCustomModelResourceLocation(Items.Bs[1], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[1], "inventory"));
	}

the top one is called first. Both in preInit. Maybe that helps.

Dont worry about the setProperties with what seems to be invalid arguments, this is just another method used to autocreate a creative tab with initiated item as its icon.

Edited by Flutterish
Posted

Fixed it!

The problem was, I dont really know what, but I used the Minecraft method and it worked. Had to also move it to Init.

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Items.Bs[0], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[0], "inventory"));
		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Items.Bs[1], 0, new ModelResourceLocation(Permafrost.RESOURCE_PREFIX + Names.item_B[1], "inventory"));

 

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.