Jump to content

[1.12.2] Retrieving .png texture file corresponding to held item?


Recommended Posts

Posted

Hello all,

 

I am in the process of adding Touch Bar integration to Minecraft. I have the touch bar hooked into the Minecraft window, and have it dynamically show which slot on the hotter is selected. Now, I want to add an icon to the Touch Bar button that corresponds to the held item's icon, but Apple and the JTouchBar API can only accept .png file paths or a byte array. Searching into the conversion of 2D int array textures to a 1D byte array seems fruitless. Is it possible to retrieve the PNG texture of an Item or Block from the ItemStack? So far I have a "TextureAtlasSprite" object, which has a "getIconName()" method, but this returns a string in the format "[domain]:[item_name]" such as "minecraft:diamond". I somehow want this to become a path to "assets/minecraft/textures/items/diamond.png", if it is even possible without extensive String manipulation.

 

Thank you!

Posted
1 hour ago, diesieben07 said:

Once you have the TextureAtlasSprite you know the UV coordinates of the texture in the global texture sheet (TextureMap.LOCATION_BLOCKS_TEXTURE). You then have to bind it (TextureManager::bindTexture) and then you can use glGetTexImage to transfer the OpenGL texture into memory. This data you then have to convert into a png image, possibly using ImageIO from the JDK.


However, this will not work properly for items using a custom model, such as a compass. For those you need to actually render the model and then perform similar steps, effectively making a "screenshot".

Hi,

 

I am not following your process, sadly. I can take the TextureMap, but I cannot seem to piece together how I am supposed to bind the Texturemap and then use OpenGL to get the texture. Attached is a picture of my code.

Screen Shot 2018-03-10 at 6.18.20 PM.png

Posted (edited)

One thing: Couldn't the getFrameTexture be used in order to retrieve a Image Data?

Second: Isn't the TextureAtlasSprite you're retrieving above the one for the Items Particles (like the ones in an Items json file)?

Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(new ResourceLocation("iron_ingot").toString())

Maybe that would retrieve the whole atlas Sprite... (I rember someone saying, that this map isn't named in correspondance to what it does... correct?)

(Probably that Resourcelocation doesn't even Point to iron ingots, It's just there to show the kind of key used by it)

EDIT:

Sry, frameTexture is probably only for a single Frame... :( and if one already has that resourceLocation, there are definitly simple ways to do this... ok sry

Edited by Major Tuvok
Posted
20 hours ago, Major Tuvok said:

One thing: Couldn't the getFrameTexture be used in order to retrieve a Image Data?

Second: Isn't the TextureAtlasSprite you're retrieving above the one for the Items Particles (like the ones in an Items json file)?


Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(new ResourceLocation("iron_ingot").toString())

Maybe that would retrieve the whole atlas Sprite... (I rember someone saying, that this map isn't named in correspondance to what it does... correct?)

(Probably that Resourcelocation doesn't even Point to iron ingots, It's just there to show the kind of key used by it)

EDIT:

Sry, frameTexture is probably only for a single Frame... :( and if one already has that resourceLocation, there are definitly simple ways to do this... ok sry

Your idea isn't half bad, actually. Items on the touch bar cannot be animated due to Apple code restrictions, so pulling the png from the assets pack seemed like the easiest way, until 3D blocks enter the scene.

Posted (edited)

Soo, I've been looking at how Minecraft draws ItemStacks f.e. in GuiContainers how Minecraft handels ItemStack drawing...

I failed to find out, where it set's it's ResourceLocation (GuiContainer simply calls slotIn.getBackgroundLocation, but that only references the TextureMap) ...

But with reference to that Post I've found out, that one should retrieve the Model using:

ItemStack gold = new ItemStack(Items.GOLD_INGOT);
IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(gold);

And that you're right using the ParticleTexture in order to retrieve the AtlasSprite

TextureAtlasSprite sprite = model.getParticleTexture();

One can then bind (with reference to GuiContainer) the TextureMap and draw the AtlasSprite:

Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
new Gui().drawTexturedModalRect(0,0, sprite, 16, 16);

(I'm creating that gui only as an example for drawing it)

Or one could maybe retrieve PixelData:

Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
IntBuffer buffer = BufferUtils.createIntBuffer(16*16);
GL11.glGetTexImage(GL11.GL_TEXTURE_2D,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_INT, buffer);

(The reason why I'm using unsingend Int is, that Java uses every Byte seperatly for colors, so that this result should provide you with  correct Color values.)

Unfortunatly I don't think this will work so easily, because we never specified the AtlasSprite after binding the Texture, correct?

 

Sadly using this Method of accessing the TextureAtlasSprite only works (referring to dieSiebens eralier Post) in Game, so that I can't use it to retrieve parsable Textures during Initialisation... 

Edited by Major Tuvok
Posted
On 3/14/2018 at 1:19 PM, Major Tuvok said:

Soo, I've been looking at how Minecraft draws ItemStacks f.e. in GuiContainers how Minecraft handels ItemStack drawing...

I failed to find out, where it set's it's ResourceLocation (GuiContainer simply calls slotIn.getBackgroundLocation, but that only references the TextureMap) ...

But with reference to that Post I've found out, that one should retrieve the Model using:


ItemStack gold = new ItemStack(Items.GOLD_INGOT);
IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(gold);

And that you're right using the ParticleTexture in order to retrieve the AtlasSprite


TextureAtlasSprite sprite = model.getParticleTexture();

One can then bind (with reference to GuiContainer) the TextureMap and draw the AtlasSprite:


Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
new Gui().drawTexturedModalRect(0,0, sprite, 16, 16);

(I'm creating that gui only as an example for drawing it)

Or one could maybe retrieve PixelData:


Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
IntBuffer buffer = BufferUtils.createIntBuffer(16*16);
GL11.glGetTexImage(GL11.GL_TEXTURE_2D,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_INT, buffer);

(The reason why I'm using unsingend Int is, that Java uses every Byte seperatly for colors, so that this result should provide you with  correct Color values.)

Unfortunatly I don't think this will work so easily, because we never specified the AtlasSprite after binding the Texture, correct?

 

Sadly using this Method of accessing the TextureAtlasSprite only works (referring to dieSiebens eralier Post) in Game, so that I can't use it to retrieve parsable Textures during Initialisation... 

Hi Major Tuvok,

 

I tried using the Line to retrieve pixel data, but it seems

Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

does not want to work! I get a nullPointer due to a ticking player, and a fatal error is thrown:

java.lang.RuntimeException: No OpenGL context found in the current thread.

I've truly hit a wall with my Minecraft coding knowledge here.

Posted

It looks like OpenGl is only accessible from the rendering Thread, but not from the client or similiar threads (1.8 ousourced drawing to different Threads) (try it out in a GuiScreens drawScreen Method, OpenGl calls are definitly allowed there)...

Hmm...

I actually don't know how to get Access to Minecraft's drawing thread I only ever tried to draw sth. from explicit drawing calls.

Still I don't think that will workout well, because we didn't specify the AtlasSprite...

Another pretty similiar thing 

I don't quite understand how they were able to extract the Texture from a given AtlasSprite. And what they did:

TextureAtlasSprite sprite = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getParticleIcon(Items.GOLD_INGOT);

seems to be equivalent to my previous calls...

Anyway: I don't understand much of OpenGl too, soo we'd need some expert to show us how to get that damned texture from a given AtlasSprite

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.