Implement detection for resetting points and add remaining skillpoints in tree screen

This commit is contained in:
2025-11-25 22:23:14 +01:00
parent ec49eb4385
commit dd15eb9327
9 changed files with 116 additions and 8 deletions
@@ -12,9 +12,11 @@ import java.util.function.Supplier;
public class ClientboundSyncSkillsPacket {
private final Set<ResourceLocation> unlocked;
private final int skillPoints;
public ClientboundSyncSkillsPacket(Set<ResourceLocation> unlocked) {
public ClientboundSyncSkillsPacket(Set<ResourceLocation> unlocked, int skillPoints) {
this.unlocked = unlocked;
this.skillPoints = skillPoints;
}
public static void encode(ClientboundSyncSkillsPacket msg, FriendlyByteBuf buf) {
@@ -22,6 +24,7 @@ public class ClientboundSyncSkillsPacket {
for (ResourceLocation id : msg.unlocked) {
buf.writeResourceLocation(id);
}
buf.writeInt(msg.skillPoints);
}
public static ClientboundSyncSkillsPacket decode(FriendlyByteBuf buf) {
@@ -30,13 +33,15 @@ public class ClientboundSyncSkillsPacket {
for (int i = 0; i < size; i++) {
result.add(buf.readResourceLocation());
}
return new ClientboundSyncSkillsPacket(result);
int points = buf.readInt();
return new ClientboundSyncSkillsPacket(result, points);
}
public static void handle(ClientboundSyncSkillsPacket msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
SkilltreeClientState.setUnlocked(msg.unlocked);
SkilltreeClientState.setCurrentSkillPoints(msg.skillPoints);
});
ctx.get().setPacketHandled(true);
}
}
}