Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Getting texture from an item as an image and exporting it (1.18.2)


Greenem
 Share

Recommended Posts

I have and Item/ItemStack and I need to get it's texture as an usual image. (I'm quite new to modding)
I tried doing random stuff with ResourceLocation, ItemRenderer and BlockRenderDispatcher, but didn't succeed. I know that now it's all models and not textures (and some other info), but I'm just too new to this to know what ways to do this exist
Can you help me?

Link to comment
Share on other sites

Posted (edited)

Thanks, but I sill don't understand some details
I tried your way and created this:

Player p = Minecraft.getInstance().player;
Item item = p.getInventory().getSelected().getItem();
Block b = Block.byItem(item);
Minecraft.getInstance().getItemRenderer().getModel(item.getDefaultInstance(), p.getLevel(), p, 1).getQuads(b.defaultBlockState(), Direction.NORTH, new Random()).get(0).getSprite()

But what are the 4th argument in getModel(...) and 3rd argument in getQuads(...)? Am I using all of this in any supposed way? (I just don't know what to put in the arguments) Anyway, this (somehow) gives me the TextureAtlasSprite, but how can I save it to png file?

Edited by Greenem
Link to comment
Share on other sites

Why are you first getting the Item from the ItemStack only to then convert it back to its default ItemStack using getDefaultInstance? Use the ItemStack you get in the first place.

For item models obviously it doesn't make sense to pass in a BlockState, so pass null for that parameter. Same for the direction. Do not create a new Random instance every time. For item models the IModelData is also not used.

Link to comment
Share on other sites

22 minutes ago, Greenem said:

Anyway, this (somehow) gives me the TextureAtlasSprite, but how can I save it to png file?

TextureAtlasSprite has an array of NativeImages which you can access using reflection. However Forge allows custom TAS implementations, which might not be image-backed at all.

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
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.

 Share



×
×
  • Create New...

Important Information

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