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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
  • Topics

×
×
  • Create New...

Important Information

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