Posted April 3, 20178 yr 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..
April 3, 20178 yr 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.
April 3, 20178 yr Author 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?
April 3, 20178 yr You can also use MathHelper.rgb, which takes the three colour values and converts them into a hex colour int.
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.