From f9755fbc9958bb921d4ea2dc3504a7045157a100 Mon Sep 17 00:00:00 2001 From: Apex Date: Mon, 19 Aug 2024 03:08:40 +0100 Subject: [PATCH 01/10] Reimplement PR changes --- .../neoforge/server/command/TPSCommand.java | 110 ++++++++++++++---- .../resources/assets/neoforge/lang/en_us.json | 13 ++- 2 files changed, 96 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index eb50fd2963..887ae4edef 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -5,18 +5,29 @@ package net.neoforged.neoforge.server.command; +import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import java.text.DecimalFormat; +import java.util.Objects; +import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.DimensionArgument; -import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.CommonColors; +import net.minecraft.util.Mth; import net.minecraft.util.TimeUtil; -import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.TickRateManager; +import org.jetbrains.annotations.Nullable; +import org.joml.Math; class TPSCommand { private static final DecimalFormat TIME_FORMATTER = new DecimalFormat("########0.000"); @@ -24,34 +35,23 @@ class TPSCommand { static ArgumentBuilder register() { return Commands.literal("tps") - .requires(cs -> cs.hasPermission(0)) //permission + .requires(cs -> cs.hasPermission(Commands.LEVEL_ALL)) //permission .then(Commands.argument("dim", DimensionArgument.dimension()) - .executes(ctx -> sendTime(ctx.getSource(), DimensionArgument.getDimension(ctx, "dim")))) + .executes(ctx -> sendTime(ctx, DimensionArgument.getDimension(ctx, "dim")))) .executes(ctx -> { - for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) - sendTime(ctx.getSource(), dim); + for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) { + sendTime(ctx, dim); + } - long[] times = ctx.getSource().getServer().getTickTimesNanos(); - double meanTickTime = mean(times) * 1.0E-6D; - double meanTPS = TimeUtil.MILLISECONDS_PER_SECOND / Math.max(meanTickTime, ctx.getSource().getServer().tickRateManager().millisecondsPerTick()); - ctx.getSource().sendSuccess(() -> Component.translatable("commands.neoforge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false); - - return 0; + sendTime(ctx, null); + return Command.SINGLE_SUCCESS; }); } - private static int sendTime(CommandSourceStack cs, ServerLevel dim) throws CommandSyntaxException { - long[] times = cs.getServer().getTickTime(dim.dimension()); - - if (times == null) // Null means the world is unloaded. Not invalid. That's taken care of by DimensionArgument itself. - times = UNLOADED; - - final Registry reg = cs.registryAccess().registryOrThrow(Registries.DIMENSION_TYPE); - double worldTickTime = mean(times) * 1.0E-6D; - double worldTPS = TimeUtil.MILLISECONDS_PER_SECOND / Math.max(worldTickTime, dim.tickRateManager().millisecondsPerTick()); - cs.sendSuccess(() -> Component.translatable("commands.neoforge.tps.summary.named", dim.getDescription(), reg.getKey(dim.dimensionType()).toString(), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false); - - return 1; + private static int sendTime(CommandContext context, ServerLevel dim) throws CommandSyntaxException { + var src = context.getSource(); + src.sendSuccess(() -> createComponent(src.getServer(), dim), false); + return Command.SINGLE_SUCCESS; } private static long mean(long[] values) { @@ -60,4 +60,66 @@ private static long mean(long[] values) { sum += v; return sum / values.length; } + + private static Component createComponent(MinecraftServer server, @Nullable ServerLevel dimension) { + MutableComponent prefix; + long[] times; + TickRateManager tickRateManager; + + if (dimension == null) { + prefix = Component.translatable("commands.neoforge.tps.summary.overall"); + times = server.getTickTimesNanos(); + tickRateManager = server.tickRateManager(); + } else { + var dimKey = dimension.dimension(); + var dimensionTimes = server.getTickTime(dimKey); + + prefix = Component.translatable("commands.neoforge.tps.summary.dimension", createDimensionComponent(dimension)); + times = dimensionTimes == null ? UNLOADED : dimensionTimes; + tickRateManager = dimension.tickRateManager(); + } + + var tickTime = mean(times) * 1.0E-6D; + var tps = TimeUtil.MILLISECONDS_PER_SECOND / Math.max(tickTime, tickRateManager.millisecondsPerTick()); + var timeComponent = Component.empty().append(createTickTimeComponent(tickTime)).append(". ").append(createTpsComponent(tickRateManager, tps)); + return prefix.append(CommonComponents.SPACE).append(timeComponent); + } + + private static Component createDimensionComponent(ServerLevel dimension) { + var regName = dimension.dimension().location(); + var langKey = regName.toLanguageKey("dimension"); + var dimensionTypes = dimension.registryAccess().registryOrThrow(Registries.DIMENSION_TYPE); + var dimensionType = Objects.requireNonNull(dimensionTypes.getKey(dimension.dimensionType())); + + return Component.translatableWithFallback(langKey, regName.toString()).withStyle(style -> style + .withColor(ChatFormatting.GREEN) + .withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Component.literal(regName.toString()) + .append(" (") + .append(dimensionType.toString()) + .append(")")))); + } + + private static Component createTickTimeComponent(double tickTime) { + return Component.translatable("commands.neoforge.tps.mean_tick_time", Component.literal(TIME_FORMATTER.format(tickTime)) + .withColor(CommonColors.GRAY)) + .withStyle(style -> style.withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Component.translatable("commands.neoforge.tps.mean_tick_time.tooltip")))); + } + + private static Component createTpsComponent(TickRateManager tickRateManager, double tps) { + return Component.translatable("commands.neoforge.tps.mean_tps", Component.literal(TIME_FORMATTER.format(tps)).withColor(calculateTPSColor(tickRateManager, tps))) + .withStyle(style -> style.withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Component.translatable("commands.neoforge.tps.mean_tps.tooltip")))); + } + + private static int calculateTPSColor(TickRateManager tickRateManager, double tps) { + // Improved color blending code thanks to sciwhiz12 + float maxTPS = TimeUtil.MILLISECONDS_PER_SECOND / tickRateManager.millisecondsPerTick(); + // 0 degrees (0F) is red, 120 degrees (0.33F) is green + return Mth.hsvToRgb((float) (Mth.inverseLerp(tps, 0, maxTPS) * 0.33F), 1F, 1F); + } } diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 46e4288763..b8f9bec9a7 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -81,10 +81,13 @@ "commands.neoforge.setdim.invalid.nochange": "The entity selected (%1$s) is already in the dimension specified (%2$s).", "commands.neoforge.setdim.deprecated": "This command is deprecated for removal in 1.17, use %s instead.", "commands.neoforge.tps.invalid": "Invalid dimension %1$s Possible values: %2$s", - "commands.neoforge.tps.summary.all": "Overall: Mean tick time: %1$s ms. Mean TPS: %2$s", + "commands.neoforge.tps.summary.overall": "Overall:", + "commands.neoforge.tps.summary.dimension": "'%s':", + "commands.neoforge.tps.mean_tps": "Mean TPS: %s", + "commands.neoforge.tps.mean_tps.tooltip": "Closer to 20 is better", + "commands.neoforge.tps.mean_tick_time": "Mean tick time: %s ms", + "commands.neoforge.tps.mean_tick_time.tooltip": "Lower is better, Higher is worse", "commands.neoforge.mods.list": "Mod List: %1$s", - "commands.neoforge.tps.summary.basic": "Dim %1$s: Mean tick time: %2$s ms. Mean TPS: %3$s", - "commands.neoforge.tps.summary.named": "Dim %1$s (%2$s): Mean tick time: %3$s ms. Mean TPS: %4$s", "commands.neoforge.tracking.entity.enabled": "Entity tracking enabled for %d seconds.", "commands.neoforge.tracking.entity.reset": "Entity timings data has been cleared!", "commands.neoforge.tracking.invalid": "Invalid tracking data.", @@ -131,6 +134,10 @@ "commands.config.getwithtype": "Config for %s of type %s found at %s", "commands.config.noconfig": "Config for %s of type %s not found", + "dimension.minecraft.overworld": "Overworld", + "dimension.minecraft.the_nether": "The Nether", + "dimension.minecraft.the_end": "The End", + "neoforge.update.beta.1": "%sWARNING: %sNeoForge Beta", "neoforge.update.beta.2": "Major issues may arise, verify before reporting.", "neoforge.update.newversion": "New NeoForge version available: %s", From 2d6aee2b2b983f4d6892ab71b7585a5e0c70ac0e Mon Sep 17 00:00:00 2001 From: Apex Date: Mon, 19 Aug 2024 03:16:00 +0100 Subject: [PATCH 02/10] Update to make use of changes from #1428 --- .../net/neoforged/neoforge/server/command/TPSCommand.java | 3 +-- src/main/resources/assets/neoforge/lang/en_us.json | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index 887ae4edef..b974ab84f6 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -87,11 +87,10 @@ private static Component createComponent(MinecraftServer server, @Nullable Serve private static Component createDimensionComponent(ServerLevel dimension) { var regName = dimension.dimension().location(); - var langKey = regName.toLanguageKey("dimension"); var dimensionTypes = dimension.registryAccess().registryOrThrow(Registries.DIMENSION_TYPE); var dimensionType = Objects.requireNonNull(dimensionTypes.getKey(dimension.dimensionType())); - return Component.translatableWithFallback(langKey, regName.toString()).withStyle(style -> style + return Component.empty().append(dimension.getDescription()).withStyle(style -> style .withColor(ChatFormatting.GREEN) .withHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index b8f9bec9a7..5807cc5d8d 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -134,10 +134,6 @@ "commands.config.getwithtype": "Config for %s of type %s found at %s", "commands.config.noconfig": "Config for %s of type %s not found", - "dimension.minecraft.overworld": "Overworld", - "dimension.minecraft.the_nether": "The Nether", - "dimension.minecraft.the_end": "The End", - "neoforge.update.beta.1": "%sWARNING: %sNeoForge Beta", "neoforge.update.beta.2": "Major issues may arise, verify before reporting.", "neoforge.update.newversion": "New NeoForge version available: %s", From 07db7f3d4b134083974e4509dbfaa280d21a3ef6 Mon Sep 17 00:00:00 2001 From: Apex Date: Mon, 19 Aug 2024 03:17:23 +0100 Subject: [PATCH 03/10] Apply Formatting --- .../java/net/neoforged/neoforge/server/command/TPSCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index b974ab84f6..6a15f6b234 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -102,7 +102,7 @@ private static Component createDimensionComponent(ServerLevel dimension) { private static Component createTickTimeComponent(double tickTime) { return Component.translatable("commands.neoforge.tps.mean_tick_time", Component.literal(TIME_FORMATTER.format(tickTime)) - .withColor(CommonColors.GRAY)) + .withColor(CommonColors.GRAY)) .withStyle(style -> style.withHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, Component.translatable("commands.neoforge.tps.mean_tick_time.tooltip")))); From 7c7eb0418196e561bd37067193277c12ef4f0176 Mon Sep 17 00:00:00 2001 From: Apex Date: Fri, 23 Aug 2024 08:07:27 +0100 Subject: [PATCH 04/10] Remove permission requirement --- .../java/net/neoforged/neoforge/server/command/TPSCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index 6a15f6b234..4c3f49f619 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -35,7 +35,6 @@ class TPSCommand { static ArgumentBuilder register() { return Commands.literal("tps") - .requires(cs -> cs.hasPermission(Commands.LEVEL_ALL)) //permission .then(Commands.argument("dim", DimensionArgument.dimension()) .executes(ctx -> sendTime(ctx, DimensionArgument.getDimension(ctx, "dim")))) .executes(ctx -> { From 97f625c270ba9d681a92230c6f8df55b34353517 Mon Sep 17 00:00:00 2001 From: Apex Date: Fri, 23 Aug 2024 08:10:26 +0100 Subject: [PATCH 05/10] Use Guava Stats.meanOf Also replace magic number with TimeUtil constant --- .../neoforged/neoforge/server/command/TPSCommand.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index 4c3f49f619..aed50b9891 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -5,6 +5,7 @@ package net.neoforged.neoforge.server.command; +import com.google.common.math.Stats; import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.context.CommandContext; @@ -53,13 +54,6 @@ private static int sendTime(CommandContext context, ServerLe return Command.SINGLE_SUCCESS; } - private static long mean(long[] values) { - long sum = 0L; - for (long v : values) - sum += v; - return sum / values.length; - } - private static Component createComponent(MinecraftServer server, @Nullable ServerLevel dimension) { MutableComponent prefix; long[] times; @@ -78,7 +72,7 @@ private static Component createComponent(MinecraftServer server, @Nullable Serve tickRateManager = dimension.tickRateManager(); } - var tickTime = mean(times) * 1.0E-6D; + var tickTime = Stats.meanOf(times) / TimeUtil.NANOSECONDS_PER_MILLISECOND; var tps = TimeUtil.MILLISECONDS_PER_SECOND / Math.max(tickTime, tickRateManager.millisecondsPerTick()); var timeComponent = Component.empty().append(createTickTimeComponent(tickTime)).append(". ").append(createTpsComponent(tickRateManager, tps)); return prefix.append(CommonComponents.SPACE).append(timeComponent); From 3f9aa36eb73f1b57950f575cf35585fe895ab707 Mon Sep 17 00:00:00 2001 From: Apex Date: Fri, 23 Aug 2024 08:13:44 +0100 Subject: [PATCH 06/10] Mark parameter as Nullable Rename 'dim' to 'dimension' for better readability --- .../neoforge/server/command/TPSCommand.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index aed50b9891..2786cdb4e1 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -36,11 +36,11 @@ class TPSCommand { static ArgumentBuilder register() { return Commands.literal("tps") - .then(Commands.argument("dim", DimensionArgument.dimension()) - .executes(ctx -> sendTime(ctx, DimensionArgument.getDimension(ctx, "dim")))) + .then(Commands.argument("dimension", DimensionArgument.dimension()) + .executes(ctx -> sendTime(ctx, DimensionArgument.getDimension(ctx, "dimension")))) .executes(ctx -> { - for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) { - sendTime(ctx, dim); + for (ServerLevel dimension : ctx.getSource().getServer().getAllLevels()) { + sendTime(ctx, dimension); } sendTime(ctx, null); @@ -48,9 +48,9 @@ class TPSCommand { }); } - private static int sendTime(CommandContext context, ServerLevel dim) throws CommandSyntaxException { + private static int sendTime(CommandContext context, @Nullable ServerLevel dimension) throws CommandSyntaxException { var src = context.getSource(); - src.sendSuccess(() -> createComponent(src.getServer(), dim), false); + src.sendSuccess(() -> createComponent(src.getServer(), dimension), false); return Command.SINGLE_SUCCESS; } From 8dd611e029c2d53ed95ea30a98bd22b7c9158b2e Mon Sep 17 00:00:00 2001 From: Apex Date: Fri, 23 Aug 2024 08:51:49 +0100 Subject: [PATCH 07/10] Convert dimension tooltip to being a translatable component --- .../net/neoforged/neoforge/server/command/TPSCommand.java | 5 +---- src/main/resources/assets/neoforge/lang/en_us.json | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index 2786cdb4e1..ac5e97ad73 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -87,10 +87,7 @@ private static Component createDimensionComponent(ServerLevel dimension) { .withColor(ChatFormatting.GREEN) .withHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, - Component.literal(regName.toString()) - .append(" (") - .append(dimensionType.toString()) - .append(")")))); + Component.translatable("commands.neoforge.tps.summary.dimension.tooltip", regName.toString(), dimensionType.toString())))); } private static Component createTickTimeComponent(double tickTime) { diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 5807cc5d8d..b35a2a8ac5 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -83,6 +83,7 @@ "commands.neoforge.tps.invalid": "Invalid dimension %1$s Possible values: %2$s", "commands.neoforge.tps.summary.overall": "Overall:", "commands.neoforge.tps.summary.dimension": "'%s':", + "commands.neoforge.tps.summary.dimension.tooltip": "%s (%s)", "commands.neoforge.tps.mean_tps": "Mean TPS: %s", "commands.neoforge.tps.mean_tps.tooltip": "Closer to 20 is better", "commands.neoforge.tps.mean_tick_time": "Mean tick time: %s ms", From f65ebd97c21e8823243b7897ff2e0ef180b59bd0 Mon Sep 17 00:00:00 2001 From: Apex Date: Fri, 23 Aug 2024 15:55:04 +0100 Subject: [PATCH 08/10] Big refactoring to shorten overall output While keeping all of the same information and stylization --- .../neoforge/server/command/TPSCommand.java | 52 +++++++------------ .../resources/assets/neoforge/lang/en_us.json | 12 ++--- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index ac5e97ad73..72f9d3ec63 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -11,13 +11,10 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import java.text.DecimalFormat; -import java.util.Objects; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.DimensionArgument; -import net.minecraft.core.registries.Registries; -import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.MutableComponent; @@ -55,54 +52,41 @@ private static int sendTime(CommandContext context, @Nullabl } private static Component createComponent(MinecraftServer server, @Nullable ServerLevel dimension) { - MutableComponent prefix; long[] times; TickRateManager tickRateManager; if (dimension == null) { - prefix = Component.translatable("commands.neoforge.tps.summary.overall"); times = server.getTickTimesNanos(); tickRateManager = server.tickRateManager(); } else { - var dimKey = dimension.dimension(); - var dimensionTimes = server.getTickTime(dimKey); - - prefix = Component.translatable("commands.neoforge.tps.summary.dimension", createDimensionComponent(dimension)); + var dimensionTimes = server.getTickTime(dimension.dimension()); times = dimensionTimes == null ? UNLOADED : dimensionTimes; tickRateManager = dimension.tickRateManager(); } var tickTime = Stats.meanOf(times) / TimeUtil.NANOSECONDS_PER_MILLISECOND; var tps = TimeUtil.MILLISECONDS_PER_SECOND / Math.max(tickTime, tickRateManager.millisecondsPerTick()); - var timeComponent = Component.empty().append(createTickTimeComponent(tickTime)).append(". ").append(createTpsComponent(tickRateManager, tps)); - return prefix.append(CommonComponents.SPACE).append(timeComponent); - } + var tickTimeComponent = Component.literal(TIME_FORMATTER.format(tickTime)).withColor(CommonColors.LIGHT_GRAY); + var tpsComponent = Component.literal(TIME_FORMATTER.format(tps)).withColor(calculateTPSColor(tickRateManager, tps)); - private static Component createDimensionComponent(ServerLevel dimension) { - var regName = dimension.dimension().location(); - var dimensionTypes = dimension.registryAccess().registryOrThrow(Registries.DIMENSION_TYPE); - var dimensionType = Objects.requireNonNull(dimensionTypes.getKey(dimension.dimensionType())); + MutableComponent component; - return Component.empty().append(dimension.getDescription()).withStyle(style -> style - .withColor(ChatFormatting.GREEN) - .withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - Component.translatable("commands.neoforge.tps.summary.dimension.tooltip", regName.toString(), dimensionType.toString())))); - } + if (dimension == null) + component = Component.translatable("commands.neoforge.tps.overall", tpsComponent, tickTimeComponent); + else { + var dimensionType = dimension.dimensionTypeRegistration(); - private static Component createTickTimeComponent(double tickTime) { - return Component.translatable("commands.neoforge.tps.mean_tick_time", Component.literal(TIME_FORMATTER.format(tickTime)) - .withColor(CommonColors.GRAY)) - .withStyle(style -> style.withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - Component.translatable("commands.neoforge.tps.mean_tick_time.tooltip")))); - } + var dimensionName = Component.empty().append(dimension.getDescription()).withStyle(style -> style + .withColor(ChatFormatting.GREEN) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable( + "commands.neoforge.tps.dimension.tooltip", + dimension.dimension().location().toString(), + dimensionType.getRegisteredName())))); + + component = Component.translatable("commands.neoforge.tps.dimension", dimensionName, tpsComponent, tickTimeComponent); + } - private static Component createTpsComponent(TickRateManager tickRateManager, double tps) { - return Component.translatable("commands.neoforge.tps.mean_tps", Component.literal(TIME_FORMATTER.format(tps)).withColor(calculateTPSColor(tickRateManager, tps))) - .withStyle(style -> style.withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - Component.translatable("commands.neoforge.tps.mean_tps.tooltip")))); + return component.withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("commands.neoforge.tps.tooltip", tickRateManager.tickrate())))); } private static int calculateTPSColor(TickRateManager tickRateManager, double tps) { diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index b35a2a8ac5..b42242b0c1 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -80,14 +80,10 @@ "commands.neoforge.setdim.invalid.dim": "The dimension ID specified (%1$s) is not valid.", "commands.neoforge.setdim.invalid.nochange": "The entity selected (%1$s) is already in the dimension specified (%2$s).", "commands.neoforge.setdim.deprecated": "This command is deprecated for removal in 1.17, use %s instead.", - "commands.neoforge.tps.invalid": "Invalid dimension %1$s Possible values: %2$s", - "commands.neoforge.tps.summary.overall": "Overall:", - "commands.neoforge.tps.summary.dimension": "'%s':", - "commands.neoforge.tps.summary.dimension.tooltip": "%s (%s)", - "commands.neoforge.tps.mean_tps": "Mean TPS: %s", - "commands.neoforge.tps.mean_tps.tooltip": "Closer to 20 is better", - "commands.neoforge.tps.mean_tick_time": "Mean tick time: %s ms", - "commands.neoforge.tps.mean_tick_time.tooltip": "Lower is better, Higher is worse", + "commands.neoforge.tps.overall": "Overall: %s TPS (%s ms/tick)", + "commands.neoforge.tps.tooltip": "Mean TPS; higher is better. Target TPS: %s", + "commands.neoforge.tps.dimension": "%s: %s TPS (%s ms/tick)", + "commands.neoforge.tps.dimension.tooltip": "%s (%s)", "commands.neoforge.mods.list": "Mod List: %1$s", "commands.neoforge.tracking.entity.enabled": "Entity tracking enabled for %d seconds.", "commands.neoforge.tracking.entity.reset": "Entity timings data has been cleared!", From 60823c4877a9a0c2017dd14d927f51c7b0f34f6c Mon Sep 17 00:00:00 2001 From: Apex Date: Sun, 25 Aug 2024 15:18:17 +0100 Subject: [PATCH 09/10] Add braces to if statement --- .../net/neoforged/neoforge/server/command/TPSCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java index 72f9d3ec63..4703bda119 100644 --- a/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java +++ b/src/main/java/net/neoforged/neoforge/server/command/TPSCommand.java @@ -71,9 +71,9 @@ private static Component createComponent(MinecraftServer server, @Nullable Serve MutableComponent component; - if (dimension == null) + if (dimension == null) { component = Component.translatable("commands.neoforge.tps.overall", tpsComponent, tickTimeComponent); - else { + } else { var dimensionType = dimension.dimensionTypeRegistration(); var dimensionName = Component.empty().append(dimension.getDescription()).withStyle(style -> style From c2f464d7f7659ebf131a2fc30ad813fccd74685b Mon Sep 17 00:00:00 2001 From: Apex Date: Fri, 30 Aug 2024 08:41:40 +0100 Subject: [PATCH 10/10] Append 'Dimension Type:' to dimension tooltip --- src/main/resources/assets/neoforge/lang/en_us.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index b42242b0c1..5e0e4c29db 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -83,7 +83,7 @@ "commands.neoforge.tps.overall": "Overall: %s TPS (%s ms/tick)", "commands.neoforge.tps.tooltip": "Mean TPS; higher is better. Target TPS: %s", "commands.neoforge.tps.dimension": "%s: %s TPS (%s ms/tick)", - "commands.neoforge.tps.dimension.tooltip": "%s (%s)", + "commands.neoforge.tps.dimension.tooltip": "%s (Dimension Type: %s)", "commands.neoforge.mods.list": "Mod List: %1$s", "commands.neoforge.tracking.entity.enabled": "Entity tracking enabled for %d seconds.", "commands.neoforge.tracking.entity.reset": "Entity timings data has been cleared!",