Skip to content

Commit

Permalink
feat: Some minor improvements to distance display
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Sep 12, 2023
1 parent 00a9ca2 commit f22d98a
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
Minecraft mc = Minecraft.getInstance();

// render distance
if(waystone.getDimension() == mc.player.level().dimension()) {
if (waystone.getDimension() == mc.player.level().dimension() && isActive()) {
int distance = (int) mc.player.position().distanceTo(waystone.getPos().getCenter());
String distanceStr;
if (distance < 1000) {
if (distance < 10000 && (mc.font.width(getMessage()) < 120 || distance < 1000)) {
distanceStr = distance + "m";
} else {
distanceStr = String.format("%.1fkm", distance / 1000.0);
// sorry for ugly code, chatgpt was down and this was the only thing my dumbed down brain could come up with
distanceStr = String.format("%.1f", distance / 1000f).replace(",0", "").replace(".0", "") + "km";
}
int xOffset = getWidth() - mc.font.width(distanceStr);
guiGraphics.drawString(mc.font, distanceStr, getX() + xOffset - 4, getY() + 6, 0xFFFFFF);
Expand Down

0 comments on commit f22d98a

Please sign in to comment.