Skip to content

Commit

Permalink
Fix the amplifier code
Browse files Browse the repository at this point in the history
* Handle cases for non-translated values of amplifier
* Don't call drawString unless we have something to draw

(cherry picked from commit d756fd4)
  • Loading branch information
magicus committed Dec 30, 2021
1 parent f9ec938 commit 4b5a253
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ private void renderDurationOverlay(MatrixStack matrices, CallbackInfo c) {
int durationLength = client.textRenderer.getWidth(duration);
drawStringWithShadow(matrices, client.textRenderer, duration, x + 13 - (durationLength / 2), y + 14, 0x99FFFFFF);

String amplifier = getAmplifierAsString(statusEffectInstance);
int amplifierLength = client.textRenderer.getWidth(amplifier);
drawStringWithShadow(matrices, client.textRenderer, amplifier, x + 22 - amplifierLength, y + 3, 0x99FFFFFF);
int amplifier = statusEffectInstance.getAmplifier();
if (amplifier > 0) {
// Most langages has "translations" for amplifier 1-5, converting to roman numerals
String amplifierString = (amplifier < 6) ? I18n.translate("potion.potency." + amplifier) : "**";
int amplifierLength = client.textRenderer.getWidth(amplifierString);
drawStringWithShadow(matrices, client.textRenderer, amplifierString, x + 22 - amplifierLength, y + 3, 0x99FFFFFF);
}
}
}
}
Expand All @@ -81,15 +85,4 @@ private String getDurationAsString(StatusEffectInstance statusEffectInstance) {
return String.valueOf(seconds);
}
}

@NotNull
private String getAmplifierAsString(StatusEffectInstance statusEffectInstance) {
int amplifier = statusEffectInstance.getAmplifier();

if (amplifier > 0) {
return I18n.translate("potion.potency." + amplifier);
} else {
return "";
}
}
}

0 comments on commit 4b5a253

Please sign in to comment.