]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Impl. player_only_battles, v1.21.3 1.21.3
authorStephen Seo <seo.disparate@gmail.com>
Wed, 24 Aug 2022 03:16:36 +0000 (12:16 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 24 Aug 2022 03:18:32 +0000 (12:18 +0900)
A server-side config option was added to enable "player_only_battles" where mobs
cannot enter battle. (I haven't actually tested this fully since I am only 1
person, so there may be bugs.) This can be edited via the config, or via the
`/tbm-server-edit` command.

Version bumped to 1.21.3 .

Changelog.md
build.gradle
src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java
src/main/resources/META-INF/mods.toml
src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml
src/main/resources/mcmod.info

index 6a838d9d4bb63540cd26ab01a9ab8a1b43436b32..ef90a8cad6e61d67439a11dcc5b85e2f5bebf7ef 100644 (file)
@@ -1,5 +1,11 @@
 # Upcoming changes
 
+# Version 1.21.3
+
+Implemented "player-only" battles, which can be enabled in the server-side
+config or set using `/tbm-server-edit`. (Somewhat untested because I am only 1
+person.)
+
 # Version 1.21.2
 
 Refactored checking-if-in-battle code from `O(n)` to `O(1)` complexity.
index 15c0aeb571a397bd13d28cd6dc7ef39f93d1dbf8..00d5ea0e58f72a5696e9fff59198478fa8fd4778 100644 (file)
@@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle'
 //apply plugin: 'eclipse'
 //apply plugin: 'maven-publish'
 
-version = "1.21.2"
+version = "1.21.3"
 group = "com.burnedkirby.TurnBasedMinecraft"
 archivesBaseName = "TurnBasedMinecraft"
 
index a5763f684212211631c6d31caf418fda82df7f90..34ff24bde85ec5b17dc9b38881ac44969f60520d 100644 (file)
@@ -1062,6 +1062,34 @@ public class ClientProxy extends CommonProxy {
                         .withBold(true));
                     parent.getSiblings().add(sub);
 
+                    sub = Component.literal("player_only_battles ");
+                    sub.setStyle(sub.getStyle()
+                        .withColor(ChatFormatting.YELLOW)
+                        .withBold(true)
+                        .withHoverEvent(new HoverEvent(
+                            HoverEvent.Action.SHOW_TEXT,
+                            Component.literal("Disables battle for non-player entities")
+                        )));
+                    parent.getSiblings().add(sub);
+
+                    sub = Component.literal("enable ");
+                    sub.setStyle(sub.getStyle()
+                        .withColor(ChatFormatting.GREEN)
+                        .withClickEvent(new ClickEvent(
+                            ClickEvent.Action.RUN_COMMAND,
+                            "/tbm-server-edit player_only_battles true"
+                        )));
+                    parent.getSiblings().add(sub);
+
+                    sub = Component.literal("disable ");
+                    sub.setStyle(sub.getStyle()
+                        .withColor(ChatFormatting.GREEN)
+                        .withClickEvent(new ClickEvent(
+                            ClickEvent.Action.RUN_COMMAND,
+                            "/tbm-server-edit player_only_battles false"
+                        )));
+                    parent.getSiblings().add(sub);
+
                     TurnBasedMinecraftMod.proxy.displayComponent(parent);
                     break;
                 }
index a9cac7f1cf78b1b808d8a109097bde149f4ed34e..28978def9b8198900060007b1123283f244c8760 100644 (file)
@@ -66,11 +66,14 @@ public class BattleManager
             attackerCustomName = null;
         }
 
-        // verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo
+        // Verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo.
+        // Also check if "player_only_battles" is enabled and both entities are players.
         if(!((event.getEntity() instanceof Player && !((Player)event.getEntity()).isCreative())
                 || (config.getEntityInfoReference(receiverClassName) != null || config.getCustomEntityInfoReference(receiverCustomName) != null))
             || !((event.getSource().getEntity() instanceof Player && !((Player)event.getSource().getEntity()).isCreative())
-                || (config.getEntityInfoReference(attackerClassName) != null || config.getCustomEntityInfoReference(attackerCustomName) != null)))
+                || (config.getEntityInfoReference(attackerClassName) != null || config.getCustomEntityInfoReference(attackerCustomName) != null))
+            || (TurnBasedMinecraftMod.proxy.getConfig().isPlayerOnlyBattlesEnabled() &&
+                (!(event.getEntity() instanceof Player) || !(event.getSource().getEntity() instanceof Player))))
         {
 //            logger.debug("BattleManager: Failed first check, attacker is \"" + attackerClassName + "\", defender is \"" + receiverClassName + "\"");
             return false;
@@ -176,6 +179,12 @@ public class BattleManager
     
     public void checkTargeted(LivingSetAttackTargetEvent event)
     {
+        // Check if "player_only_battles" is enabled and if both entities are players.
+        if (TurnBasedMinecraftMod.proxy.getConfig().isPlayerOnlyBattlesEnabled() &&
+            (!(event.getEntity() instanceof Player) || !(event.getTarget() instanceof Player))) {
+            return;
+        }
+
         String targetedCustomName;
         try {
             targetedCustomName = event.getTarget().getCustomName().getString();
index 496f273c9aa3273a0a736653f4ad47e477acb6b2..5a12f2e36c71869067cf2fd81fbc7fa1ece48eb9 100644 (file)
@@ -53,6 +53,8 @@ public class Config
     private Set<String> possibleIgnoreHurtDamageSources;
     private Set<String> ignoreHurtDamageSources;
 
+    private boolean playerOnlyBattles = false;
+
     public Config(Logger logger)
     {
         entityInfoMap = new HashMap<String, EntityInfo>();
@@ -548,6 +550,19 @@ public class Config
             logTOMLInvalidValue("server_config.ignore_damage_sources");
         }
 
+        try {
+            Boolean is_only_player_battles_enabled = conf.get("server_config.player_only_battles");
+            if (is_only_player_battles_enabled != null) {
+                playerOnlyBattles = is_only_player_battles_enabled;
+            } else {
+                playerOnlyBattles = false;
+                logNotFound("server_config.player_only_battles", "false");
+            }
+        } catch (ClassCastException e) {
+            playerOnlyBattles = false;
+            logTOMLInvalidValue("server_config.player_only_battles", "false");
+        }
+
         Collection<com.electronwill.nightconfig.core.Config> entities = null;
         try {
             entities = conf.get("server_config.entity");
@@ -1513,4 +1528,12 @@ public class Config
     public boolean removeIgnoreHurtDamageSource(String source) {
         return ignoreHurtDamageSources.remove(source);
     }
+
+    public boolean isPlayerOnlyBattlesEnabled() {
+        return playerOnlyBattles;
+    }
+
+    public void setIsPlayerOnlyBattles(boolean enabled) {
+        playerOnlyBattles = enabled;
+    }
 }
\ No newline at end of file
index 305a0cc24943f32af09012d9a59e9888601188d1..115125f762b979e43b08b7f53bc96b8f1852f466 100644 (file)
@@ -39,7 +39,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.21.2";
+    public static final String VERSION = "1.21.3";
     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/";
@@ -1589,6 +1589,30 @@ public class TurnBasedMinecraftMod {
                             c.getSource().sendFailure(Component.literal("Failed to remove type \"" + type + "\" from ignore_damage_sources"));
                             return 1;
                         }))))
+                .then(Commands.literal("player_only_battles").executes(c -> {
+                        MutableComponent parent = Component.literal("Use ");
+                        MutableComponent sub = Component.literal("/tbm-server-edit player_only_battles <true/false>");
+                        sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
+                        parent.getSiblings().add(sub);
+
+                        c.getSource().sendSuccess(parent, false);
+                        return 1;
+                    })
+                    .then(Commands.argument("player_only_battles", BoolArgumentType.bool()).executes(c -> {
+                        boolean player_only_battles = BoolArgumentType.getBool(c, "player_only_battles");
+                        TurnBasedMinecraftMod.proxy.getConfig().setIsPlayerOnlyBattles(player_only_battles);
+                        if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig("server_config.player_only_battles", player_only_battles)) {
+                            TurnBasedMinecraftMod.logger.warn("Failed to set \"server_config.player_only_battles\" in config file!");
+                            c.getSource().sendFailure(Component.literal("Failed to set player_only_battles to \"" + player_only_battles + "\" in config file"));
+                        } else {
+                            MutableComponent response = Component.literal("Successfully set player_only_battles to: ");
+                            MutableComponent sub = Component.literal(String.valueOf(player_only_battles));
+                            sub.setStyle(sub.getStyle().withColor(ChatFormatting.GREEN));
+                            response.getSiblings().add(sub);
+                            c.getSource().sendSuccess(response, true);
+                        }
+                        return 1;
+                    })))
         );
     }
 
index 3780f3e4f19a252b5b7a4d7769f13f48affe7cd4..847c7384ad9fc5185e53caaa730e04d38913e20b 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.21.2" #mandatory
+version="1.21.3" #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 9dc672084575e5aa2fe63d06ecfce98c235f51f6..52314019471900081c7bc2e6e92ea2ea34da8028 100644 (file)
@@ -100,6 +100,9 @@ ignore_damage_sources = [
     "sweetBerryBush"
 ]
 
+# If this is set to true, only players can enter battle.
+player_only_battles = false
+
 
 # Each "server_config.entity" entry uses the following options:
 # name: full class name of the entity, cannot also have option "custom_name"
index 5b9cfd0f76fe6dc206557eb95a08b4d429dec340..906078962479e34b47c1c1dbac0ae72502ed8520 100644 (file)
@@ -3,7 +3,7 @@
   "modid": "com_burnedkirby_turnbasedminecraft",
   "name": "Turn Based Minecraft",
   "description": "Changes battles to be turn-based.",
-  "version": "1.21.2",
+  "version": "1.21.3",
   "mcversion": "1.18.2",
   "url": "",
   "updateUrl": "",