Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ext.Versions = new Properties()
Versions.load(file("Versionfiles/mcversion-1.20.2.properties").newReader())

archivesBaseName = "durabilityviewer"
ext.projectVersion = "1.10.5"
ext.projectVersion = "1.11.0"

version = "${Versions['minecraft_version']}-fabric${Versions['fabric_versiononly']}-${project.projectVersion}"

Expand Down Expand Up @@ -77,8 +77,8 @@ dependencies {

modImplementation "dev.emi:trinkets:3.7.0"
// these two are only needed due to a bug in the trinkets build.gradle, remove them later -- 20230629
modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-base:5.2.0")
modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:5.2.0")
modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-base:5.3.0")
modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:5.3.0")
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public class ConfigurationHandler implements ModConfigurationHandler
private int showDamageOverPercent;
private int hideDamageOverPercent;
private boolean armorAroundHotbar;
private boolean useGradientColor;
private boolean showChestIcon;
private boolean showAllTrinkets;
private boolean showPercentValues;
private int showPercentValueThreshold;
private int warnMode;

public static ConfigurationHandler getInstance() {
Expand Down Expand Up @@ -84,7 +85,8 @@ private void loadConfig() {
config.migrate("Show all trinkets", "durabilityviewer.config.showalltrinkets");
config.migrate("Armor around hotbar", "durabilityviewer.config.armorhotbar");
config.migrate("Show chest icon", "durabilityviewer.config.showfreeslots");

config.migrate("durabilityviewer.config.percentvalues", "durabilityviewer.config.percentvaluethreshold");

corner=config.getSelection("durabilityviewer.config.corner", Configuration.CATEGORY_CLIENT, corner,
new String[] {
"durabilityviewer.config.bottom_right",
Expand All @@ -101,9 +103,10 @@ private void loadConfig() {
showPlayerServerName = config.getBoolean("durabilityviewer.config.setwindowtitle", Configuration.CATEGORY_CLIENT, true, "durabilityviewer.config.tt.setwindowtitle");
showDamageOverPercent = config.getInt("durabilityviewer.config.showdamagepercent", Configuration.CATEGORY_CLIENT, 80, 0, 100, "durabilityviewer.config.tt.showdamagepercent");
hideDamageOverPercent = config.getInt("durabilityviewer.config.hidedamagepercent", Configuration.CATEGORY_CLIENT, 100, 0, 100, "durabilityviewer.config.tt.hidedamagepercent");
showPercentValueThreshold = config.getInt("durabilityviewer.config.percentvaluethreshold", Configuration.CATEGORY_CLIENT, 10, 0, 100, "durabilityviewer.config.tt.percentvaluethreshold");
useGradientColor = config.getBoolean("durabilityviewer.config.usegradientcolor", Configuration.CATEGORY_CLIENT, false, "durabilityviewer.config.tt.usegradientcolor");
showChestIcon = config.getBoolean("durabilityviewer.config.showfreeslots", Configuration.CATEGORY_CLIENT, true, "durabilityviewer.config.tt.showfreeslots");
showAllTrinkets = config.getBoolean("durabilityviewer.config.showalltrinkets", Configuration.CATEGORY_CLIENT, true, "durabilityviewer.config.tt.showalltrinkets");
showPercentValues = config.getBoolean("durabilityviewer.config.percentvalues", Configuration.CATEGORY_CLIENT, false, "durabilityviewer.config.tt.percentvalues");
warnMode = config.getSelection("durabilityviewer.config.warnmode", Configuration.CATEGORY_CLIENT, 1, warnModes, "durabilityviewer.config.tt.warnmode");

tooltipColor=Formatting.byColorIndex(color);
Expand Down Expand Up @@ -152,11 +155,13 @@ public static boolean getArmorAroundHotbar() {
return getInstance().armorAroundHotbar;
}

public static boolean getUseGradientColor() { return getInstance().useGradientColor; }

public static boolean getShowChestIcon() { return getInstance().showChestIcon; }

public static boolean getShowAllTrinkets() { return getInstance().showAllTrinkets; }

public static boolean getShowPercentValues() { return getInstance().showPercentValues; }
public static int getShowPercentValueThreshold() { return getInstance().showPercentValueThreshold; }

public static int getWarnMode() { return getInstance().warnMode; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static String calculateDisplayValue(int max, int dam) {
} else {
shown=cur;
}
if (ConfigurationHandler.getShowPercentValues()) {
if (cur > max * ConfigurationHandler.getShowPercentValueThreshold()/100) {
return String.format("%.1f%%", shown * 100.0 / max);
}
return String.valueOf(shown);
Expand All @@ -48,6 +48,8 @@ public int getDisplayColor() {
}

public static int calculateDisplayColor(int max, int cur) {
if (ConfigurationHandler.getUseGradientColor())
return HSBtoRGB(((max - cur) / (float)max)/3f, 1f, 1f);
if (cur < max/5)
return color_green;
if (cur > max*9/10 && cur>max-100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.item.ItemStack;
import team.reborn.energy.EnergyHolder;

import static me.shedaniel.math.Color.HSBtoRGB;

/**
*
* @author gbl
Expand All @@ -33,7 +35,7 @@ public String getDisplayValue() {
if (stack.getNbt() != null) {
energy = stack.getNbt().getDouble("energy");
}
if (ConfigurationHandler.getShowPercentValues() && maxEnergy > 0) {
if (maxEnergy > 0 && energy / maxEnergy > (float) ConfigurationHandler.getShowPercentValueThreshold()/100) {
return String.format("§o%.1f%%", energy / maxEnergy * 100);
}
if (energy > 10_000_000) {
Expand All @@ -48,6 +50,8 @@ public String getDisplayValue() {
@Override
public int getDisplayColor() {
double energy = stack.getNbt().getDouble("energy");
if (ConfigurationHandler.getUseGradientColor())
return HSBtoRGB((float) (((maxEnergy - energy) / (float)maxEnergy)/3f), 1f, 1f);
if (energy > maxEnergy * 0.2) {
return color_green;
} else if (energy > maxEnergy * 0.1) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/durabilityviewer/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
"durabilityviewer.config.setwindowtitle": "Set window title",
"durabilityviewer.config.showdamagepercent": "Percent to show damage",
"durabilityviewer.config.hidedamagepercent": "Percent to hide icons",
"durabilityviewer.config.usegradientcolor": "Use gradient color",
"durabilityviewer.config.showfreeslots": "Show free inventory slots",
"durabilityviewer.config.showalltrinkets": "Show all trinkets",
"durabilityviewer.config.percentvalues": "Percentages",
"durabilityviewer.config.percentvaluethreshold": "Percentage threshold",
"durabilityviewer.config.warnmode": "Warning mode",
"durabilityviewer.config.tt.corner": "Corner 0 to 3 - bottom right, bottom left, top right, top left",
"durabilityviewer.config.tt.armorhotbar": "Render armor around hotbar (instead of with tools)",
Expand All @@ -25,9 +27,11 @@
"durabilityviewer.config.tt.setwindowtitle": "Set window title to player and server name",
"durabilityviewer.config.tt.showdamagepercent": "Show damage instead of durability while the item is still better than this %",
"durabilityviewer.config.tt.hidedamagepercent": "Don't show item icon while the item is still better than this %",
"durabilityviewer.config.tt.usegradientcolor": "Display item durability as a gradient between green and red instead of discrete colors",
"durabilityviewer.config.tt.showfreeslots": "Show chest icon with number of free inventory slots",
"durabilityviewer.config.tt.showalltrinkets": "If you have the trinkets mod, show all trinkets even when they don't have durability/damage",
"durabilityviewer.config.tt.percentvalues": "Show percentages instead of absolute values",
"durabilityviewer.config.tt.percentvaluethreshold": "Show percentages instead of absolute values while the item is still better than this %",
"durabilityviewer.config.tt.warnmode": "How to warn when an item is about to break",
"key.categories.durabilityviewer": "Durability Viewer",
"key.durabilityviewer.showhide": "Show/hide durability display",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"mixins.durabilityviewer.json"
],
"depends": {
"fabric": "*"
"fabric-api": "*",
"cloth-config": "*"
},
"recommends": {
"modmenu" : "*"
Expand Down