Jump to content

Recommended Posts

Posted (edited)

Hello,

I am currently trying to draw the texture of the current held item by the player somewhere else on the inGameGui. I am using the RenderGameOverlayEvent.post and i can easily drawString but i don't know how to draw texture.

I tried using the blit method but i don't know how to get the TextureAtlasSprite of an item (wich is needed for the method). I can get the ResourceLocation of the item but i have no clue for the TextureAtlasSprite.

Could i also have explanation on the bindTexture(ResourceLocation resource) method ?

 

Thank you for any reply.

Edited by JOB
Posted

Resolved my issue.

To get the TextureAtlasSprite of an item i use :


public static final Minecraft MC = Minecraft.getInstance();
public static final PlayerEntity player = MC.player;

TextureAtlasSprite texture = MC.getTextureMap().getSprite(player.getHeldItemMainHand().getItem().getRegistryName());

 

Posted
3 hours ago, JOB said:

MC.getTextureMap().getSprite(player.getHeldItemMainHand().getItem().getRegistryName());

Don’t use that... that will break completely for anything that isn’t 100% standard. In 1.12.2 you would use RenderItem#renderStack. I’m not sure what the 1.14 replacement is, but it should be pretty easy to find by looking at the ingame GUI renderer or the item group renderer.

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Thank you,

You were right i looked more deeply in the way that the inventory is generated on the GUI and found this method :

renderItemIntoGUI(ItemStack stack, int x, int y)

in the ItemRenderer class and it is really easy to use. For example i use it like this :

public static finale Minecraft MC = Minecraft.getInstance();

MC.getItemRenderer().renderItemIntoGUI(MC.player.getHeldItemMainhand(), 200, 200);

 

For some reasons when i first read the ItemRenderer class i completely passed over it.

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.