Skip to content

Commit

Permalink
Merge pull request #18 from CodexNotFound/12-12-hour-clock
Browse files Browse the repository at this point in the history
12 12 hour clock
  • Loading branch information
CodexNotFound authored Oct 9, 2022
2 parents 27fa92b + f1af6dd commit c7f882c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.19+build.4
loader_version=0.14.8

# Mod Properties
mod_version=1.0.0
mod_version=1.0.1
maven_group=nl.codexnotfound
archives_base_name=tweaks_not_found

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package nl.codexnotfound.tweaks_not_found.config;

public enum ClockFormat {
TwentyFour,
Twelve
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
@Modmenu(modId = "tweaks_not_found")
@Config(name="tweaks-not-found-config", wrapperName = "TweaksConfig")
public class TnfConfigModel {
@SectionHeader("timestamp")
public boolean showTimestamp = true;
public ClockFormat timeFormat = ClockFormat.TwentyFour;

@SectionHeader("chatCollapsing")
public boolean enableChatCollapsing = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.text.*;
import net.minecraft.util.math.MathHelper;
import nl.codexnotfound.tweaks_not_found.TweaksNotFound;
import nl.codexnotfound.tweaks_not_found.config.ClockFormat;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -18,6 +19,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
Expand All @@ -31,7 +33,7 @@ public class ChatMixin {
@Shadow @Final private MinecraftClient client;

private final Pattern COLLAPSE_CHAT_FORMAT_REGEX = Pattern.compile(" \\{×(\\d+)}");
private final Pattern TIMESTAMP_FORMAT_REGEX = Pattern.compile("\\[\\d{2}:\\d{2}] ");
private final Pattern TIMESTAMP_FORMAT_REGEX = Pattern.compile("\\[\\d{2}:\\d{2}( [AP]M)?] ");

@ModifyArgs(method = "addMessage(Lnet/minecraft/text/Text;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;I)V"))
private void modifyArgsAddMessage(org.spongepowered.asm.mixin.injection.invoke.arg.Args args) {
Expand Down Expand Up @@ -152,10 +154,10 @@ private static boolean shouldCollapseMessage(String newMessageTextCleanedUp) {
}

private MutableText buildTimePrefix() {
var TIMESTAMP_FORMAT = "[%02d:%02d] ";
var format = TweaksNotFound.CONFIG.timeFormat() == ClockFormat.TwentyFour ? "HH:mm" : "hh:mm a";

var time = LocalTime.now();
var timeText = String.format(TIMESTAMP_FORMAT, time.getHour(), time.getMinute());
var time = LocalTime.now().format(DateTimeFormatter.ofPattern(format));
var timeText = String.format("[%s] ", time);

return MutableText
.of(new LiteralTextContent(timeText));
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/assets/tweaks_not_found/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"text.config.tweaks-not-found-config.title" : "TweaksNotFound",
"text.config.tweaks-not-found-config.section.timestamp" : "Timestamp",
"text.config.tweaks-not-found-config.option.showTimestamp" : "Prefix chat with timestamp",
"text.config.tweaks-not-found-config.option.timeFormat" : "Time format",
"text.config.tweaks-not-found-config.option.timeFormat.value.twentyfour" : "[20:05]",
"text.config.tweaks-not-found-config.option.timeFormat.value.twelve" : "[08:05 PM]",
"text.config.tweaks-not-found-config.section.chatCollapsing" : "Collapsing Repeated Chat",
"text.config.tweaks-not-found-config.option.enableChatCollapsing" : "Chat collapsing",
"text.config.tweaks-not-found-config.option.collapseDistance" : "Collapse distance",
"text.config.tweaks-not-found-config.option.nonCollapsingMessages" : "Ignore collapsing for"
"text.config.tweaks-not-found-config.option.nonCollapsingMessages" : "Ignore collapsing for",
"text.config.tweaks-not-found-config.option.nonCollapsingMessages.tooltip" : "Semicolon separated list, NOTE: use &bs& instead of backspaces"
}

0 comments on commit c7f882c

Please sign in to comment.