Jump to content

Durability bar that uses an integer NBT value instead of actual durability?


Recommended Posts

Posted

I have a NBT tag called "ConsumedAmount" on an item. Got everything about it working very well, but as a sort of 'final touch', I want to add a durability bar. However, this durability bar should use the ConsumedAmount. So if it's 0/there is no tag compound/ConsumedAmount key then it won't display, 1 then it'll be super low, all the way up to 32 which would be full.

 

Is there any way I can accomplish this? I've noticed that a mod like EnderIO has a 'durability bar' that uses RF instead of actual durability (I've only seen this for the Staff of Travelling so far, though). I don't exactly want the custom gradient that it uses, but just something like that.

 

 

As a completely optional question (and I hope this isn't too complex...), is it possible to change the bar's color at a certain value? Not gradually change it overtime like vanilla's, but literally change the entire color. So green to gray, gray to gold, etc. etc..

Posted

Yes, all of that is possible!

  • Item#showDurabilityBar checks whether the bar should display (you probably just want to override it to return true).
  • Item#getDurabilityForDisplay defines how much of the bar should be full (as a double between 0 and 1) - this is where you can read your custom NBT and convert it into the proportion of the bar to fill.
  • Item#getRGBDurabilityForDisplay defines the colour of the filled part of the bar (as an int representing an RGB hex colour) - this is where you can set the colour according to your custom NBT.
Posted
20 minutes ago, Jay Avery said:

Yes, all of that is possible!

  • Item#showDurabilityBar checks whether the bar should display (you probably just want to override it to return true).
  • Item#getDurabilityForDisplay defines how much of the bar should be full (as a double between 0 and 1) - this is where you can read your custom NBT and convert it into the proportion of the bar to fill.
  • Item#getRGBDurabilityForDisplay defines the colour of the filled part of the bar (as an int representing an RGB hex colour) - this is where you can set the colour according to your custom NBT.

Thank you so much! That basically answers 99% of my question!

 

The remaining question is, how should I format RGB hex colors? Just like usual, as in #FF0000?

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.