Skip to content

Commit

Permalink
use chatformat for styling rocket thrust gui (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoiron authored Apr 5, 2024
1 parent 86529f3 commit 7b50e4f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/argent_matter/gcyr/common/entity/RocketEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -887,17 +888,18 @@ public List<BlockPos> 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() {
Expand Down

0 comments on commit 7b50e4f

Please sign in to comment.