extend skill unlock packet to include ability type and improve logout handling logic

This commit is contained in:
2026-05-21 16:32:11 +02:00
parent 30310b6eb9
commit bf4452f6ac
7 changed files with 32 additions and 15 deletions
@@ -13,20 +13,19 @@ import net.minecraftforge.network.PacketDistributor;
@Mod.EventBusSubscriber(modid = SkillEngine.MODID)
public class AbilityCooldownHandler {
private static int syncCounter = 0;
@SubscribeEvent
public static void onServerTick(TickEvent.PlayerTickEvent event) {
if (event.phase != TickEvent.Phase.END) return;
if (event.player.level().isClientSide) return;
if (!(event.player instanceof ServerPlayer player)) return;
event.player.getCapability(SkillEngineCapabilities.PLAYER_SKILLS).ifPresent(data -> {
data.tickCooldowns();
syncCounter++;
if (syncCounter >= 10) {
syncCounter = 0;
data.tickTagCooldowns();
if (player.tickCount % 10 == 0) {
for (int i = 1; i <= 3; i++) {
PacketHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> (ServerPlayer) event.player),
PacketDistributor.PLAYER.with(() -> player),
new ClientboundSyncCooldownPacket(i, data.getCooldown(i))
);
}