Implement rebinding, Translation support and small adjustments to balance

This commit is contained in:
2025-11-09 23:00:12 +01:00
parent 28a0327363
commit 7be17457a3
6 changed files with 61 additions and 83 deletions
@@ -22,6 +22,12 @@ public class StatsScreen extends Screen {
private int topPos;
private final Minecraft mc = Minecraft.getInstance();
private final Map<String, Button> plusButtons = new HashMap<>();
private String hoveredAttributeKey = null;
public StatsScreen() {
super(Component.literal("Ascend Stats"));
}
private static final String[] ATTRIBUTES = new String[]{
"strength", "agility", "fortitude", "intelligence",
@@ -29,49 +35,13 @@ public class StatsScreen extends Screen {
"light_scaling", "medium_scaling", "heavy_scaling", "magic_scaling"
};
private final Map<String, Button> plusButtons = new HashMap<>();
// --- Tooltips for attributes ---
// Use translation keys for attribute labels and tooltips
private static final Map<String, Component> ATTRIBUTE_TOOLTIPS = new HashMap<>();
static {
ATTRIBUTE_TOOLTIPS.put("strength", Component.literal(
"Strength: Increases melee damage, knockback and armor penetration."
));
ATTRIBUTE_TOOLTIPS.put("agility", Component.literal(
"Agility: Increases movement speed and mobility."
));
ATTRIBUTE_TOOLTIPS.put("fortitude", Component.literal(
"Fortitude: Increases max health and knockback resistance."
));
ATTRIBUTE_TOOLTIPS.put("intelligence", Component.literal(
"Intelligence: Boosts mana, spell power, mana regen & cooldown reduction (with Iron's Spellbooks)."
));
ATTRIBUTE_TOOLTIPS.put("willpower", Component.literal(
"Willpower: Reduces sanity drain and improves stamina/tempo in harsh conditions."
));
ATTRIBUTE_TOOLTIPS.put("charisma", Component.literal(
"Charisma: Increases max mana and improves trade deals."
));
ATTRIBUTE_TOOLTIPS.put("light_scaling", Component.literal(
"Light Scaling: Increases damage with light weapons that scale with this stat."
));
ATTRIBUTE_TOOLTIPS.put("medium_scaling", Component.literal(
"Medium Scaling: Increases damage with medium weapons that scale with this stat."
));
ATTRIBUTE_TOOLTIPS.put("heavy_scaling", Component.literal(
"Heavy Scaling: Increases damage with heavy weapons that scale with this stat."
));
ATTRIBUTE_TOOLTIPS.put("magic_scaling", Component.literal(
"Magic Scaling: Increases spell power, mana regen & cooldown reduction for scaling spells."
));
}
// which attribute label the mouse is currently over (for tooltip)
private String hoveredAttributeKey = null;
public StatsScreen() {
super(Component.literal("Ascend Stats"));
for (String key : ATTRIBUTES) {
ATTRIBUTE_TOOLTIPS.put(key, Component.translatable("ascend.attribute." + key + ".desc"));
}
}
@Override
@@ -108,7 +78,8 @@ public class StatsScreen extends Screen {
RenderSystem.enableBlend();
gui.fill(leftPos - 4, topPos - 4, leftPos + WIDTH + 4, topPos + HEIGHT + 4, 0xAA000000);
RenderSystem.disableBlend();
gui.drawCenteredString(this.font, this.title, this.width / 2, topPos + 8, 0xFFFFFF);
gui.drawCenteredString(this.font, Component.translatable("ascend.stats.title"), this.width / 2, topPos + 8, 0xFFFFFF);
hoveredAttributeKey = null;
if (mc.player != null) {
mc.player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
@@ -116,26 +87,25 @@ public class StatsScreen extends Screen {
int xp = stats.getAscendXP();
int xpNext = stats.getXPToNextAscendLevel();
int unspent = stats.getUnspentPoints();
String levelStr = "Level: " + level + "/" + 20;
gui.drawString(font, levelStr, leftPos + 10, topPos + 24, 0xFFFF55);
gui.drawString(font, Component.translatable("ascend.stats.level", level, 20), leftPos + 10, topPos + 24, 0xFFFF55);
if (level < 20) {
String xpStr = "Ascend XP: " + xp + " / " + xpNext;
gui.drawString(font, xpStr, leftPos + 10, topPos + 36, 0xAAAAAA);
gui.drawString(font, Component.translatable("ascend.stats.xp", xp, xpNext), leftPos + 10, topPos + 36, 0xAAAAAA);
} else {
gui.drawString(font, "Ascend XP: MAX", leftPos + 10, topPos + 36, 0xAAAAAA);
gui.drawString(font, Component.translatable("ascend.stats.xp_max"), leftPos + 10, topPos + 36, 0xAAAAAA);
}
String ptsStr = "Unspent Points: " + unspent;
int ptsWidth = font.width(ptsStr);
gui.drawString(font, ptsStr,
leftPos + WIDTH - 10 - ptsWidth, topPos + 24, 0x55FF55);
gui.drawString(font, Component.translatable("ascend.stats.unspent", unspent),
leftPos + WIDTH - 10 - font.width("Unspent Points: " + unspent), topPos + 24, 0x55FF55);
int y = topPos + 55;
for (String key : ATTRIBUTES) {
int attrLevel = stats.getAttributeLevel(key);
int cost = stats.getCostToUpgrade(key);
String niceName = formatAttributeName(key);
String label = niceName + ": " + attrLevel;
Component name = Component.translatable("ascend.attribute." + key);
Component label = Component.translatable("ascend.attribute.display", name, attrLevel);
int labelX = leftPos + 10;
gui.drawString(font, label, labelX, y, 0xFFFFFF);
Button plus = plusButtons.get(key);
if (plus != null) {
plus.setX(leftPos + WIDTH - 40);
@@ -143,17 +113,19 @@ public class StatsScreen extends Screen {
plus.active = (unspent >= cost);
plus.setMessage(Component.literal("+" + cost));
}
int labelWidth = font.width(label);
int labelHeight = font.lineHeight;
if (mouseX >= labelX && mouseX <= labelX + labelWidth
&& mouseY >= y && mouseY <= y + labelHeight) {
&& mouseY >= y && mouseY <= y + font.lineHeight) {
hoveredAttributeKey = key;
}
y += 16;
}
});
}
super.render(gui, mouseX, mouseY, partialTicks);
if (hoveredAttributeKey != null) {
Component tooltip = ATTRIBUTE_TOOLTIPS.get(hoveredAttributeKey);
if (tooltip != null) {
@@ -162,11 +134,6 @@ public class StatsScreen extends Screen {
}
}
private String formatAttributeName(String key) {
String withSpaces = key.replace('_', ' ');
return withSpaces.substring(0, 1).toUpperCase() + withSpaces.substring(1);
}
@Override
public boolean isPauseScreen() {
return false;
@@ -1,6 +1,5 @@
package net.fretux.ascend.network;
import net.fretux.ascend.player.PlayerStats;
import net.fretux.ascend.player.PlayerStatsProvider;
import net.fretux.ascend.player.StatEffects;
import net.minecraft.client.Minecraft;
@@ -35,13 +34,6 @@ public class ClientboundSyncStatsPacket {
stats.deserializeNBT(data);
StatEffects.applyAll(mc.player);
stats.deserializeNBT(data);
System.out.println("[CLIENT] Before sync: points="
+ player.getCapability(PlayerStatsProvider.PLAYER_STATS)
.map(PlayerStats::getUnspentPoints).orElse(-1));
stats.deserializeNBT(data);
System.out.println("[CLIENT] After sync: points="
+ player.getCapability(PlayerStatsProvider.PLAYER_STATS)
.map(PlayerStats::getUnspentPoints).orElse(-1));
});
}
ctx.get().setPacketHandled(true);
@@ -2,7 +2,6 @@ package net.fretux.ascend.network;
import net.fretux.ascend.AscendMod;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
@@ -13,10 +12,6 @@ public class PacketHandler {
private static int id = 0;
public static void register() {
System.out.println("[Ascend] Registering network packets...");
System.out.println("[Ascend] Registering packets on side: " +
(FMLEnvironment.dist.isClient() ? "CLIENT" : "SERVER"));
INSTANCE = NetworkRegistry.newSimpleChannel(
new ResourceLocation(AscendMod.MODID, "main"),
() -> PROTOCOL_VERSION,
@@ -3,7 +3,6 @@ package net.fretux.ascend.network;
import net.fretux.ascend.player.PlayerStatsProvider;
import net.fretux.ascend.player.StatEffects;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.PacketDistributor;
@@ -40,14 +39,6 @@ public class ServerboundSpendPointPacket {
PacketDistributor.PLAYER.with(() -> player),
new ClientboundSyncStatsPacket(data)
);
player.sendSystemMessage(Component.literal("You increased " + attribute + "!"));
} else {
int level = stats.getAttributeLevel(attribute);
int cost = stats.getCostToUpgrade(attribute);
int have = stats.getUnspentPoints();
player.sendSystemMessage(Component.literal(
"Not enough points (" + have + "/" + cost + ") to increase " + attribute + " (lvl " + level + ")."
));
}
});
});
@@ -62,7 +62,7 @@ public final class StatEffects {
if (kb != null) {
kb.removeModifier(STRENGTH_KNOCKBACK_UUID);
if (strengthLevel > 0) {
double kbBonus = strengthLevel * 0.03d * getScaling();
double kbBonus = strengthLevel * 0.015d * getScaling();
kb.addTransientModifier(new AttributeModifier(
STRENGTH_KNOCKBACK_UUID,
"Ascend Strength knockback bonus",
@@ -78,7 +78,7 @@ public final class StatEffects {
if (move != null) {
move.removeModifier(AGILITY_SPEED_UUID);
if (agilityLevel > 0) {
double bonus = agilityLevel * 0.002d * getScaling();
double bonus = agilityLevel * 0.0005d * getScaling();
move.addTransientModifier(new AttributeModifier(
AGILITY_SPEED_UUID,
"Ascend Agility speed bonus",