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)


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.

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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • @Mod.EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT) public class ClientEvents { @SubscribeEvent public static void camera(ViewportEvent.ComputeCameraAngles event) { event.setRoll(180f); } }  
    • @SubscribeEvent public static void onRenderTick(TickEvent.RenderTickEvent event) { Player player = Minecraft.getInstance().player; if (player != null) { Vec2 rotation = new Vec2(player.getXRot(), player.getYRot()); Vec2 addition = Vec2Rot(new Vec3(0, 0, 0.01)); player.setXRot(rotation.x + addition.x); player.setYRot(rotation.y + addition.y); } } So i was thinking that minecraft camera rotation is kinda boring so i try to make it rotate on z-axis (like how it did when the player get damage), i soonly writing codes to test it and the x, y works fine but when i try to set the z rotation, there is no setZRot method. I went to find class like Renderers, Camera, etc in the sources but still can't find how to do it. Does anyone know how to do it, or is this not possible?
    • Hello, I have a block entity that is using entity.teleportTo(x, y, z); to teleport an entity(Armor Stand in this case) into a chunk that's being kept loaded with ForgeChunkManager.forceChunk(level.getServer().getLevel(Level.OVERWORLD), StargateJourney.MODID, getBlockPos(), level.getChunk(getBlockPos()).getPos().x, level.getChunk(getBlockPos()).getPos().z, true, true); It works well, however, when I teleport the player alongside the entity, the entity doesn't load. It's still there, because if the player leaves to unload the chunk and then returns, the entity appears where it should. I've tried fixing it by not forceloading the chunk and the entity loads without problems, but I actually need to have the chunk loaded, because I have a block entity in said chunk, that is ticking(essentially, it's the second end of a teleporter mechanism). Is there a workaround to load the entity manually or even better, have it never unload in the first place?
    • Apologies, but as this is written with MCreator, we do not support it on this forum. Please ask their support forums for help.
    • Google the IDE and look up the features necessary to do so. There is plenty of text and videos about how to use it. Everything is written by volunteers and they have to be maintained by volunteers. Additionally, when it comes to the official docs or the community wiki, there are only so many people who have time and are willing to do that. It requires a lot of research to be able to write something competent without providing copy-paste elements. So, unless you're willing to hire people to do so, contribute to the people who keep Forge going, or write some yourself, expect that there probably won't be any documentation for anything besides from simple elements.
  • Topics

  • Create New...

Important Information

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