From 4e38f4a89aeb1b3d86a73faad5fc5f1d34792e95 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 22 Oct 2024 20:40:42 +0900 Subject: [PATCH] Store remaining turn seconds in PacketBattlePing --- .../com/burnedkirby/TurnBasedMinecraft/common/Battle.java | 2 +- .../common/networking/PacketBattlePing.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java index 67104bb..b7dff97 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java @@ -461,7 +461,7 @@ public class Battle { if (!isServer) { return; } - PacketBattlePing pingPacket = new PacketBattlePing(getId()); + PacketBattlePing pingPacket = new PacketBattlePing(getId(), (int)(timer / 1000000000L)); for (Combatant p : players.values()) { PacketDistributor.sendToPlayer((ServerPlayer)p.entity, pingPacket); } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java index 08ed1ff..0e3c1ba 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java @@ -11,12 +11,14 @@ import net.neoforged.neoforge.network.handling.IPayloadContext; import net.neoforged.neoforge.network.handling.IPayloadHandler; import org.jetbrains.annotations.NotNull; -public record PacketBattlePing(int battleID) implements CustomPacketPayload { +public record PacketBattlePing(int battleID, int remainingSeconds) implements CustomPacketPayload { public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(TurnBasedMinecraftMod.MODID, "network_packetbattleping")); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.VAR_INT, PacketBattlePing::battleID, + ByteBufCodecs.VAR_INT, + PacketBattlePing::remainingSeconds, PacketBattlePing::new ); @@ -34,6 +36,7 @@ public record PacketBattlePing(int battleID) implements CustomPacketPayload { } TurnBasedMinecraftMod.proxy.setBattleGuiAsGui(); TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); + TurnBasedMinecraftMod.proxy.setBattleGuiTime(pkt.remainingSeconds); }).exceptionally(e -> { ctx.disconnect(Component.literal("Exception handling PacketBattlePing! " + e.getMessage())); return null;