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

Hi, I'm trying to make an item that can store "energy". I'd like the item to have a durability bar that displays how much energy it currently stores. I've tried to use showDurabilityBar() and getDurabilityForDisplay(), however it seems that the durability bar displays the opposite of what it should. (i.e. the bar is completely green when the item is empty and empty when the item is full)

Here is an example of what I mean:

http://i.imgur.com/U2byBbA.png

The item on the left is empty and the item on the right is full.

This is the code I have for the durability bar:

    @Override
    public boolean showDurabilityBar(ItemStack itemStack)
    {
        return true;
    }

    @Override
    public double getDurabilityForDisplay(ItemStack itemStack)
    {
        if (itemStack.getTagCompound() == null || !itemStack.getTagCompound().hasKey("Energy"))
        {
            itemStack.stackTagCompound = new NBTTagCompound();
            itemStack.getTagCompound().setInteger("Energy", 0);
        }

        return itemStack.getTagCompound().getInteger("Energy") / 80000;
    }

According to the documentation for getDurabilityForDisplay(), you are to pass 1 for 100% durability and 0 for 0%. I thought that this is what this would accomplish, but I must have done something wrong.

Thanks! :D

  • Author

Yeah, sorry, I meant to say that. 80k should be a full item. I got the items from the creative menu. This is the code I used to add the full item to the menu, if it is relevant:

    @Override
    public void getSubItems(Item item, CreativeTabs creativeTabs, List list)
    {
            list.add(new ItemStack(this, 1));
            ItemStack fullEnergy = new ItemStack(this, 1);
            this.setEnergyStored(fullEnergy, 80000);
            list.add(fullEnergy);
    }

setEnergyStored() just manipulates the NBT value used to store the amount of energy.

It could be documented wrong.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Yes,

    /**
     * Queries the percentage of the 'Durability' bar that should be drawn.
     * 
     * @param stack The current ItemStack
     * @return 1.0 for 100% 0 for 0%
     */
    public double getDurabilityForDisplay(ItemStack stack)
    {
        return (double)stack.getItemDamageForDisplay() / (double)stack.getMaxDamage();
    }

  (default implementation of stack.getItemDamageForDisplay() just gives stack.itemDamage)

So this means that the javadoc is inverted.

 

And  how it is used:

                int j1 = (int)Math.round(13.0D - health * 13.0D);
                int k = (int)Math.round(255.0D - health * 255.0D);
                GL11.glDisable(GL11.GL_LIGHTING);
                GL11.glDisable(GL11.GL_DEPTH_TEST);
                GL11.glDisable(GL11.GL_TEXTURE_2D);
                GL11.glDisable(GL11.GL_ALPHA_TEST);
                GL11.glDisable(GL11.GL_BLEND);
                Tessellator tessellator = Tessellator.instance;
                int l = 255 - k << 16 | k << 8;
                int i1 = (255 - k) / 4 << 16 | 16128;
                this.renderQuad(tessellator, p_94148_4_ + 2, p_94148_5_ + 13, 13, 2, 0);
                this.renderQuad(tessellator, p_94148_4_ + 2, p_94148_5_ + 13, 12, 1, i1);
                this.renderQuad(tessellator, p_94148_4_ + 2, p_94148_5_ + 13, j1, 1, l);
                GL11.glEnable(GL11.GL_BLEND);
                GL11.glEnable(GL11.GL_ALPHA_TEST);
                GL11.glEnable(GL11.GL_TEXTURE_2D);
                GL11.glEnable(GL11.GL_LIGHTING);
                GL11.glEnable(GL11.GL_DEPTH_TEST);
                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • Author

Thanks, it seems that's correct. I think the problem with the documentation is the difference between "Durability" and "Damage". The word could be switched and it would then make sense. Oh well, thanks again.

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.