extend skill unlock packet to include ability type and improve logout handling logic
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package net.fretux.skillengine.network;
|
||||
|
||||
import net.fretux.skillengine.skilltree.AbilityNodeRegistry;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -12,32 +11,35 @@ import java.util.function.Supplier;
|
||||
public class ClientboundNodeUnlockedPacket {
|
||||
private final ResourceLocation id;
|
||||
private final int newSkillPoints;
|
||||
private final boolean ability;
|
||||
|
||||
public ClientboundNodeUnlockedPacket(ResourceLocation id, int newSkillPoints) {
|
||||
public ClientboundNodeUnlockedPacket(ResourceLocation id, int newSkillPoints, boolean ability) {
|
||||
this.id = id;
|
||||
this.newSkillPoints = newSkillPoints;
|
||||
this.ability = ability;
|
||||
}
|
||||
|
||||
public static void encode(ClientboundNodeUnlockedPacket msg, FriendlyByteBuf buf) {
|
||||
buf.writeResourceLocation(msg.id);
|
||||
buf.writeInt(msg.newSkillPoints);
|
||||
buf.writeBoolean(msg.ability);
|
||||
}
|
||||
|
||||
public static ClientboundNodeUnlockedPacket decode(FriendlyByteBuf buf) {
|
||||
ResourceLocation id = buf.readResourceLocation();
|
||||
int points = buf.readInt();
|
||||
return new ClientboundNodeUnlockedPacket(id, points);
|
||||
boolean ability = buf.readBoolean();
|
||||
return new ClientboundNodeUnlockedPacket(id, points, ability);
|
||||
}
|
||||
|
||||
public static void handle(ClientboundNodeUnlockedPacket msg, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
boolean isAbility = AbilityNodeRegistry.get(msg.id) != null;
|
||||
DistExecutor.unsafeRunWhenOn(
|
||||
Dist.CLIENT,
|
||||
() -> () -> net.fretux.skillengine.client.ClientSkillEngineBridge.handleNodeUnlocked(
|
||||
msg.id,
|
||||
msg.newSkillPoints,
|
||||
isAbility
|
||||
msg.ability
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraftforge.network.simple.SimpleChannel;
|
||||
|
||||
public class PacketHandler {
|
||||
|
||||
private static final String PROTOCOL = "2";
|
||||
private static final String PROTOCOL = "3";
|
||||
public static final SimpleChannel CHANNEL = NetworkRegistry.ChannelBuilder
|
||||
.named(ResourceLocation.fromNamespaceAndPath(SkillEngine.MODID, "network"))
|
||||
.clientAcceptedVersions(PROTOCOL::equals)
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ServerboundUnlockNodePacket {
|
||||
PacketHandler.syncSkillsTo(player);
|
||||
PacketHandler.CHANNEL.send(
|
||||
PacketDistributor.PLAYER.with(() -> player),
|
||||
new ClientboundNodeUnlockedPacket(node.getId(), data.getSkillPoints())
|
||||
new ClientboundNodeUnlockedPacket(node.getId(), data.getSkillPoints(), false)
|
||||
);
|
||||
} else {
|
||||
SkillEngine.LOGGER.info("[SKILLENGINE] Rejecting unlock for {}", node.getId());
|
||||
@@ -57,7 +57,7 @@ public class ServerboundUnlockNodePacket {
|
||||
PacketHandler.syncSkillsTo(player);
|
||||
PacketHandler.CHANNEL.send(
|
||||
PacketDistributor.PLAYER.with(() -> player),
|
||||
new ClientboundNodeUnlockedPacket(ability.getId(), data.getSkillPoints())
|
||||
new ClientboundNodeUnlockedPacket(ability.getId(), data.getSkillPoints(), true)
|
||||
);
|
||||
} else {
|
||||
SkillEngine.LOGGER.info("[SKILLENGINE] Rejecting ability unlock for {}", ability.getId());
|
||||
|
||||
Reference in New Issue
Block a user