diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java index a5f4bb1..39a7644 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java @@ -18,6 +18,8 @@ import java.util.concurrent.atomic.AtomicInteger; public class BattleGui extends Screen { private AtomicInteger timeRemaining; + + private int timerMax; private boolean turnTimerEnabled; private long lastInstant; private long elapsedTime; @@ -82,6 +84,7 @@ public class BattleGui extends Screen { public BattleGui() { super(new TextComponent("Battle Gui")); timeRemaining = new AtomicInteger((int) (Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L)); + timerMax = timeRemaining.get(); lastInstant = System.nanoTime(); elapsedTime = 0; state = MenuState.MAIN_MENU; @@ -104,7 +107,7 @@ public class BattleGui extends Screen { if (TurnBasedMinecraftMod.proxy.getLocalBattle() != null) { TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.DECISION); } - timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds()); + timeRemaining.set(timerMax); elapsedTime = 0; lastInstant = System.nanoTime(); setState(MenuState.MAIN_MENU); @@ -359,4 +362,8 @@ public class BattleGui extends Screen { public void setTurnTimerEnabled(boolean enabled) { turnTimerEnabled = enabled; } + + public void setTurnTimerMax(int timerMax) { + this.timerMax = timerMax; + } } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java index e57b67f..7f073eb 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java @@ -60,6 +60,11 @@ public class ClientProxy extends CommonProxy { battleGui.setTurnTimerEnabled(enabled); } + @Override + public void setBattleGuiTurnTimerMax(int timeMax) { + battleGui.setTurnTimerMax(timeMax); + } + @Override public void battleGuiTurnBegin() { battleGui.turnBegin(); diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java index 6a8882c..cf192de 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java @@ -445,7 +445,7 @@ public class Battle { if (!isServer) { return; } - PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()); + PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()); for (Combatant p : players.values()) { TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) p.entity), infoPacket); } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java index 0d02f9f..6f9ebdc 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java @@ -63,6 +63,8 @@ public class CommonProxy public void setBattleGuiAsGui() {} public void setBattleGuiTurnTimerEnabled(boolean enabled) {} + + public void setBattleGuiTurnTimerMax(int timeMax) {} public void battleGuiTurnBegin() {} diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleInfo.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleInfo.java index 2d1ca6d..515fb0d 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleInfo.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleInfo.java @@ -16,6 +16,8 @@ public class PacketBattleInfo private Collection sideA; private Collection sideB; private long decisionNanos; + + private long maxDecisionNanos; private boolean turnTimerEnabled; public PacketBattleInfo() @@ -23,14 +25,16 @@ public class PacketBattleInfo sideA = new ArrayList(); sideB = new ArrayList(); decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(); + maxDecisionNanos = decisionNanos; turnTimerEnabled = false; } - public PacketBattleInfo(Collection sideA, Collection sideB, long decisionNanos, boolean turnTimerEnabled) + public PacketBattleInfo(Collection sideA, Collection sideB, long decisionNanos, long maxDecisionNanos, boolean turnTimerEnabled) { this.sideA = sideA; this.sideB = sideB; this.decisionNanos = decisionNanos; + this.maxDecisionNanos = maxDecisionNanos; this.turnTimerEnabled = turnTimerEnabled; } @@ -44,6 +48,7 @@ public class PacketBattleInfo buf.writeInt(id); } buf.writeLong(msg.decisionNanos); + buf.writeLong(msg.maxDecisionNanos); buf.writeBoolean(msg.turnTimerEnabled); } @@ -59,8 +64,9 @@ public class PacketBattleInfo sideB.add(buf.readInt()); } long decisionNanos = buf.readLong(); + long maxDecisionNanos = buf.readLong(); boolean turnTimerEnabled = buf.readBoolean(); - return new PacketBattleInfo(sideA, sideB, decisionNanos, turnTimerEnabled); + return new PacketBattleInfo(sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled); } public static void handle(final PacketBattleInfo pkt, Supplier ctx) { @@ -89,6 +95,7 @@ public class PacketBattleInfo TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L)); TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled); + TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerMax((int)(pkt.maxDecisionNanos / 1000000000L)); }); ctx.get().setPacketHandled(true); } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleRequestInfo.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleRequestInfo.java index b678983..c12620e 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleRequestInfo.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleRequestInfo.java @@ -34,7 +34,7 @@ public class PacketBattleRequestInfo if(b == null) { return; } - TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get()); + TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get()); }); ctx.get().setPacketHandled(true); }