]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Store remaining turn seconds in PacketBattlePing
authorStephen Seo <seo.disparate@gmail.com>
Tue, 22 Oct 2024 11:40:42 +0000 (20:40 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 23 Oct 2024 07:23:10 +0000 (16:23 +0900)
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java

index 67104bb33eac0637f9160dede1bfdd8c0ac03124..b7dff97abdbcb86256e3fb13811eade08d8d62d6 100644 (file)
@@ -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);
         }
index 08ed1ff4f284d4986b4a81c14326d422f94a674e..0e3c1ba59d4ff9d73edc5e110fdb064e5d7ef4c8 100644 (file)
@@ -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<PacketBattlePing> TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(TurnBasedMinecraftMod.MODID, "network_packetbattleping"));
 
     public static final StreamCodec<ByteBuf, PacketBattlePing> 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;