Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So I am creating a HUD that shows your current equipped item/armor and I have it showing the durability on the hud, but it doesn't display properly.

 

Here is what it is doing:

 

 

2llyt8n.png

 

 

 

This is the code for rendering the hud:

 

 

public void renderItemTexture(int x, int y, Item item, int width, int height)

{

IBakedModel ibakedmodel = mc.getRenderItem().getItemModelMesher().getItemModel(new ItemStack(item));

TextureAtlasSprite textureAtlasSprite = mc.getTextureMapBlocks().getAtlasSprite(ibakedmodel.getTexture().getIconName()); // Get item texture

mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); // Binds texture

ItemStack stack = new ItemStack(item);

 

if (item.isDamageable()) // Renders the damage bar under the item

{

GlStateManager.pushMatrix();

double damage = stack.getItem().getDurabilityForDisplay(stack);

int j1 = (int) Math.round(13.0D - damage * 13.0D);

int k = (int) Math.round(255.0D - damage * 255.0D);

GlStateManager.disableDepth();

GlStateManager.disableTexture2D();

GlStateManager.disableAlpha();

GlStateManager.disableBlend();

Tessellator tessellator = Tessellator.getInstance();

WorldRenderer worldrenderer = tessellator.getWorldRenderer();

int l = 255 - k << 16 | k << 8;

int i1 = (255 - k) / 4 << 16 | 16128;

drawRect(worldrenderer, x + 6, y + 9, 13, 2, 0);

drawRect(worldrenderer, x + 6, y + 9, 12, 1, i1);

drawRect(worldrenderer, x + 6, y + 9, j1, 1, l);

GlStateManager.enableBlend();

GlStateManager.enableAlpha();

GlStateManager.enableTexture2D();

GlStateManager.enableDepth();

GlStateManager.popMatrix();

}

 

if (Block.getBlockFromItem(item) != null) return; // Makes sure that when a Block is held out, it doesn't render its icon.

renderTexture(x, y, textureAtlasSprite, width, height, 0); // Renders the texture to screen

 

GlStateManager.pushMatrix();

GlStateManager.scale(0.5F, 0.5F, 0.5F);

int y1 = y;

y1 += y;

mc.fontRendererObj.drawString(getDamageString(new ItemStack(item)), x + 12, y1 + 10, 16777215); // This renders the durability to the screen

GlStateManager.popMatrix();

}

 

 

 

This is my string code that should display the proper durability:

 

 

private String getDamageString(ItemStack stack)

{

String result = stack.getItem().getItemStackDisplayName(stack);

if (stack.getMaxDamage() == 0) return result; // If the stack isn't damageable, just render the name of the item.

int maxDamage = 0;

int tmpDamage = 0;

int durability = 0;

maxDamage = stack.getMaxDamage() + 1;

tmpDamage = stack.getItemDamage();

durability = maxDamage - tmpDamage;

int percentDamage = (stack.getMaxDamage() - stack.getItemDamage()) * 100 / stack.getMaxDamage(); // This will show the item damage in percent.

result = (maxDamage - tmpDamage) + "/" + maxDamage; // This should show the proper durability

return result;

}

 

 

mc.fontRendererObj.drawString(getDamageString(new ItemStack(item)), x + 12, y1 + 10, 16777215); // This renders the durability to the screen

 

You are making new ItemStack - it will be untouched. ItemStack's itemDamage = meta.

You need to either do new ItemStack(item, 1, damage) or simply use ItemStack pulled from player.

 

Item is just an instance, it's the ItemStack that holds data, pass that instead of Item.

You shouldn't even make "new ItemStack" - ever. In most cases very bad, is some - it's just pointless.

 

To get armour worn:

Minecraft.getMinecraft().thePlayer.inventory.armorInventory[index]

1.7.10 is no longer supported by forge, you are on your own.

  • Author

I Fixed it, instead of passing an Item in my renderItemTexture I pass an ItemStack and I just use stack.getItem() to return the stacks item

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.