Comments (6)
Well, if I tell the real reason, I was actually not even aware of that formatting. We learn things every day ;) ...
from healthcare.
The following is the full body of the function that I have modified to get what I wanted out of the displays:
public MutableText getHealthbarText(float health, float maxHealth) {
if(health < 0.0F) {
health = 0.0F;
}
if(maxHealth <= 0.0F) {
maxHealth = 1.0F;
}
if(health > maxHealth) {
maxHealth = health;
}
String first, second;
if(this.healthbarStyle.equals(HealthbarStyle.SKYBLOCK)) {
// String.format("%.2f", health) for rounding
first = String.format("%.2f", health);
second = String.valueOf((int) Math.ceil(maxHealth));
// We return it here because of custom formatting
return new LiteralText(first)
.formatted(health > maxHealth / 2 ? Formatting.GREEN : Formatting.YELLOW)
.append(new LiteralText("/")
.formatted(Formatting.WHITE))
.append(new LiteralText(second)
.formatted(Formatting.GREEN))
.append(new LiteralText(String.valueOf((char) 10084)) // ❤
.formatted(Formatting.RED));
} else if(this.healthbarStyle.equals(HealthbarStyle.NUMBER)) {
// Number
// String.format("%.2f", health) for rounding
first = String.format("%.2f", health);
second = "/" + String.format("%.2f", maxHealth);
} else if(this.healthbarStyle.equals(HealthbarStyle.PERCENTAGE)) {
first = String.format("%.2f", health * 100.0F / maxHealth).concat("%");
second = "";
} else {
int heartCount, fullHearts;
char full, empty;
if(this.healthbarStyle.equals(HealthbarStyle.LINES)) {
heartCount = maxHealth < 20 ? (int) Math.ceil(maxHealth) : 20;
empty = '|';
full = '|';
} else { // Hearts
// We ceil the number to not show 0 hearts if entity has like 0.2f health
int length = this.healthbarStyle == HealthbarStyle.CUSTOM ? customLength : 10;
heartCount = maxHealth < length ? (int) Math.ceil(maxHealth) : length;
full = (char) (this.healthbarStyle.equals(HealthbarStyle.HEARTS) ? 9829 : this.customFullChar); // ♥ or custom
empty = (char) (this.healthbarStyle.equals(HealthbarStyle.HEARTS) ? 9825 : this.customEmptyChar); // ♡ or custom
}
// Hearts that should be colored red
fullHearts = (int) Math.ceil(health * heartCount / maxHealth);
first = new String(new char[fullHearts]).replace('\0', full);
second = new String(new char[heartCount - fullHearts]).replace('\0', empty);
}
return new LiteralText(first)
.formatted(Formatting.RED) /*health > maxHealth / 3 ? (health > maxHealth * 1.5F ? Formatting.YELLOW : Formatting.GOLD) : */
.append(new LiteralText(second).formatted(Formatting.GRAY));
}
from healthcare.
Closing as fixed (implemented) in 6689a04.
from healthcare.
Yes, release is on the way :). Thanks!
from healthcare.
The commit managed to generate an error of the following form:
Upload failed! Status: 400 Error: invalid_input Reason: Error with multipart data: A version with that version_number already exists
See: https://github.com/samolego/HealthCare/runs/2704820180
In other words, have you bumped the version yet?
from healthcare.
ohno, forgot to add the file to git :|
from healthcare.
Related Issues (15)
- Crash HOT 1
- Suggestion - allow for custom icons or datapack to for icons to show. HOT 3
- Conflict with Immersive Portals mod: no errors, but HealthCare UI is not shown HOT 10
- Crash in 1.19.4
- Mod configuration HOT 1
- [Feature Request] RpgDifficulty compat (show mob level prefix in display name) HOT 2
- 1.20.2 support required HOT 3
- Release process doesn't send changelog to modrinth
- Idea: A "skyblock" `HealthBarStyle` HOT 8
- No mention that Fabric API is required
- Certain mobs report incorrect health and max health values until damaged
- Players getting disconnected when grouped HOT 3
- Crashes with NegativeArraySizeException HOT 3
- Toggleable name
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from healthcare.