Store remaining turn seconds in PacketBattlePing
This commit is contained in:
parent
cd6106a19c
commit
4e38f4a89a
2 changed files with 5 additions and 2 deletions
|
@ -461,7 +461,7 @@ public class Battle {
|
||||||
if (!isServer) {
|
if (!isServer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PacketBattlePing pingPacket = new PacketBattlePing(getId());
|
PacketBattlePing pingPacket = new PacketBattlePing(getId(), (int)(timer / 1000000000L));
|
||||||
for (Combatant p : players.values()) {
|
for (Combatant p : players.values()) {
|
||||||
PacketDistributor.sendToPlayer((ServerPlayer)p.entity, pingPacket);
|
PacketDistributor.sendToPlayer((ServerPlayer)p.entity, pingPacket);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,14 @@ import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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 CustomPacketPayload.Type<PacketBattlePing> TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(TurnBasedMinecraftMod.MODID, "network_packetbattleping"));
|
||||||
|
|
||||||
public static final StreamCodec<ByteBuf, PacketBattlePing> STREAM_CODEC = StreamCodec.composite(
|
public static final StreamCodec<ByteBuf, PacketBattlePing> STREAM_CODEC = StreamCodec.composite(
|
||||||
ByteBufCodecs.VAR_INT,
|
ByteBufCodecs.VAR_INT,
|
||||||
PacketBattlePing::battleID,
|
PacketBattlePing::battleID,
|
||||||
|
ByteBufCodecs.VAR_INT,
|
||||||
|
PacketBattlePing::remainingSeconds,
|
||||||
PacketBattlePing::new
|
PacketBattlePing::new
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ public record PacketBattlePing(int battleID) implements CustomPacketPayload {
|
||||||
}
|
}
|
||||||
TurnBasedMinecraftMod.proxy.setBattleGuiAsGui();
|
TurnBasedMinecraftMod.proxy.setBattleGuiAsGui();
|
||||||
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
|
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
|
||||||
|
TurnBasedMinecraftMod.proxy.setBattleGuiTime(pkt.remainingSeconds);
|
||||||
}).exceptionally(e -> {
|
}).exceptionally(e -> {
|
||||||
ctx.disconnect(Component.literal("Exception handling PacketBattlePing! " + e.getMessage()));
|
ctx.disconnect(Component.literal("Exception handling PacketBattlePing! " + e.getMessage()));
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue