From c67deef3933adf4681692b57dd99d93c5c7afc2d Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 18 Nov 2020 17:24:18 +0900 Subject: [PATCH] Impl config and settings for creeper behavior --- Changelog.md | 10 ++++++ build.gradle | 2 +- .../common/AttackEventHandler.java | 7 +++- .../common/BattleManager.java | 4 +++ .../TurnBasedMinecraft/common/Config.java | 32 +++++++++++++++++++ .../common/TurnBasedMinecraftMod.java | 2 +- src/main/resources/META-INF/mods.toml | 2 +- .../TBM_Config.toml | 8 ++++- src/main/resources/mcmod.info | 2 +- 9 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 57ecaf7..1d5b80d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,15 @@ # Upcoming changes +# Version 1.16 + +Add config options regarding creeper behavior. + +By default, creepers will not explode if they leave battle (maybe due to a +player fleeing), until the cooldown time ends. + +By default, creepers that explode will damage anyone, even if they weren't in +turn-based battle. + # Version 1.15 Add server-side config option that determines on what turn a Creeper will diff --git a/build.gradle b/build.gradle index 7ce28a7..5d633d1 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.15" +version = "1.16" group = "com.burnedkirby.TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft" diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java index 2f43706..025fb55 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java @@ -6,6 +6,7 @@ import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage; import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketEditingMessage; import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage; +import net.minecraft.entity.monster.CreeperEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; @@ -115,8 +116,12 @@ public class AttackEventHandler } if(event.getEntity() != null && event.getSource().getTrueSource() != null && (battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId()) || battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId()))) { + if(event.getSource().getTrueSource().getEntity() instanceof CreeperEntity && TurnBasedMinecraftMod.proxy.getConfig().getCreeperAlwaysAllowDamage()) { + event.setCanceled(false); + } else { // TurnBasedMinecraftMod.logger.debug("Canceled attack"); - event.setCanceled(true); + event.setCanceled(true); + } return; } else if(!isAttackerValid(event) diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java index 1c29562..23fc442 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import net.minecraft.entity.monster.CreeperEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.util.RegistryKey; @@ -323,6 +324,9 @@ public class BattleManager for(Iterator> iter = recentlyLeftBattle.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = iter.next(); + if(entry.getValue().entity instanceof CreeperEntity && TurnBasedMinecraftMod.proxy.getConfig().getCreeperStopExplodeOnLeaveBattle()) { + ((CreeperEntity)entry.getValue().entity).setCreeperState(-10); + } if(current - entry.getValue().time > TurnBasedMinecraftMod.proxy.getConfig().getLeaveBattleCooldownNanos()) { iter.remove(); diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java index 251be08..7baa93d 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java @@ -46,6 +46,8 @@ public class Config private int leaveBattleCooldownSeconds = 5; private int aggroStartBattleDistance = 8; private int creeperExplodeTurn = 5; + private boolean creeperStopExplodeOnLeaveBattle = true; + private boolean creeperAlwaysAllowDamage = true; public Config(Logger logger) { @@ -254,6 +256,32 @@ public class Config logTOMLInvalidValue("server_config.creeper_explode_turn", "5"); } + try { + Boolean creeper_stop_explode_on_leave_battle = conf.get("server_config.creeper_stop_explode_on_leave_battle"); + if(creeper_stop_explode_on_leave_battle != null) { + this.creeperStopExplodeOnLeaveBattle = creeper_stop_explode_on_leave_battle; + } else { + this.creeperStopExplodeOnLeaveBattle = true; + logNotFound("server_config.creeper_stop_explode_on_leave_battle", "true"); + } + } catch (ClassCastException e) { + this.creeperStopExplodeOnLeaveBattle = true; + logTOMLInvalidValue("server_config.creeper_stop_explode_on_leave_battle", "true"); + } + + try { + Boolean creeper_always_allow_damage = conf.get("server_config.creeper_always_allow_damage"); + if(creeper_always_allow_damage != null) { + this.creeperAlwaysAllowDamage = creeper_always_allow_damage; + } else { + this.creeperAlwaysAllowDamage = true; + logNotFound("server_config.creeper_always_allow_damage", "true"); + } + } catch (ClassCastException e) { + this.creeperAlwaysAllowDamage = true; + logTOMLInvalidValue("server_config.creeper_always_allow_damage", "true"); + } + try { Boolean old_battle_behavior = conf.get("server_config.old_battle_behavior"); if(old_battle_behavior != null) { @@ -1157,4 +1185,8 @@ public class Config } public int getCreeperExplodeTurn() { return creeperExplodeTurn; } + + public boolean getCreeperStopExplodeOnLeaveBattle() { return creeperStopExplodeOnLeaveBattle; } + + public boolean getCreeperAlwaysAllowDamage() { return creeperAlwaysAllowDamage; } } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java index 9a8fc72..60201e2 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.15"; + public static final String VERSION = "1.16"; 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 cf7b291..e44196d 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.15" #mandatory +version="1.16" #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 a55d44f..686f3a8 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 = 5 +version = 6 do_not_overwrite = false [client_config] @@ -72,6 +72,12 @@ battle_turn_time_seconds = 15 # 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) +creeper_stop_explode_on_leave_battle = true + +# If false, creepers may not damage others outside of turn-based battle +creeper_always_allow_damage = true + # 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 20cc2a1..02a1d5d 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.15", + "version": "1.16", "mcversion": "1.16.3", "url": "", "updateUrl": "",