Skip to content

Commit

Permalink
Raw health consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Madis0 committed Oct 20, 2024
1 parent ee7ed77 commit af9579b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/main/java/io/github/madis0/OneBarElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.RegistryKey;
import net.minecraft.text.Text;
import net.minecraft.util.Arm;
import net.minecraft.world.Difficulty;

import java.util.Locale;
import java.util.Objects;

public class OneBarElements {
private final ModConfig config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/io/github/madis0/TextGeneration.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public String GenerateOneBarText()
if (config.healthEstimates && showHealthParentheses)
value += pStart;

value += getSymbol("text.onebar.health", config.textSettings.rawHealth ? (Math.round(playerProperties.healthRaw * 100.0) / 100.0) : getFraction(playerProperties.health, false));
value += getSymbol("text.onebar.health",
config.textSettings.rawHealth ?
getFraction(Math.round(playerProperties.healthRaw * 100.0) / 100.0) :
getFraction(playerProperties.health, false));

if(config.healthEstimates){
if (playerProperties.naturalRegenerationHealth > playerProperties.health && !config.uhcMode)
Expand Down Expand Up @@ -169,13 +172,21 @@ public String GenerateOneBarText()
}

public String GenerateMountBarText(float rawHealth, int health){
return getSymbol("text.onebar.mountHealth", config.textSettings.rawHealth ? (Math.round(rawHealth * 100.0) / 100.0) : getFraction(health, false));
return getSymbol("text.onebar.mountHealth",
config.textSettings.rawHealth ?
getFraction(Math.round(rawHealth * 100.0) / 100.0) :
getFraction(health, false));
}

private boolean translationStringValid(String key){
return !Objects.equals(Text.translatable(key).getString(), key);
}

private String getFraction(double number){
DecimalFormat df = new DecimalFormat("0.00");
return df.format(number);
}

private String getFraction(int number){
return getFraction(number, config.textSettings.estimatesItalic);
}
Expand Down

0 comments on commit af9579b

Please sign in to comment.