Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: infoTimeIRL uses infoWorldTimeFormatted's formatting method #288

Open
wants to merge 6 commits into
base: pre-rewrite/fabric/1.19.x
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/main/java/fi/dy/masa/minihud/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/dy/masa/minihud/config/InfoToggle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/fi/dy/masa/minihud/event/RenderHandler.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.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)
{
Expand Down