extend skill unlock packet to include ability type and improve logout handling logic
This commit is contained in:
@@ -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))
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user