From a89a85a016be46e6ef76abde65aa3badd4d87aa2 Mon Sep 17 00:00:00 2001 From: Starcea Date: Wed, 4 Jan 2023 10:36:06 +0900 Subject: [PATCH 1/5] feat: infoTimeIRL uses infoWorldTimeFormatted's formattinG method --- .../fi/dy/masa/minihud/event/RenderHandler.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java b/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java index af12613c..f713a0de 100644 --- a/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java +++ b/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java @@ -1,6 +1,6 @@ package fi.dy.masa.minihud.event; -import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -316,9 +316,15 @@ else if (type == InfoToggle.TIME_REAL) { try { - SimpleDateFormat sdf = new SimpleDateFormat(Configs.Generic.DATE_FORMAT_REAL.getStringValue()); - this.date.setTime(System.currentTimeMillis()); - this.addLine(sdf.format(this.date)); + String str = Configs.Generic.DATE_FORMAT_REAL.getStringValue(); + LocalDateTime now = LocalDateTime.now(); + str = str.replace("{YEAR}", String.valueOf(now.getYear())); + str = str.replace("{MONTH}", String.valueOf(now.getMonthValue())); + str = str.replace("{DAY}", String.valueOf(now.getDayOfMonth())); + str = str.replace("{HOUR}", String.valueOf(now.getHour())); + str = str.replace("{MIN}", String.valueOf(now.getMinute())); + str = str.replace("{SEC}", String.valueOf(now.getSecond())); + this.addLine(str); } catch (Exception e) { From 19b32025778d96b1d326de01a6a4cc7231b25ddb Mon Sep 17 00:00:00 2001 From: Starcea Date: Wed, 4 Jan 2023 10:38:09 +0900 Subject: [PATCH 2/5] fix: configs --- src/main/java/fi/dy/masa/minihud/config/Configs.java | 2 +- src/main/java/fi/dy/masa/minihud/config/InfoToggle.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fi/dy/masa/minihud/config/Configs.java b/src/main/java/fi/dy/masa/minihud/config/Configs.java index d0c10860..4dea9696 100644 --- a/src/main/java/fi/dy/masa/minihud/config/Configs.java +++ b/src/main/java/fi/dy/masa/minihud/config/Configs.java @@ -47,7 +47,7 @@ public static class Generic public static final ConfigOptionList BLOCK_GRID_OVERLAY_MODE = new ConfigOptionList("blockGridOverlayMode", BlockGridMode.ALL, "The block grid render mode"); public static final ConfigInteger BLOCK_GRID_OVERLAY_RADIUS = new ConfigInteger("blockGridOverlayRadius", 32, 0, 128, "The radius of the block grid lines to render"); public static final ConfigString COORDINATE_FORMAT_STRING = new ConfigString("coordinateFormat", "x: %.1f y: %.1f z: %.1f", "The format string for the coordinate line.\nNeeds to have three %f format strings!\nDefault: x: %.1f y: %.1f z: %.1f"); - public static final ConfigString DATE_FORMAT_REAL = new ConfigString("dateFormatReal", "yyyy-MM-dd HH:mm:ss", "The format string for real time, see the Java SimpleDateFormat\nclass for the format patterns, if needed."); + public static final ConfigString DATE_FORMAT_REAL = new ConfigString("dateFormatReal", "{YEAR}/{MONTH}/{DAY} {HOUR}:{MIN}:{SEC}", "The format string for real time.\nThe supported placeholders are: {YEAR}, {MONTH}, {DAY}, {HOUR}, {MIN}, {SEC}."); public static final ConfigString DATE_FORMAT_MINECRAFT = new ConfigString("dateFormatMinecraft", "MC time: (day {DAY}) {HOUR}:{MIN}:xx", "The format string for the Minecraft time.\nThe supported placeholders are: {DAY_1}, {DAY}, {HOUR}, {MIN}, {SEC}, {MOON}.\n{DAY_1} starts the day counter from 1, {DAY} starts from 0."); public static final ConfigBoolean DEBUG_MESSAGES = new ConfigBoolean("debugMessages", false, "Enables some debug messages in the game console"); public static final ConfigBoolean DEBUG_RENDERER_PATH_MAX_DIST = new ConfigBoolean("debugRendererPathFindingEnablePointWidth", true, "If true, then the vanilla pathfinding debug renderer\nwill render the path point width boxes."); diff --git a/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java b/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java index 0eccbd5b..3c072ccc 100644 --- a/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java +++ b/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java @@ -60,7 +60,7 @@ public enum InfoToggle implements IConfigInteger, IHotkeyTogglable SPRINTING ("infoSprinting", false, 40, "", "Show the \"Sprinting\" info line if the player is sprinting"), TILE_ENTITIES ("infoTileEntities", false, 32, "", "Show the number of TileEntities in the client world"), TIME_DAY_MODULO ("infoTimeDayModulo", false, 35, "", "Show a modulo of the current day time.\nSee Generic configs for the divisor."), - TIME_REAL ("infoTimeIRL", true, 1, "", "Show the current real time formatted according to dateFormatReal"), + TIME_REAL ("infoTimeIRL", true, 1, "", "Show the current real time formatted to years, months, days, hours, minutes, seconds"), TIME_TOTAL_MODULO ("infoTimeTotalModulo", false, 34, "", "Show a modulo of the current total world time.\nSee Generic configs for the divisor."), TIME_WORLD ("infoTimeWorld", false, 2, "", "Show the current world time in ticks"), TIME_WORLD_FORMATTED ("infoWorldTimeFormatted", false, 3, "", "Show the current world time formatted to days, hours, minutes"); From b00693ea8bb4f92d5c0bc6c3a49c9e1c2d0a89e5 Mon Sep 17 00:00:00 2001 From: Starcea Date: Wed, 4 Jan 2023 10:36:06 +0900 Subject: [PATCH 3/5] feat: infoTimeIRL uses infoWorldTimeFormatted's formatting method --- .../fi/dy/masa/minihud/event/RenderHandler.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java b/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java index af12613c..f713a0de 100644 --- a/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java +++ b/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java @@ -1,6 +1,6 @@ package fi.dy.masa.minihud.event; -import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -316,9 +316,15 @@ else if (type == InfoToggle.TIME_REAL) { try { - SimpleDateFormat sdf = new SimpleDateFormat(Configs.Generic.DATE_FORMAT_REAL.getStringValue()); - this.date.setTime(System.currentTimeMillis()); - this.addLine(sdf.format(this.date)); + String str = Configs.Generic.DATE_FORMAT_REAL.getStringValue(); + LocalDateTime now = LocalDateTime.now(); + str = str.replace("{YEAR}", String.valueOf(now.getYear())); + str = str.replace("{MONTH}", String.valueOf(now.getMonthValue())); + str = str.replace("{DAY}", String.valueOf(now.getDayOfMonth())); + str = str.replace("{HOUR}", String.valueOf(now.getHour())); + str = str.replace("{MIN}", String.valueOf(now.getMinute())); + str = str.replace("{SEC}", String.valueOf(now.getSecond())); + this.addLine(str); } catch (Exception e) { From a29ad8da8d924672ef5ff69c7e04b598ceb3d8fd Mon Sep 17 00:00:00 2001 From: Starcea Date: Wed, 4 Jan 2023 10:38:09 +0900 Subject: [PATCH 4/5] fix: configs --- src/main/java/fi/dy/masa/minihud/config/Configs.java | 2 +- src/main/java/fi/dy/masa/minihud/config/InfoToggle.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fi/dy/masa/minihud/config/Configs.java b/src/main/java/fi/dy/masa/minihud/config/Configs.java index d0c10860..4dea9696 100644 --- a/src/main/java/fi/dy/masa/minihud/config/Configs.java +++ b/src/main/java/fi/dy/masa/minihud/config/Configs.java @@ -47,7 +47,7 @@ public static class Generic public static final ConfigOptionList BLOCK_GRID_OVERLAY_MODE = new ConfigOptionList("blockGridOverlayMode", BlockGridMode.ALL, "The block grid render mode"); public static final ConfigInteger BLOCK_GRID_OVERLAY_RADIUS = new ConfigInteger("blockGridOverlayRadius", 32, 0, 128, "The radius of the block grid lines to render"); public static final ConfigString COORDINATE_FORMAT_STRING = new ConfigString("coordinateFormat", "x: %.1f y: %.1f z: %.1f", "The format string for the coordinate line.\nNeeds to have three %f format strings!\nDefault: x: %.1f y: %.1f z: %.1f"); - public static final ConfigString DATE_FORMAT_REAL = new ConfigString("dateFormatReal", "yyyy-MM-dd HH:mm:ss", "The format string for real time, see the Java SimpleDateFormat\nclass for the format patterns, if needed."); + public static final ConfigString DATE_FORMAT_REAL = new ConfigString("dateFormatReal", "{YEAR}/{MONTH}/{DAY} {HOUR}:{MIN}:{SEC}", "The format string for real time.\nThe supported placeholders are: {YEAR}, {MONTH}, {DAY}, {HOUR}, {MIN}, {SEC}."); public static final ConfigString DATE_FORMAT_MINECRAFT = new ConfigString("dateFormatMinecraft", "MC time: (day {DAY}) {HOUR}:{MIN}:xx", "The format string for the Minecraft time.\nThe supported placeholders are: {DAY_1}, {DAY}, {HOUR}, {MIN}, {SEC}, {MOON}.\n{DAY_1} starts the day counter from 1, {DAY} starts from 0."); public static final ConfigBoolean DEBUG_MESSAGES = new ConfigBoolean("debugMessages", false, "Enables some debug messages in the game console"); public static final ConfigBoolean DEBUG_RENDERER_PATH_MAX_DIST = new ConfigBoolean("debugRendererPathFindingEnablePointWidth", true, "If true, then the vanilla pathfinding debug renderer\nwill render the path point width boxes."); diff --git a/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java b/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java index 0eccbd5b..3c072ccc 100644 --- a/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java +++ b/src/main/java/fi/dy/masa/minihud/config/InfoToggle.java @@ -60,7 +60,7 @@ public enum InfoToggle implements IConfigInteger, IHotkeyTogglable SPRINTING ("infoSprinting", false, 40, "", "Show the \"Sprinting\" info line if the player is sprinting"), TILE_ENTITIES ("infoTileEntities", false, 32, "", "Show the number of TileEntities in the client world"), TIME_DAY_MODULO ("infoTimeDayModulo", false, 35, "", "Show a modulo of the current day time.\nSee Generic configs for the divisor."), - TIME_REAL ("infoTimeIRL", true, 1, "", "Show the current real time formatted according to dateFormatReal"), + TIME_REAL ("infoTimeIRL", true, 1, "", "Show the current real time formatted to years, months, days, hours, minutes, seconds"), TIME_TOTAL_MODULO ("infoTimeTotalModulo", false, 34, "", "Show a modulo of the current total world time.\nSee Generic configs for the divisor."), TIME_WORLD ("infoTimeWorld", false, 2, "", "Show the current world time in ticks"), TIME_WORLD_FORMATTED ("infoWorldTimeFormatted", false, 3, "", "Show the current world time formatted to days, hours, minutes"); From 3c787391ce80643bbdd1fedea1ef7109fe9fafc7 Mon Sep 17 00:00:00 2001 From: Starcea Date: Wed, 4 Jan 2023 16:08:35 +0900 Subject: [PATCH 5/5] fix: using 2 digits --- .../java/fi/dy/masa/minihud/event/RenderHandler.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java b/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java index f713a0de..15fd7a2c 100644 --- a/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java +++ b/src/main/java/fi/dy/masa/minihud/event/RenderHandler.java @@ -318,12 +318,12 @@ else if (type == InfoToggle.TIME_REAL) { String str = Configs.Generic.DATE_FORMAT_REAL.getStringValue(); LocalDateTime now = LocalDateTime.now(); - str = str.replace("{YEAR}", String.valueOf(now.getYear())); - str = str.replace("{MONTH}", String.valueOf(now.getMonthValue())); - str = str.replace("{DAY}", String.valueOf(now.getDayOfMonth())); - str = str.replace("{HOUR}", String.valueOf(now.getHour())); - str = str.replace("{MIN}", String.valueOf(now.getMinute())); - str = str.replace("{SEC}", String.valueOf(now.getSecond())); + str = str.replace("{YEAR}", String.format("%d", now.getYear())); + str = str.replace("{MONTH}", String.format("%02d", now.getMonthValue())); + str = str.replace("{DAY}", String.format("%02d", now.getDayOfMonth())); + str = str.replace("{HOUR}", String.format("%02d", now.getHour())); + str = str.replace("{MIN}", String.format("%02d", now.getMinute())); + str = str.replace("{SEC}", String.format("%02d", now.getSecond())); this.addLine(str); } catch (Exception e)