From 505943621c17bc61eaf0c7bb892df38e34f3a2c4 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 21 Apr 2025 19:45:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8E=A9=E5=AE=B6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../capability/player/PlayerVariable.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java index 46bc0df92..22fbe2e67 100644 --- a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java +++ b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java @@ -52,11 +52,38 @@ public class PlayerVariable implements INBTSerializable { PacketDistributor.sendToPlayer(player, new PlayerVariablesSyncMessage(player.getId(), player.getData(ModAttachments.PLAYER_VARIABLE).compareAndUpdate())); } + @SubscribeEvent + public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) { + if (!(event.getEntity() instanceof ServerPlayer player)) return; + + PacketDistributor.sendToPlayer(player, new PlayerVariablesSyncMessage(player.getId(), player.getData(ModAttachments.PLAYER_VARIABLE).compareAndUpdate())); + } + + @SubscribeEvent + public static void onPlayerChangeDimension(PlayerEvent.PlayerChangedDimensionEvent event) { + if (!(event.getEntity() instanceof ServerPlayer player)) return; + + PacketDistributor.sendToPlayer(player, new PlayerVariablesSyncMessage(player.getId(), player.getData(ModAttachments.PLAYER_VARIABLE).forceUpdate())); + } + public PlayerVariable watch() { this.old = this.copy(); return this; } + public Map forceUpdate() { + var map = new HashMap(); + + for (var type : Ammo.values()) { + map.put((byte) type.ordinal(), type.get(this)); + } + + map.put((byte) -1, this.tacticalSprint ? 1 : 0); + map.put((byte) -2, this.edit ? 1 : 0); + + return map; + } + public Map compareAndUpdate() { var map = new HashMap(); var old = this.old == null ? new PlayerVariable() : this.old;