feat: revamped hud
Release / build-and-release (push) Successful in 1m48s

This commit is contained in:
darwincereska
2026-05-10 15:54:00 -04:00
parent dce135c857
commit 13fd72d304
3 changed files with 56 additions and 14 deletions
+1 -1
View File
@@ -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
@@ -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;
@@ -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,7 +234,16 @@ public final class HudService {
BossBar.Color.RED,
BossBar.Style.PROGRESS
));
bossBar.setName(Text.literal(configSupplier.get().hud().bountyBossbar().title() + ": " + totalValue + " souls | " + DurationFormatter.formatSeconds(remainingSeconds)));
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)) {
@@ -243,12 +254,12 @@ public final class HudService {
private List<Text> buildSidebarLines(ServerPlayerEntity player, long nowEpochMillis) {
List<StoredBounty> activeBounties = bountyService.activeBountiesForTarget(player.getUuid());
List<Text> 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
@@ -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);
}
}