make various fixes

This commit is contained in:
2026-07-23 13:37:23 +02:00
parent 402e45e5a9
commit 9eb418afb0
10 changed files with 166 additions and 24 deletions
@@ -8,8 +8,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fretux.ascend.player.PlayerStats;
import net.fretux.ascend.player.PlayerStatsProvider;
import net.fretux.ascend.player.StatEffects;
import net.fretux.ascend.network.PacketHandler;
import net.fretux.ascend.network.ClientboundSyncStatsPacket;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
@@ -17,7 +15,6 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.network.PacketDistributor;
public class AscendCommand {
@SubscribeEvent
@@ -67,7 +64,7 @@ public class AscendCommand {
target.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
stats.setAttributeLevel(attr, value);
StatEffects.applyAll(target);
sync(target, stats);
PlayerStatsProvider.sync(target);
ctx.getSource().sendSuccess(() ->
Component.literal("Set " + target.getName().getString() + "'s " + attr + " to " + value), true);
});
@@ -80,7 +77,7 @@ public class AscendCommand {
target.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
stats.addAscendXP(amount);
StatEffects.applyAll(target);
sync(target, stats);
PlayerStatsProvider.sync(target);
ctx.getSource().sendSuccess(() ->
Component.literal("Added " + amount + " Ascend XP to " + target.getName().getString()), true);
});
@@ -93,17 +90,11 @@ public class AscendCommand {
PlayerStats fresh = new PlayerStats();
stats.deserializeNBT(fresh.serializeNBT());
StatEffects.applyAll(target);
sync(target, stats);
PlayerStatsProvider.sync(target);
ctx.getSource().sendSuccess(() ->
Component.literal("Reset " + target.getName().getString() + "'s Ascend stats."), true);
});
return 1;
}
private static void sync(ServerPlayer player, PlayerStats stats) {
PacketHandler.INSTANCE.send(
PacketDistributor.PLAYER.with(() -> player),
new ClientboundSyncStatsPacket(stats.serializeNBT())
);
}
}
@@ -45,8 +45,13 @@ public class PlayerEvents {
@SubscribeEvent
public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
if (!event.getEntity().level().isClientSide) {
PlayerStatsProvider.sync(event.getEntity());
float healthBeforeFortitude = event.getEntity().getHealth();
StatEffects.applyAll(event.getEntity());
if (Math.abs(healthBeforeFortitude - 20.0F) < 0.001F
&& event.getEntity().getMaxHealth() > healthBeforeFortitude) {
event.getEntity().setHealth(event.getEntity().getMaxHealth());
}
PlayerStatsProvider.sync(event.getEntity());
}
}
}
@@ -1,5 +1,6 @@
package net.fretux.ascend.network;
import net.fretux.ascend.advancement.AscendAdvancements;
import net.fretux.ascend.compat.AscendMMCompat;
import net.fretux.ascend.item.RemembranceEssenceItem;
import net.fretux.ascend.player.PlayerStatsProvider;
@@ -41,6 +42,7 @@ public class ServerboundShrineChoicePacket {
net.fretux.ascend.player.StatEffects.applyAll(player);
player.sendSystemMessage(Component.literal("YOU ARE A BLANK SLATE. EMPTY. FORGOTTEN."));
RemembranceEssenceItem.consume(player);
AscendAdvancements.grant(player, "use_shrine");
} else {
player.sendSystemMessage(Component.literal("YOUR MIND IS TOO EMPTY TO BE WORTH MY TOUCH."));
player.hurt(player.level().damageSources().magic(), 4.0F);
@@ -60,6 +62,7 @@ public class ServerboundShrineChoicePacket {
sanity.setInsanity(0);
player.sendSystemMessage(Component.literal("YOUR MIND EXPANDS AS IT BREAKS."));
RemembranceEssenceItem.consume(player);
AscendAdvancements.grant(player, "use_shrine");
} else {
player.sendSystemMessage(Component.literal("YOUR MIND IS NOT YET CLEAR ENOUGH."));
}
@@ -76,6 +79,7 @@ public class ServerboundShrineChoicePacket {
});
player.sendSystemMessage(Component.literal("THE SHRINE RESTORES YOUR FRACTURED MIND."));
RemembranceEssenceItem.consume(player);
AscendAdvancements.grant(player, "use_shrine");
} else {
player.sendSystemMessage(Component.literal("YOU LACK THE KNOWLEDGE TO REST."));
}
@@ -5,8 +5,6 @@ import net.fretux.ascend.player.StatEffects;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.PacketDistributor;
import net.minecraft.nbt.CompoundTag;
import java.util.function.Supplier;
@@ -41,11 +39,7 @@ public class ServerboundSpendPointPacket {
player.setHealth(Math.min(player.getHealth() + gainedMaxHealth, player.getMaxHealth()));
}
}
CompoundTag data = stats.serializeNBT();
PacketHandler.INSTANCE.send(
PacketDistributor.PLAYER.with(() -> player),
new ClientboundSyncStatsPacket(data)
);
PlayerStatsProvider.sync(player);
}
});
});
@@ -13,11 +13,14 @@ public class PlayerStats {
"light_scaling", "medium_scaling", "heavy_scaling", "magic_scaling"
};
private final Map<String, Integer> attributes = new HashMap<>();
private final Map<String, Integer> lastRespecBuild = new HashMap<>();
private int ascendLevel = 1;
private int ascendXP = 0;
private int unspentPoints = getPointsPerLevel();
private int maxAscendLevel = getConfiguredMaxAscendLevel();
private int maxAttributePoints = getConfiguredMaxAttributePoints();
private int respecCount = 0;
private boolean everInvestedWeaponScaling = false;
public PlayerStats() {
for (String attr : ATTRIBUTE_KEYS) {
attributes.put(attr, 0);
@@ -77,6 +80,9 @@ public class PlayerStats {
}
unspentPoints -= 1;
attributes.put(attribute, level + 1);
if (isWeaponScaling(attribute)) {
everInvestedWeaponScaling = true;
}
return true;
}
@@ -100,6 +106,9 @@ public class PlayerStats {
if (!attributes.containsKey(attribute)) return;
int clamped = Math.max(0, Math.min(level, getMaxAttributePoints()));
attributes.put(attribute, clamped);
if (clamped > 0 && isWeaponScaling(attribute)) {
everInvestedWeaponScaling = true;
}
}
public int getMaxMana() {
@@ -133,14 +142,47 @@ public class PlayerStats {
public void refundAllPoints() {
int totalSpent = 0;
for (String key : attributes.keySet()) {
int lvl = attributes.get(key);
Map<String, Integer> refundedBuild = new HashMap<>();
for (String key : ATTRIBUTE_KEYS) {
int lvl = attributes.getOrDefault(key, 0);
totalSpent += lvl;
refundedBuild.put(key, lvl);
attributes.put(key, 0);
}
if (totalSpent > 0) {
lastRespecBuild.clear();
lastRespecBuild.putAll(refundedBuild);
respecCount++;
}
unspentPoints += totalSpent;
}
public int getRespecCount() {
return respecCount;
}
public boolean hasEverInvestedWeaponScaling() {
return everInvestedWeaponScaling;
}
public boolean hasNearlyRestoredLastBuild() {
if (lastRespecBuild.isEmpty()) return false;
int originalTotal = 0;
int currentTotal = 0;
int totalDifference = 0;
for (String key : ATTRIBUTE_KEYS) {
int original = lastRespecBuild.getOrDefault(key, 0);
int current = attributes.getOrDefault(key, 0);
originalTotal += original;
currentTotal += current;
totalDifference += Math.abs(original - current);
}
int allowedDifference = Math.max(2, (int) Math.ceil(originalTotal * 0.05D));
return originalTotal > 0 && currentTotal > 0
&& currentTotal >= originalTotal - allowedDifference
&& totalDifference <= allowedDifference;
}
public boolean hasUsedMoonseye() {
return hasUsedMoonseye;
}
@@ -159,11 +201,18 @@ public class PlayerStats {
tag.putInt("MaxAttributePoints", getMaxAttributePoints());
tag.putInt("Knowledge", knowledge);
tag.putBoolean("HasUsedMoonseye", hasUsedMoonseye);
tag.putInt("RespecCount", respecCount);
tag.putBoolean("EverInvestedWeaponScaling", everInvestedWeaponScaling);
CompoundTag attrTag = new CompoundTag();
for (Map.Entry<String, Integer> entry : attributes.entrySet()) {
attrTag.putInt(entry.getKey(), entry.getValue());
}
tag.put("Attributes", attrTag);
CompoundTag respecBuildTag = new CompoundTag();
for (Map.Entry<String, Integer> entry : lastRespecBuild.entrySet()) {
respecBuildTag.putInt(entry.getKey(), entry.getValue());
}
tag.put("LastRespecBuild", respecBuildTag);
return tag;
}
@@ -189,6 +238,19 @@ public class PlayerStats {
attributes.put(key, Math.max(0, Math.min(loaded, getMaxAttributePoints())));
}
}
respecCount = Math.max(0, tag.getInt("RespecCount"));
everInvestedWeaponScaling = tag.contains("EverInvestedWeaponScaling")
? tag.getBoolean("EverInvestedWeaponScaling")
: getAttributeLevel("light_scaling") > 0
|| getAttributeLevel("medium_scaling") > 0
|| getAttributeLevel("heavy_scaling") > 0;
lastRespecBuild.clear();
if (tag.contains("LastRespecBuild")) {
CompoundTag respecBuildTag = tag.getCompound("LastRespecBuild");
for (String key : ATTRIBUTE_KEYS) {
lastRespecBuild.put(key, Math.max(0, respecBuildTag.getInt(key)));
}
}
if (tag.contains("Knowledge")) {
knowledge = Math.max(0, tag.getInt("Knowledge"));
}
@@ -212,4 +274,10 @@ public class PlayerStats {
private static int getConfiguredMaxAttributePoints() {
return AscendConfig.COMMON.maxAttributePoints.get();
}
private static boolean isWeaponScaling(String attribute) {
return "light_scaling".equals(attribute)
|| "medium_scaling".equals(attribute)
|| "heavy_scaling".equals(attribute);
}
}
@@ -1,5 +1,6 @@
package net.fretux.ascend.player;
import net.fretux.ascend.advancement.AscendAdvancements;
import net.fretux.ascend.network.ClientboundSyncStatsPacket;
import net.fretux.ascend.network.PacketHandler;
import net.minecraft.core.Direction;
@@ -43,6 +44,7 @@ public class PlayerStatsProvider implements ICapabilitySerializable<CompoundTag>
return;
}
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
AscendAdvancements.checkMilestones(serverPlayer, stats);
CompoundTag data = stats.serializeNBT();
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> serverPlayer),
new ClientboundSyncStatsPacket(data));