Jump to content

Creating an ItemStack for armor texturing


satyreyes

Recommended Posts

I'm trying to get my armor to render correctly, and I'm running into what's probably a basic problem.  The method I'm using to get the texture, which I think is all right, is:

 

public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){
	if(stack.getItem() == Heart.heartstoneChestplate) {
				return "tutorial:textures/models/armor/heartstone_1.png";
	}
	  else
		return null;
	}

 

The problem comes when I actually try to call this method, from my main mod file:

 

heartstoneChestplate = new ItemArmor(HEARTSTONE, proxy.addArmor("heartstone"), 1)
		.getArmorTexture(new ItemStack(this.heartstoneChestplate), null, 1, "heartstone");

 

...Which underlines the whole definition in red and invites me to change heartstoneChestplate to a string rather than an item.  The problem seems to be tied to the "new ItemStack" part.  Am I calling ItemStack incorrectly?  Is new the wrong keyword to use here?

 

Thanks for your help!  :D

Link to comment
Share on other sites

I hang my head in shame; in hindsight, yeah, trying to create an ItemStack of the object before the object was initialized was probably not the best idea.  But I have no idea what to do instead.  :(

 

Create a new class which extends ItemArmor, override the method and put your code in there. Example:

https://github.com/SanAndreasP/EnderStuffPlus/blob/master/java/sanandreasp/mods/EnderStuffPlus/item/ItemNiobArmor.java#L26-L36

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Thank you very much.  There is nothing like seeing a working example!  I have it working, and I understand Java better now to boot.

 

(Anyone who stumbles on this thread later: stack.itemID, which is used in the linked example to identify the armor we're looking at, no longer works.  We now test this with stack.getItem() == Yourmod.exampleItem.)

Link to comment
Share on other sites

Thank you very much.  There is nothing like seeing a working example!  I have it working, and I understand Java better now to boot.

 

(Anyone who stumbles on this thread later: stack.itemID, which is used in the linked example to identify the armor we're looking at, no longer works.  We now test this with stack.getItem() == Yourmod.exampleItem.)

 

Glad I could help.

By the way, I'm currently refractoring the mod, so there's a cleaned up version here:

https://github.com/SanAndreasP/EnderStuffPlus/blob/code-cleanup/java/sanandreasp/mods/EnderStuffPlus/item/ItemNiobArmor.java#L29-L39

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.