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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I've already tried it without mods and it works.
    • i never created a world on singleplayer and I don't see a level.dat file, there's a server.dat file though. but i play multiplayer on my minecraft server with my friends.
    • Add crash-reports with sites like https://mclo.gs/   Make a test without any mods - just Forge
    • Also add the level.dat from your worldsave via sites like mediafire
    • It's the little things that get you sometimes, isn't it? I was actually pretty hyped with my new Bluetooth speaker, ready to see just how well it would sound and pump up my playlist while finishing some work. So, like any other tech enthusiast, I connected it to my laptop, where, of course, my crypto wallet was open and logged in. Big mistake. It was a freakish twist of fate that, well, the Bluetooth speaker seemed to have other plans. It began glitching like a broken record, sending my laptop into a frenzy. I tried reconnecting it, and that's when the disaster struck. In some kind of crazy chain of events, I managed to get locked out of my $90,000 Bitcoin wallet. My wallet was still there, but access was completely blocked. As I sat staring at the screen in utter disbelief, my mind wandered to how something so silly could have caused such a huge mess. Cue the panic. Something this simple, such as a glitch with the speaker, and I don't have access to so much money. The whole thing was just utterly absurd, and I couldn't stop playing the scene over and over in my mind, wishing I'd just have waited until work was done to mess with my new gadget. But it was too late; I was locked out, and the financial chaos was real. Luckily, I knew where to go for help. The very first words in my mind were LEEULTIMATEHACKER @ AOL . COM   telegram: LEEULTIMATE   wh@tsapp +1  (715) 314  -  9248  https :// leeultimatehacker. com I had heard very positive feedback about them regarding their capabilities, and they did not even laugh after several minutes of hearing my story, which, let's face it, sounds utterly ridiculous. Instead, they reassured me that they have seen all kinds of scenarios and can be of assistance with mine. Immediately, I relaxed due to their professionalism. They were very calm, efficient, and started working on my case without wasting even a single second. In some days, they called me back to intimate me with the great news that my $90,000 was safely restored and my wallet was back in my hands. The feeling of relief which I felt was beyond description, knowing well that my ridiculous Bluetooth speaker disaster was finally over. I will make sure gadgets and crypto are in two completely different corners: Now I understand that crypto has absolutely nothing to do with gadgets. Thank the heavens, Lee Ultimate Hacker recovered my funds, at the same time teaching me how to be much more cautious in handling wallets this time around. Not getting caught a second time!
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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