diff --git a/gradle.properties b/gradle.properties index 8550656..ac3aa87 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loom_version=1.16.1 fabric_api_version=0.141.3+1.21.11 # Mod Properties -mod_version=0.4.1 +mod_version=0.5.0 maven_group=com.g2806.soulsteal archives_base_name=soul-steal diff --git a/src/main/java/com/g2806/soulsteal/service/HudService.java b/src/main/java/com/g2806/soulsteal/service/HudService.java index bde27fb..2134064 100644 --- a/src/main/java/com/g2806/soulsteal/service/HudService.java +++ b/src/main/java/com/g2806/soulsteal/service/HudService.java @@ -5,6 +5,7 @@ import com.g2806.soulsteal.data.SoulStealDataStore; import com.g2806.soulsteal.data.StoredBounty; import com.g2806.soulsteal.service.ContractService; import com.g2806.soulsteal.util.DurationFormatter; +import com.g2806.soulsteal.util.HudTexts; import java.io.IOException; import java.io.UncheckedIOException; import java.util.ArrayList; @@ -16,10 +17,10 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.UUID; -import java.util.function.Supplier; -import net.minecraft.entity.boss.BossBar; -import net.minecraft.entity.boss.ServerBossBar; +import java.util.UUID; +import java.util.function.Supplier; +import net.minecraft.entity.boss.BossBar; +import net.minecraft.entity.boss.ServerBossBar; import net.minecraft.network.packet.s2c.play.ScoreboardDisplayS2CPacket; import net.minecraft.network.packet.s2c.play.ScoreboardObjectiveUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.ScoreboardScoreResetS2CPacket; @@ -31,6 +32,7 @@ import net.minecraft.scoreboard.ScoreboardObjective; import net.minecraft.scoreboard.number.BlankNumberFormat; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -232,8 +234,17 @@ public final class HudService { BossBar.Color.RED, BossBar.Style.PROGRESS )); - bossBar.setName(Text.literal(configSupplier.get().hud().bountyBossbar().title() + ": " + totalValue + " souls | " + DurationFormatter.formatSeconds(remainingSeconds))); - bossBar.setPercent(percent); + MutableText bossbarText = HudTexts.title(configSupplier.get().hud().bountyBossbar().title()) + .append(Text.literal(" ")) + .append(HudTexts.value(String.valueOf(totalValue), Formatting.GOLD)) + .append(Text.literal(" ")) + .append(HudTexts.value("souls", Formatting.GRAY)) + .append(Text.literal(" ")) + .append(HudTexts.value("•", Formatting.DARK_GRAY)) + .append(Text.literal(" ")) + .append(HudTexts.value(DurationFormatter.formatSeconds(remainingSeconds), Formatting.RED)); + bossBar.setName(bossbarText); + bossBar.setPercent(percent); bossBar.setVisible(true); if (!bossBar.getPlayers().contains(player)) { bossBar.addPlayer(player); @@ -243,12 +254,12 @@ public final class HudService { private List buildSidebarLines(ServerPlayerEntity player, long nowEpochMillis) { List activeBounties = bountyService.activeBountiesForTarget(player.getUuid()); List lines = new ArrayList<>(); - lines.add(Text.literal("Souls: " + soulService.balanceOf(player.getUuid())).formatted(Formatting.GOLD)); + lines.add(HudTexts.labeledValue("Souls", String.valueOf(soulService.balanceOf(player.getUuid())), Formatting.GOLD)); contractService.selectedContract(player.getUuid()).ifPresent(contract -> { long progress = contractService.progress(player.getUuid(), contract.id()); - lines.add(Text.literal("Contract: " + contract.name()).formatted(Formatting.AQUA)); - lines.add(Text.literal("Progress: " + progress + "/" + contract.amountRequired()).formatted(Formatting.GRAY)); + lines.add(HudTexts.labeledValue("Contract", contract.name(), Formatting.WHITE)); + lines.add(HudTexts.labeledValue("Progress", progress + "/" + contract.amountRequired(), Formatting.GRAY)); }); if (!activeBounties.isEmpty()) { @@ -259,9 +270,9 @@ public final class HudService { .orElse(nowEpochMillis); remainingSeconds = Math.max(0L, (remainingSeconds - nowEpochMillis + 999L) / 1000L); - lines.add(Text.literal("Bounties: " + activeBounties.size()).formatted(Formatting.RED)); - lines.add(Text.literal("Wanted Value: " + totalValue).formatted(Formatting.GOLD)); - lines.add(Text.literal("Wanted Time: " + DurationFormatter.formatSeconds(remainingSeconds)).formatted(Formatting.DARK_RED)); + lines.add(HudTexts.labeledValue("Bounties", String.valueOf(activeBounties.size()), Formatting.RED)); + lines.add(HudTexts.labeledValue("Wanted", String.valueOf(totalValue), Formatting.GOLD)); + lines.add(HudTexts.labeledValue("Time Left", DurationFormatter.formatSeconds(remainingSeconds), Formatting.DARK_RED)); } return lines; @@ -294,7 +305,7 @@ public final class HudService { return scoreboard.addObjective( objectiveName, ScoreboardCriterion.DUMMY, - Text.literal(configSupplier.get().hud().scoreboard().title()).formatted(Formatting.DARK_AQUA), + HudTexts.title(configSupplier.get().hud().scoreboard().title()), ScoreboardCriterion.RenderType.INTEGER, false, BlankNumberFormat.INSTANCE diff --git a/src/main/java/com/g2806/soulsteal/util/HudTexts.java b/src/main/java/com/g2806/soulsteal/util/HudTexts.java new file mode 100644 index 0000000..800f0c5 --- /dev/null +++ b/src/main/java/com/g2806/soulsteal/util/HudTexts.java @@ -0,0 +1,31 @@ +package com.g2806.soulsteal.util; + +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +/** Text helpers for sidebar, bossbar, and other compact HUD surfaces. */ +public final class HudTexts { + private HudTexts() { + } + + public static MutableText title(String text) { + return Text.literal(text).formatted(Formatting.DARK_AQUA, Formatting.BOLD); + } + + public static MutableText label(String text) { + return Text.literal(text).formatted(Formatting.AQUA, Formatting.BOLD); + } + + public static MutableText value(String text, Formatting formatting) { + return Text.literal(text).formatted(formatting); + } + + public static MutableText labeledValue(String label, String value, Formatting valueFormatting) { + return label(label).append(Text.literal(" ")).append(value(value, valueFormatting)); + } + + public static MutableText separator() { + return Text.literal(" ").formatted(Formatting.GRAY); + } +}