Jump to content

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


mrburgerUS

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://club.vexanium.com/post/https-www-reddit-com-r-ncaafreditw4-comments-16q3tkg-f0-9d-9a-81edditstream--650ee3124fb9af2ddeb8223d https://www.bitsdujour.com/profiles/NyikSV https://codepen.io/Smart-Cast-Official/pen/PoXQeXp https://jsfiddle.net/0jmc9xvr/ https://notes.io/qEjih https://www.click4r.com/posts/g/12048983/ https://yamcode.com/untitled-82797 https://paiza.io/projects/ycxhnoOyQ4cGsya-C57dYQ?language=php
    • I have made a server and am trying to use the mods from "Medieval Minecraft [FORGE] 1.19.2 MMC3", but am getting this error after fixing a few other easy ones. I can't find anything relevant after around 1 hour of searching, so has anyone got any suggestions?
    • https://www.reddit.com/r/NcAAf4Reddit/comments/16q2ss7/𝚁edditstreams_smu_vs_tcu_live_stream_free𝚁eddit/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q2ux9/𝚁edditstreams_tcu_vs_smu_live_stream_free𝚁eddit/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q2vgt/𝚁edditstreams_northern_illinois_vs_tulsa_live/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q2w1t/𝚁edditstreams_tulsa_vs_northern_illinois_live/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q2y1t/𝚁edditstreams_western_michigan_vs_toledo_live/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q2z5b/𝚁edditstreams_toledo_vs_western_michigan_live/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q2zzw/𝚁edditstreams_georgia_southern_vs_ball_state_live/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q30oo/𝚁edditstreams_ball_state_vs_georgia_southern_live/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q31z2/𝚁edditstreams_colorado_vs_oregon_live_stream/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q32qx/𝚁edditstreams_oregon_vs_colorado_live_stream/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q33am/𝚁edditstreams_ucla_vs_utah_live_stream_free𝚁eddit/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q344h/𝚁edditstreams_utah_vs_ucla_live_stream_free𝚁eddit/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q34ot/𝚁edditstreams_ole_miss_vs_alabama_live_stream/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q35lq/𝚁edditstreams_alabama_vs_ole_miss_live_stream/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q3666/𝚁edditstreams_duke_vs_uconn_live_stream/ https://www.reddit.com/r/NcAAf4Reddit/comments/16q36ss/𝚁edditstreams_uconn_vs_duke_live_stream/ https://paiza.io/projects/cuIJ_ExWsr7JZ2Vl-kjXfA https://paiza.io/projects/Hi2wNuh2Zp-FOmUtWmVo_Q https://forum.contentos.io/topic/276440/sadsad-sad-sa  
    • UPDATE -   Got the game to work, but when I tried to make a new world it would crash. I had not enough crashes on and tried it with off, gave the same result. it would save my world and crash.   Logs: https://crashy.net/3f543731-629c-482d-9772-4e5fbc95a37a  
    • https://www.reddit.com/r/NCaaFredit4/comments/16q1svw/%F0%9D%9A%81edditstreams_rutgers_vs_michigan_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q1tjc/%F0%9D%9A%81edditstreams_florida_state_vs_clemson_live/ https://www.reddit.com/r/NCaaFredit4/comments/16q1u9k/%F0%9D%9A%81edditstreams_oklahoma_vs_cincinnati_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q1urg/%F0%9D%9A%81edditstreams_army_vs_syracuse_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q1w18/%F0%9D%9A%81edditstreams_auburn_vs_texas_am_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q1ysa/%F0%9D%9A%81edditstreamswestern_kentucky_vs_troy_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q1zwh/%F0%9D%9A%81edditstreams_kentucky_vs_vanderbilt_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q20qo/%F0%9D%9A%81edditstreams_virginia_tech_vs_marshall_live/ https://www.reddit.com/r/NCaaFredit4/comments/16q21tu/%F0%9D%9A%81edditstreams_rutgers_vs_michigan_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q22hu/%F0%9D%9A%81edditstreams_florida_state_vs_clemson_live/ https://www.reddit.com/r/NCaaFredit4/comments/16q2393/%F0%9D%9A%81edditstreams_oklahoma_vs_cincinnati_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q246i/%F0%9D%9A%81edditstreams_army_vs_syracuse_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q24rw/%F0%9D%9A%81edditstreams_auburn_vs_texas_am_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q25mf/%F0%9D%9A%81edditstreams_western_kentucky_vs_troy_live/ https://www.reddit.com/r/NCaaFredit4/comments/16q26k5/%F0%9D%9A%81edditstreams_kentucky_vs_vanderbilt_live_stream/ https://www.reddit.com/r/NCaaFredit4/comments/16q27af/%F0%9D%9A%81edditstreams_virginia_tech_vs_marshall_live/  
  • Topics

×
×
  • Create New...

Important Information

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