fix more bugs
This commit is contained in:
@@ -10,22 +10,29 @@ import java.util.function.Supplier;
|
||||
public class ClientboundNodeUnlockedPacket {
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final int newSkillPoints;
|
||||
|
||||
public ClientboundNodeUnlockedPacket(ResourceLocation id) {
|
||||
public ClientboundNodeUnlockedPacket(ResourceLocation id, int newSkillPoints) {
|
||||
this.id = id;
|
||||
this.newSkillPoints = newSkillPoints;
|
||||
}
|
||||
|
||||
public static void encode(ClientboundNodeUnlockedPacket msg, FriendlyByteBuf buf) {
|
||||
buf.writeResourceLocation(msg.id);
|
||||
buf.writeInt(msg.newSkillPoints);
|
||||
}
|
||||
|
||||
public static ClientboundNodeUnlockedPacket decode(FriendlyByteBuf buf) {
|
||||
return new ClientboundNodeUnlockedPacket(buf.readResourceLocation());
|
||||
ResourceLocation id = buf.readResourceLocation();
|
||||
int points = buf.readInt();
|
||||
return new ClientboundNodeUnlockedPacket(id, points);
|
||||
}
|
||||
|
||||
public static void handle(ClientboundNodeUnlockedPacket msg, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
// Update client-side unlocked set and points immediately so UI can reflect changes this frame
|
||||
SkilltreeClientState.unlockNode(msg.id);
|
||||
SkilltreeClientState.setCurrentSkillPoints(msg.newSkillPoints);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,10 @@ public class ServerboundUnlockNodePacket {
|
||||
data.unlockNode(node);
|
||||
SkillEngine.LOGGER.info("Node {} unlocked for {}", msg.nodeId, player.getGameProfile().getName());
|
||||
|
||||
// Send client an immediate update about the unlocked node and the new remaining points
|
||||
PacketHandler.CHANNEL.send(
|
||||
PacketDistributor.PLAYER.with(() -> player),
|
||||
new ClientboundNodeUnlockedPacket(node.getId())
|
||||
new ClientboundNodeUnlockedPacket(node.getId(), data.getSkillPoints())
|
||||
);
|
||||
} else {
|
||||
SkillEngine.LOGGER.info("Cannot unlock node {} for {} (canUnlock=false)",
|
||||
|
||||
Reference in New Issue
Block a user