Posted June 20, 201510 yr 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: 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; }
June 20, 201510 yr 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.
June 20, 201510 yr 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.