diff --git a/README.md b/README.md index 9b116d3..f2eefd9 100644 --- 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 diff --git a/build.gradle b/build.gradle index 959074f..599d054 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java index 66fe08e..a5f4bb1 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleGui.java @@ -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; + } } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java index efb8060..e57b67f 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java @@ -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) diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java index 4d8c807..6a8882c 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java @@ -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()) { diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java index c4b19c6..0d02f9f 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java @@ -61,6 +61,8 @@ public class CommonProxy public void setBattleGuiBattleChanged() {} public void setBattleGuiAsGui() {} + + public void setBattleGuiTurnTimerEnabled(boolean enabled) {} public void battleGuiTurnBegin() {} diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java index 5169436..7e53046 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java @@ -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 entityInfoMap; private Map customEntityInfoMap; private Set 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 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; + } } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java index 9c91381..3fb5501 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java @@ -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 "); + 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>"); 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 698dc99..2d1ca6d 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleInfo.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleInfo.java @@ -16,19 +16,22 @@ public class PacketBattleInfo private Collection sideA; private Collection sideB; private long decisionNanos; + private boolean turnTimerEnabled; public PacketBattleInfo() { sideA = new ArrayList(); sideB = new ArrayList(); decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(); + turnTimerEnabled = false; } - public PacketBattleInfo(Collection sideA, Collection sideB, long decisionNanos) + public PacketBattleInfo(Collection sideA, Collection 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 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); } 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 b78896b..b678983 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.getTimerSeconds()), ctx.get()); + TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get()); }); ctx.get().setPacketHandled(true); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 5157a9f..b2f3cee 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -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 diff --git a/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml b/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml index b5823aa..da39a8b 100644 --- a/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml +++ b/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml @@ -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 diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index ddbd50f..c877896 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -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": "",