From befc7cf6114de39f9308f4cc67e8a388ab0cb4a6 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 18 Nov 2020 16:16:18 +0900 Subject: [PATCH] Add config option for creeper turn explosion --- Changelog.md | 5 +++++ build.gradle | 2 +- .../TurnBasedMinecraft/common/Battle.java | 10 +++++----- .../TurnBasedMinecraft/common/Combatant.java | 4 ++-- .../TurnBasedMinecraft/common/Config.java | 20 +++++++++++++++++++ .../common/TurnBasedMinecraftMod.java | 2 +- src/main/resources/META-INF/mods.toml | 2 +- .../TBM_Config.toml | 5 ++++- src/main/resources/mcmod.info | 2 +- 9 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Changelog.md b/Changelog.md index f9a7265..57ecaf7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,10 @@ # Upcoming changes +# Version 1.15 + +Add server-side config option that determines on what turn a Creeper will +explode in battle. + # Version 1.14 Implemented support for Creepers in battle. diff --git a/build.gradle b/build.gradle index 353be68..7ce28a7 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ apply plugin: 'eclipse' //apply plugin: 'maven-publish' apply plugin: 'com.github.johnrengelman.shadow' -version = "1.14" +version = "1.15" group = "com.burnedkirby.TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft" diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java index 28c09b1..17eaf00 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java @@ -830,7 +830,7 @@ public class Battle if(!(c.entity instanceof PlayerEntity) && c.decision == Decision.UNDECIDED && c.entityInfo != null) { if(c.entity instanceof CreeperEntity) { - if(c.creeperTurns++ < 2) { + if(c.creeperTurns++ < TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) { c.decision = Decision.CREEPER_WAIT; } else { c.decision = Decision.CREEPER_EXPLODE; @@ -857,7 +857,7 @@ public class Battle if(!(c.entity instanceof PlayerEntity) && c.decision == Decision.UNDECIDED && c.entityInfo != null) { if(c.entity instanceof CreeperEntity) { - if(c.creeperTurns++ < 2) { + if(c.creeperTurns++ < TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) { c.decision = Decision.CREEPER_WAIT; } else { c.decision = Decision.CREEPER_EXPLODE; @@ -1348,7 +1348,7 @@ public class Battle break; case CREEPER_WAIT: debugLog += " creeper wait"; - if(next.creeperTurns < 2) { + if(next.creeperTurns < TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) { sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_WAIT, next.entity.getEntityId(), 0, 0); } else { sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_WAIT_FINAL, next.entity.getEntityId(), 0, 0); @@ -1493,7 +1493,7 @@ public class Battle private void defuseCreepers() { for(Combatant c : sideA.values()) { if(c.entity instanceof CreeperEntity) { - if(c.creeperTurns <= 2) { + if(c.creeperTurns <= TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) { ((CreeperEntity)c.entity).setCreeperState(-10); } else { ((CreeperEntity)c.entity).setCreeperState(1000000); @@ -1502,7 +1502,7 @@ public class Battle } for(Combatant c : sideB.values()) { if(c.entity instanceof CreeperEntity) { - if(c.creeperTurns <= 2) { + if(c.creeperTurns <= TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) { ((CreeperEntity)c.entity).setCreeperState(-10); } else { ((CreeperEntity) c.entity).setCreeperState(1000000); diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java index 037fb0c..f7ed61d 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java @@ -32,7 +32,7 @@ public class Combatant decision = Battle.Decision.UNDECIDED; recalcSpeedOnCompare = false; remainingDefenses = 0; - creeperTurns = 0; + creeperTurns = 1; } public Combatant(Entity e, EntityInfo entityInfo) @@ -42,7 +42,7 @@ public class Combatant this.entityInfo = entityInfo; recalcSpeedOnCompare = false; remainingDefenses = 0; - creeperTurns = 0; + creeperTurns = 1; } /** diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java index 6174521..251be08 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java @@ -45,6 +45,7 @@ public class Config private boolean oldBattleBehaviorEnabled = false; private int leaveBattleCooldownSeconds = 5; private int aggroStartBattleDistance = 8; + private int creeperExplodeTurn = 5; public Config(Logger logger) { @@ -236,6 +237,23 @@ public class Config logTOMLInvalidValue("server_config.aggro_start_battle_max_distance", "8"); } + try { + OptionalInt creeper_explode_turn = conf.getOptionalInt("server_config.creeper_explode_turn"); + if(creeper_explode_turn.isPresent()) { + this.creeperExplodeTurn = creeper_explode_turn.getAsInt(); + if(this.creeperExplodeTurn < 1) { + logClampedValue("server_config.creeper_explode_turn", Integer.toString(this.creeperExplodeTurn), "1"); + this.creeperExplodeTurn = 1; + } + } else { + this.creeperExplodeTurn = 5; + logNotFound("server_config.creeper_explode_turn", "5"); + } + } catch(ClassCastException e) { + this.creeperExplodeTurn = 5; + logTOMLInvalidValue("server_config.creeper_explode_turn", "5"); + } + try { Boolean old_battle_behavior = conf.get("server_config.old_battle_behavior"); if(old_battle_behavior != null) { @@ -1137,4 +1155,6 @@ public class Config { return aggroStartBattleDistance; } + + public int getCreeperExplodeTurn() { return creeperExplodeTurn; } } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java index 2f8244d..9a8fc72 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java @@ -35,7 +35,7 @@ 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.14"; + public static final String VERSION = "1.15"; 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/"; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 4ed5397..cf7b291 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.14" #mandatory +version="1.15" #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 919b01c..a55d44f 100644 --- a/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml +++ b/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml @@ -1,6 +1,6 @@ # Please do not change this option, the mod uses this to keep track of what new # changes to add to the config. -version = 4 +version = 5 do_not_overwrite = false [client_config] @@ -69,6 +69,9 @@ minimum_hit_percentage = 4 # Minimum 5, maximum 60. battle_turn_time_seconds = 15 +# On what turn a Creeper will explode in battle +creeper_explode_turn = 5 + # Each "server_config.entity" entry uses the following options: # name: full class name of the entity, cannot also have option "custom_name" diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 45497a9..20cc2a1 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.14", + "version": "1.15", "mcversion": "1.16.3", "url": "", "updateUrl": "", -- 2.49.0