]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Impl "disable-turn-timer", mod version 1.18.6
authorStephen Seo <seo.disparate@gmail.com>
Thu, 21 Jul 2022 03:57:10 +0000 (12:57 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 21 Jul 2022 03:57:10 +0000 (12:57 +0900)
13 files changed:
README.md
build.gradle
src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleInfo.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleRequestInfo.java
src/main/resources/META-INF/mods.toml
src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml
src/main/resources/mcmod.info

index 9b116d3b38706123fd86d5d450f81183f82e7d94..f2eefd912acf2b6488204e99e82ab59d55ba5e95 100644 (file)
--- a/README.md
+++ b/README.md
@@ -58,7 +58,7 @@ configured for them.)
 # Building
 
 Simply invoke `./gradlew build` in the mod directory and after some time the
-finished jar will be saved at "build/libs/TurnBasedMinecraft-1.18.5.jar"
+finished jar will be saved at "build/libs/TurnBasedMinecraft-1.18.6.jar"
 
 # Other notes
 
index 959074fd051b5324672e83b5f3fbbcc49fa21825..599d054d1bed459908c0a8f9f0646cec0b3a286f 100644 (file)
@@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle'
 //apply plugin: 'eclipse'
 //apply plugin: 'maven-publish'
 
-version = "1.18.5"
+version = "1.18.6"
 group = "com.burnedkirby.TurnBasedMinecraft"
 archivesBaseName = "TurnBasedMinecraft"
 
index 66fe08efe5ff50bb72e996f27af3a0b49e64873d..a5f4bb1691c17726561acf2ac40001551bb42098 100644 (file)
@@ -18,6 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 public class BattleGui extends Screen {
        private AtomicInteger timeRemaining;
+       private boolean turnTimerEnabled;
        private long lastInstant;
        private long elapsedTime;
        private MenuState state;
@@ -242,14 +243,19 @@ public class BattleGui extends Screen {
 
                String timeRemainingString = "Time remaining: ";
                int timeRemainingInt = timeRemaining.get();
-               if (timeRemainingInt > 8) {
+               if (timeRemainingInt > 8 || !turnTimerEnabled) {
                        timeRemainingString += "\u00A7a";
                } else if (timeRemainingInt > 4) {
                        timeRemainingString += "\u00A7e";
                } else {
                        timeRemainingString += "\u00A7c";
                }
-               timeRemainingString += Integer.toString(timeRemainingInt);
+
+               if (!turnTimerEnabled) {
+                       timeRemainingString += "Infinity";
+               } else {
+                       timeRemainingString += Integer.toString(timeRemainingInt);
+               }
                int stringWidth = font.width(timeRemainingString);
                fill(poseStack, width / 2 - stringWidth / 2, 5, width / 2 + stringWidth / 2, 15, 0x70000000);
                drawString(poseStack, timeRemainingString, width / 2 - stringWidth / 2, 5, 0xFFFFFFFF);
@@ -349,4 +355,8 @@ public class BattleGui extends Screen {
        private void drawString(PoseStack poseStack, String string, int x, int y, int color) {
                font.draw(poseStack, string, x, y, color);
        }
+
+       public void setTurnTimerEnabled(boolean enabled) {
+               turnTimerEnabled = enabled;
+       }
 }
index efb806075291f9e67d37ca35a86296b81c11c7e5..e57b67f7eb618a6bb3dbd8892d1caa7775170e12 100644 (file)
@@ -55,6 +55,11 @@ public class ClientProxy extends CommonProxy {
         }
     }
 
+    @Override
+    public void setBattleGuiTurnTimerEnabled(boolean enabled) {
+        battleGui.setTurnTimerEnabled(enabled);
+    }
+
     @Override
     public void battleGuiTurnBegin() {
         battleGui.turnBegin();
@@ -942,6 +947,26 @@ public class ClientProxy extends CommonProxy {
                         parent.append(sub);
                     }
 
+                    sub = new TextComponent("battle_turn_wait_forever ");
+                    sub.setStyle(sub.getStyle()
+                        .withColor(ChatFormatting.YELLOW)
+                        .withBold(true)
+                        .withHoverEvent(new HoverEvent(
+                            HoverEvent.Action.SHOW_TEXT,
+                            new TextComponent("Disables the turn timer (recommended to leave this to false)"))
+                        ));
+                    parent.append(sub);
+
+                    sub = new TextComponent("true ");
+                    sub.setStyle(sub.getStyle().withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
+                        "/tbm-server-edit battle_turn_wait_forever true")));
+                    parent.append(sub);
+
+                    sub = new TextComponent("false ");
+                    sub.setStyle(sub.getStyle().withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
+                        "/tbm-server-edit battle_turn_wait_forever false")));
+                    parent.append(sub);
+
                     sub = new TextComponent("battle_turn_time_seconds ");
                     sub.setStyle(sub.getStyle()
                         .withColor(ChatFormatting.YELLOW)
index 4d8c8079987612859743e79a760111720e8867bf..6a8882ca10e0e9a4e4868490a444fb5b4b4877c6 100644 (file)
@@ -34,6 +34,8 @@ public class Battle {
     private long lastInstant;
     private long timer;
 
+    private boolean timerForever;
+
     private boolean isServer;
     private boolean battleEnded;
 
@@ -208,6 +210,7 @@ public class Battle {
         state = State.DECISION;
         undecidedCount.set(playerCount.get());
         timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
+        timerForever = TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever();
         battleEnded = false;
 
         notifyPlayersBattleInfo();
@@ -424,7 +427,11 @@ public class Battle {
     }
 
     public long getTimerSeconds() {
-        return timer / 1000000000;
+        return timer / 1000000000L;
+    }
+
+    public long getTimerNanos() {
+        return timer;
     }
 
     public int getSize() {
@@ -438,7 +445,7 @@ public class Battle {
         if (!isServer) {
             return;
         }
-        PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer);
+        PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
         for (Combatant p : players.values()) {
             TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) p.entity), infoPacket);
         }
@@ -667,7 +674,7 @@ public class Battle {
         switch (state) {
             case DECISION:
                 timer -= dt;
-                if (timer <= 0 || undecidedCount.get() <= 0) {
+                if ((!timerForever && timer <= 0) || undecidedCount.get() <= 0) {
                     for (Combatant c : sideA.values()) {
                         // picking decision for sideA non-players
                         if (!(c.entity instanceof Player) && c.decision == Decision.UNDECIDED && c.entityInfo != null) {
@@ -711,6 +718,7 @@ public class Battle {
                     }
                     state = State.ACTION;
                     timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
+                    timerForever = TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever();
                     sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_BEGIN, 0, 0, 0);
                     turnOrderQueue.clear();
                     for (Combatant c : sideA.values()) {
index c4b19c638a0745971a4ce6e55d8ac205b2e4bd49..0d02f9faa9165c614f4821975a9c2308a3bd70d4 100644 (file)
@@ -61,6 +61,8 @@ public class CommonProxy
     public void setBattleGuiBattleChanged() {}
     
     public void setBattleGuiAsGui() {}
+
+    public void setBattleGuiTurnTimerEnabled(boolean enabled) {}
     
     public void battleGuiTurnBegin() {}
     
index 5169436ab5cd864ed8d4dab7f73c033a6989c49c..7e530461d8dc990bfbd55839e00a99c766b666c5 100644 (file)
@@ -20,6 +20,7 @@ public class Config
     public static final long BATTLE_DECISION_DURATION_NANO_MAX = BATTLE_DECISION_DURATION_SEC_MAX * 1000000000L;
     public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = BATTLE_DECISION_DURATION_SEC_DEFAULT * 1000000000L;
     private long battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT;
+    private boolean battleDecisionDurationForever = false;
     private Map<String, EntityInfo> entityInfoMap;
     private Map<String, EntityInfo> customEntityInfoMap;
     private Set<String> ignoreBattleTypes;
@@ -494,6 +495,19 @@ public class Config
             logTOMLInvalidValue("server_config.battle_turn_time_seconds", "15");
         }
 
+        try {
+            Boolean battle_turn_wait_forever = conf.get("server_config.battle_turn_wait_forever");
+            if (battle_turn_wait_forever != null) {
+                this.battleDecisionDurationForever = battle_turn_wait_forever;
+            } else {
+                this.battleDecisionDurationForever = false;
+                logNotFound("server_config.battle_turn_wait_forever", "false");
+            }
+        } catch (ClassCastException e) {
+            this.battleDecisionDurationForever = false;
+            logTOMLInvalidValue("server_config.battle_turn_wait_forever", "false");
+        }
+
         Collection<com.electronwill.nightconfig.core.Config> entities = null;
         try {
             entities = conf.get("server_config.entity");
@@ -1430,4 +1444,12 @@ public class Config
     public void setCreeperAlwaysAllowDamage(boolean allow_damage) {
         creeperAlwaysAllowDamage = allow_damage;
     }
+
+    public boolean isBattleDecisionDurationForever() {
+        return battleDecisionDurationForever;
+    }
+
+    public void setBattleDecisionDurationForever(boolean battleDecisionDurationForever) {
+        this.battleDecisionDurationForever = battleDecisionDurationForever;
+    }
 }
index 9c913816a2644f46ca94533f8f6595a39803d898..3fb55013cc56358f5d6c3de2a059195dcb35289b 100644 (file)
@@ -38,7 +38,7 @@ import org.apache.logging.log4j.Logger;
 public class TurnBasedMinecraftMod {
     public static final String MODID = "com_burnedkirby_turnbasedminecraft";
     public static final String NAME = "Turn Based Minecraft Mod";
-    public static final String VERSION = "1.18.5";
+    public static final String VERSION = "1.18.6";
     public static final String CONFIG_FILENAME = "TBM_Config.toml";
     public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
     public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
@@ -1337,6 +1337,32 @@ public class TurnBasedMinecraftMod {
                         }
                         return 1;
                     })))
+                .then(Commands.literal("battle_turn_wait_forever").executes(c -> {
+                        TextComponent parent = new TextComponent("Use ");
+                        TextComponent sub = new TextComponent("/tbm-server-edit battle_turn_wait_forever <true/false>");
+                        sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
+                        parent.append(sub);
+
+                        c.getSource().sendSuccess(parent, false);
+                        return 1;
+                    })
+                    .then(Commands.argument("enabled", BoolArgumentType.bool()).executes(c -> {
+                        boolean enabled = BoolArgumentType.getBool(c, "enabled");
+                        TurnBasedMinecraftMod.proxy.getConfig().setBattleDecisionDurationForever(enabled);
+                        if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig("server_config.battle_turn_wait_forever", enabled)) {
+                            TurnBasedMinecraftMod.logger.warn(
+                                "Failed to set \"server_config.battle_turn_wait_forever\" in config file!"
+                            );
+                            c.getSource().sendFailure(new TextComponent("Failed to set battle_turn_wait_forever to \"" + (enabled ? "true" : "false") + "\" in config file!"));
+                        } else {
+                            TextComponent response = new TextComponent("Successfully set battle_turn_wait_forever to: ");
+                            TextComponent subResponse = new TextComponent((enabled ? "true" : "false"));
+                            subResponse.setStyle(subResponse.getStyle().withColor(ChatFormatting.GREEN));
+                            response.append(subResponse);
+                            c.getSource().sendSuccess(response, true);
+                        }
+                        return 1;
+                    })))
                 .then(Commands.literal("battle_turn_time_seconds").executes(c -> {
                         TextComponent parent = new TextComponent("Use ");
                         TextComponent sub = new TextComponent("/tbm-server-edit battle_turn_time_seconds <5-60>");
index 698dc995f67e8597d9765777fa13a54058ee0475..2d1ca6d0940fbf77962a4fa2576330640792a2fc 100644 (file)
@@ -16,19 +16,22 @@ public class PacketBattleInfo
     private Collection<Integer> sideA;
     private Collection<Integer> sideB;
     private long decisionNanos;
+    private boolean turnTimerEnabled;
     
     public PacketBattleInfo()
     {
         sideA = new ArrayList<Integer>();
         sideB = new ArrayList<Integer>();
         decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
+        turnTimerEnabled = false;
     }
 
-    public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos)
+    public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, boolean turnTimerEnabled)
     {
         this.sideA = sideA;
         this.sideB = sideB;
         this.decisionNanos = decisionNanos;
+        this.turnTimerEnabled = turnTimerEnabled;
     }
 
     public static void encode(PacketBattleInfo msg, FriendlyByteBuf buf) {
@@ -41,6 +44,7 @@ public class PacketBattleInfo
                buf.writeInt(id);
        }
        buf.writeLong(msg.decisionNanos);
+        buf.writeBoolean(msg.turnTimerEnabled);
     }
 
     public static PacketBattleInfo decode(FriendlyByteBuf buf) {
@@ -55,7 +59,8 @@ public class PacketBattleInfo
                sideB.add(buf.readInt());
        }
        long decisionNanos = buf.readLong();
-       return new PacketBattleInfo(sideA, sideB, decisionNanos);
+        boolean turnTimerEnabled = buf.readBoolean();
+       return new PacketBattleInfo(sideA, sideB, decisionNanos, turnTimerEnabled);
     }
     
     public static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
@@ -83,6 +88,7 @@ public class PacketBattleInfo
             }
             TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
             TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
+            TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
         });
         ctx.get().setPacketHandled(true);
     }
index b78896bf422035650707716bfa4d80909e4157fe..b678983540a41aaaff117ee12a7ebb7993bddb34 100644 (file)
@@ -34,7 +34,7 @@ public class PacketBattleRequestInfo
             if(b == null) {
                 return;
             }
-            TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds()), ctx.get());
+            TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get());
         });
         ctx.get().setPacketHandled(true);
     }
index 5157a9fd068fcd76dc30f9e6dc5085bda5bfec6a..b2f3cee1e9a24b0b698660d5af52076cbf07811e 100644 (file)
@@ -15,7 +15,7 @@ license="MIT"
 # The modid of the mod
 modId="com_burnedkirby_turnbasedminecraft" #mandatory
 # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
-version="1.18.5" #mandatory
+version="1.18.6" #mandatory
  # A display name for the mod
 displayName="TurnBasedMinecraftMod" #mandatory
 # A URL to query for updates for this mod. See the JSON update specification <here>
index b5823aa4594d94b23820046127d5ec781d7568bf..da39a8b0c46392723e6a42abb3713090337310e0 100644 (file)
@@ -36,29 +36,29 @@ anyone_can_disable_tbm_for_self = false
 # will be added to battle until there are less than max entities.
 max_in_battle = 8
 
-# If true, all entities in battle will be frozen in place
+# If true, all entities in battle will be frozen in place.
 freeze_battle_combatants = false
 
 # Entity categories that will not initiate battle.
 ignore_battle_types = ["passive", "boss"]
 
-# speed stat of all players in battle
+# Speed stat of all players in battle.
 player_speed = 50
-# speed stat of all players under the effects of haste
+# Speed stat of all players under the effects of haste.
 player_haste_speed = 80
-# speed stat of all players under the effects of slow
+# Speed stat of all players under the effects of slow.
 player_slow_speed = 20
-# attack probability stat for all players
+# Attack probability stat for all players.
 player_attack_probability = 90
-# evasion stat for all players
+# Evasion stat for all players.
 player_evasion = 10
 
-# Number of attacks that a "defend" move will block
+# Number of attacks that a "defend" move will block.
 defense_duration = 1
 
-# probability of fleeing from battle when speed is greater than fastest enemy's speed
+# Probability of fleeing from battle when speed is greater than fastest enemy's speed.
 flee_good_probability = 90
-# probability of fleeing from battle when speed is less than fastest enemy's speed
+# Probability of fleeing from battle when speed is less than fastest enemy's speed.
 flee_bad_probability = 40
 
 # Minimum hit percentage for everyone. If option is set to less than 1,
@@ -69,13 +69,17 @@ minimum_hit_percentage = 4
 # Minimum 5, maximum 60.
 battle_turn_time_seconds = 15
 
-# On what turn a Creeper will explode in battle
+# If set to true, battle_turn_time_seconds will be ignored and there will be no turn timer.
+# WARNING: If this is set to true, a player can halt a battle forever by never deciding on their turn.
+battle_turn_wait_forever = false
+
+# On what turn a Creeper will explode in battle.
 creeper_explode_turn = 5
 
-# Keep creepers from exploding when they leave a battle (for leave_battle_cooldown duration)
+# Keep creepers from exploding when they leave a battle (for leave_battle_cooldown duration).
 creeper_stop_explode_on_leave_battle = true
 
-# If false, creepers may not damage others outside of turn-based battle
+# If false, creepers may not damage others outside of turn-based battle.
 creeper_always_allow_damage = true
 
 
index ddbd50f757600128fecf048483963f31db9d451f..c877896914907993873ef8a82461a5ee951d4d09 100644 (file)
@@ -3,7 +3,7 @@
   "modid": "com_burnedkirby_turnbasedminecraft",
   "name": "Turn Based Minecraft",
   "description": "Changes battles to be turn-based.",
-  "version": "1.18.5",
+  "version": "1.18.6",
   "mcversion": "1.18.2",
   "url": "",
   "updateUrl": "",