From 7b50e4f9493c412fa962fb69f10f6d753875201a Mon Sep 17 00:00:00 2001 From: Jason Moiron Date: Fri, 5 Apr 2024 00:48:35 -0400 Subject: [PATCH] use chatformat for styling rocket thrust gui (#29) --- .../gcyr/common/entity/RocketEntity.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/argent_matter/gcyr/common/entity/RocketEntity.java b/src/main/java/argent_matter/gcyr/common/entity/RocketEntity.java index 10d9ae1b..91fc9267 100644 --- a/src/main/java/argent_matter/gcyr/common/entity/RocketEntity.java +++ b/src/main/java/argent_matter/gcyr/common/entity/RocketEntity.java @@ -44,6 +44,7 @@ import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -887,17 +888,18 @@ public List getSeatPositions() { } public Component getDisplayThrust() { + ChatFormatting style; var thrust = getRocketSpeed(); - String label; + if (thrust < 0.01) { - label = String.format("§c%.1f§r", thrust); + style = ChatFormatting.RED; } else if (thrust < 1.01) { - label = String.format("§6%.1f§r", thrust); + style = ChatFormatting.GOLD; } else { - label = String.format("§a%.1f§r", thrust); + style = ChatFormatting.GREEN; } - - return Component.translatable("menu.gcyr.rocket.thrust", label); + var thrustComponent = Component.literal(String.format("%.1f", thrust)).withStyle(style); + return Component.translatable("menu.gcyr.rocket.thrust", thrustComponent); } public double getRocketSpeed() {