From 252b3a527269d1f58447504368295fccc6e95e06 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 22 Oct 2024 20:35:31 +0900 Subject: [PATCH] Store remaining turn seconds in PacketBattlePing --- .../burnedkirby/TurnBasedMinecraft/common/Battle.java | 2 +- .../common/networking/PacketBattlePing.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java index 1a031bd..0c33dae 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()) { TurnBasedMinecraftMod.getHandler().send(pingPacket, PacketDistributor.PLAYER.with((ServerPlayer)p.entity)); } 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 942c7ee..d640f0b 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java @@ -9,13 +9,16 @@ import java.util.function.Function; public class PacketBattlePing { private int battleID; + private int decisionSeconds; public PacketBattlePing() { battleID = 0; + decisionSeconds = 1; } - public PacketBattlePing(int battleID) { + public PacketBattlePing(int battleID, int decisionSeconds) { this.battleID = battleID; + this.decisionSeconds = decisionSeconds; } public static class Encoder implements BiConsumer { @@ -24,6 +27,7 @@ public class PacketBattlePing { @Override public void accept(PacketBattlePing pkt, RegistryFriendlyByteBuf buf) { buf.writeInt(pkt.battleID); + buf.writeInt(pkt.decisionSeconds); } } @@ -32,7 +36,7 @@ public class PacketBattlePing { @Override public PacketBattlePing apply(RegistryFriendlyByteBuf buf) { - return new PacketBattlePing(buf.readInt()); + return new PacketBattlePing(buf.readInt(), buf.readInt()); } } @@ -46,6 +50,8 @@ public class PacketBattlePing { TurnBasedMinecraftMod.proxy.createLocalBattle(pkt.battleID); } TurnBasedMinecraftMod.proxy.setBattleGuiAsGui(); + TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); + TurnBasedMinecraftMod.proxy.setBattleGuiTime(pkt.decisionSeconds); }); ctx.setPacketHandled(true); }