]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Version 1.7
authorStephen Seo <seo.disparate@gmail.com>
Fri, 26 Oct 2018 04:35:20 +0000 (13:35 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 26 Oct 2018 04:36:35 +0000 (13:36 +0900)
Can now add/edit "custom-name" entries to the config via
"/tbm-edit custom". These entries only apply to mobs with a matching
custom name.

12 files changed:
Changelog.md
build.gradle
src/main/java/com/seodisparate/TurnBasedMinecraft/common/AttackEventHandler.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommandTBMEdit.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/EditingInfo.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketEditingMessage.java
src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml

index ac1ec89e3cc0d5b4155ea757ae155ccfd3b08b76..22a239c5c6270017e22d931ffe8963ef64ce42cf 100644 (file)
@@ -1,3 +1,15 @@
+# Version 1.7
+
+Fix bug where after using "/tbm-edit", ignore_battle option is saved in
+config with the wrong name.
+
+Add "/tbm-edit custom", which lets an OP add an entity entry for entities with
+custom names (via name-tags). The entry added into the config file will use
+"custom_name" instead of "name" to specify if it is a regular entity entry
+or an entry for a specific custom name.
+
+Minor fixes and improvements.
+
 # Version 1.6
 
 Fix bug where player can start battle with self.
index 80ecc87b825e6d9eedd6f7688af0efb70b04b58c..9adf6306df8aa57f95b990c680ca4bfecda47e2e 100644 (file)
@@ -11,7 +11,7 @@ buildscript {
 apply plugin: 'net.minecraftforge.gradle.forge'\r
 apply plugin: 'com.github.johnrengelman.shadow'\r
 \r
-version = "1.6"\r
+version = "1.7"\r
 group = "com.seodisparate.TurnBasedMinecraft"\r
 archivesBaseName = "TurnBasedMinecraft"\r
 \r
index f5fc63af63fea75be9c349dfdf83f6a3cae840cb..ae02a2711d5fe5a4807c672253f69122af3a359c 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Iterator;
 import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
 
 import com.seodisparate.TurnBasedMinecraft.common.networking.PacketEditingMessage;
+import com.seodisparate.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
 import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraftforge.event.entity.living.LivingAttackEvent;
 import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
@@ -74,21 +75,41 @@ public class AttackEventHandler
                 {
                     editingInfo.isPendingEntitySelection = false;
                     event.setCanceled(true);
-                    editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity());
-                    if(editingInfo.entityInfo == null)
+                    if(editingInfo.isEditingCustomName)
                     {
-                        editingInfo.entityInfo = new EntityInfo();
-                        editingInfo.entityInfo.classType = event.getEntity().getClass();
-                        TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)editingInfo.editor);
-                        return;
+                        if(event.getEntity().getCustomNameTag().isEmpty())
+                        {
+                            TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name");
+                            TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit custom name from entity without custom name"), (EntityPlayerMP) editingInfo.editor);
+                            return;
+                        }
+                        editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomNameTag());
+                        if(editingInfo.entityInfo == null)
+                        {
+                            editingInfo.entityInfo = new EntityInfo();
+                            editingInfo.entityInfo.customName = event.getEntity().getCustomNameTag();
+                        }
+                        TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomNameTag() + "\""), (EntityPlayerMP) editingInfo.editor);
+                        TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomNameTag() + "\"");
+                        TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor);
+                    }
+                    else
+                    {
+                        editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity()).clone();
+                        if(editingInfo.entityInfo == null)
+                        {
+                            editingInfo.entityInfo = new EntityInfo();
+                            editingInfo.entityInfo.classType = event.getEntity().getClass();
+                        }
+                        TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), (EntityPlayerMP) editingInfo.editor);
+                        TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\"");
+                        TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor);
                     }
-                    TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)editingInfo.editor);
                     return;
                 }
             }
         }
-        if((event.getEntity() != null && battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId()))
-                || (event.getSource().getTrueSource() != null && battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId())))
+        if(event.getEntity() != null && event.getSource().getTrueSource() != null && (battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId()) || battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId())))
         {
             event.setCanceled(true);
             return;
index ba6698042579c254994e9205111b3c1b36f9211e..55276868b71c9b336e22271444770c8457a038e6 100644 (file)
@@ -139,7 +139,12 @@ public class Battle
         {
             for(Entity e : sideA)
             {
-                EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+                EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
+                if(entityInfo == null)
+                {
+                    entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+                }
+
                 if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
                 {
                     continue;
@@ -167,7 +172,12 @@ public class Battle
         {
             for(Entity e : sideB)
             {
-                EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+                EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
+                if(entityInfo == null)
+                {
+                    entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+                }
+
                 if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
                 {
                     continue;
@@ -297,7 +307,12 @@ public class Battle
     
     public void addCombatantToSideA(Entity e)
     {
-        EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+        EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
+        if(entityInfo == null)
+        {
+            entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+        }
+
         if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
         {
             return;
@@ -353,7 +368,12 @@ public class Battle
     
     public void addCombatantToSideB(Entity e)
     {
-        EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+        EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
+        if(entityInfo == null)
+        {
+            entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
+        }
+
         if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
         {
             return;
index e1ce15633fbef0c8bbddad94a404e2cc643893b3..9f1f5af2335e7087dcd247434859765680fa9f50 100644 (file)
@@ -53,7 +53,12 @@ public class BattleManager
         }
         
         // check if ignore battle in config
-        EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity());
+        EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(event.getEntity().getCustomNameTag());
+        if(entityInfo == null)
+        {
+            entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity());
+        }
+
         if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
         {
             // attacked entity ignores battle
index a707e2b7ae42c549835c65a195b3b07877aa3808..6092ca88cc3e4dcc1f3119b753e1b8f3049500e2 100644 (file)
@@ -11,7 +11,7 @@ import net.minecraft.server.MinecraftServer;
 
 public class CommandTBMEdit extends CommandBase
 {
-    public static final String usage = "/tbm-edit (Invoke without parameters to start edit)";
+    public static final String usage = "/tbm-edit [custom] (Invoke without parameters or with arg \"custom\" to start edit)";
     private Config config;
 
     public CommandTBMEdit(Config config)
@@ -68,9 +68,16 @@ public class CommandTBMEdit extends CommandBase
             {
                 if(args[0].toLowerCase().equals("finish"))
                 {
-                    config.editEntityEntry(editingInfo.entityInfo);
-                    TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId());
-                    TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Entity info saved in config and loaded."), (EntityPlayerMP) senderEntity);
+                    if(!config.editEntityEntry(editingInfo.entityInfo))
+                    {
+                        TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("An error occurred while attempting to save an entry to the config, check the logs"), (EntityPlayerMP) senderEntity);
+                        TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId());
+                    }
+                    else
+                    {
+                        TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId());
+                        TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Entity info saved in config and loaded."), (EntityPlayerMP) senderEntity);
+                    }
                 }
                 else if(args[0].toLowerCase().equals("cancel"))
                 {
@@ -88,11 +95,21 @@ public class CommandTBMEdit extends CommandBase
             }
             else if(editingInfo != null)
             {
-                TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP) senderEntity);
+                TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity);
             }
             else
             {
-                TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit entity without starting editing process (use \"/tbm-edit\")."), (EntityPlayerMP)senderEntity);
+                if(args[0].toLowerCase().equals("custom"))
+                {
+                    TurnBasedMinecraftMod.proxy.setEditingPlayer(senderEntity);
+                    TurnBasedMinecraftMod.proxy.getEditingInfo(senderEntity.getEntityId()).isEditingCustomName = true;
+                    TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity);
+                    TurnBasedMinecraftMod.logger.info("Begin editing custom TBM Entity for player \"" + senderEntity.getName() + "\"");
+                }
+                else
+                {
+                    TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit entity without starting editing process (use \"/tbm-edit\")."), (EntityPlayerMP)senderEntity);
+                }
             }
         }
         else if(args.length == 2)
index bb04d96246cedef4de2ce5f3f1e7c2c7ee23ce90..0949e0c682bd30d41795da435bb2dc0e56ca7128 100644 (file)
@@ -20,6 +20,7 @@ public class Config
     public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L;
     private long battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT;
     private Map<String, EntityInfo> entityInfoMap;
+    private Map<String, EntityInfo> customEntityInfoMap;
     private Set<String> ignoreBattleTypes;
     private Logger logger;
     private int playerSpeed = 50;
@@ -47,6 +48,7 @@ public class Config
     public Config(Logger logger)
     {
         entityInfoMap = new HashMap<String, EntityInfo>();
+        customEntityInfoMap = new HashMap<String, EntityInfo>();
         ignoreBattleTypes = new HashSet<String>();
         this.logger = logger;
         musicBattleTypes = new HashSet<String>();
@@ -400,18 +402,32 @@ public class Config
             {
                 TomlTable entity = entityArray.getTable(i);
                 EntityInfo eInfo = new EntityInfo();
-                try
+                String name = null;
+                if(entity.contains("name") && entity.contains("custom_name"))
                 {
-                    eInfo.classType = Class.forName(entity.getString("name"));
+                    logger.error("Entity cannot have both \"name\" and \"custom_name\" entries");
+                    continue;
                 }
-                catch (ClassNotFoundException e)
+                else if(entity.contains("name"))
                 {
-                    logger.error("Entity with class name \"" + entity.getString("name") + "\" not found, skipping...");
-                    continue;
+                    try
+                    {
+                        eInfo.classType = Class.forName(entity.getString("name"));
+                        name = eInfo.classType.getName();
+                    } catch(ClassNotFoundException e)
+                    {
+                        logger.error("Entity with class name \"" + entity.getString("name") + "\" not found, skipping...");
+                        continue;
+                    }
                 }
-                catch (NullPointerException e)
+                else if(entity.contains("custom_name"))
                 {
-                    logger.error("Entity does not have \"name\", skipping...");
+                    eInfo.customName = entity.getString("custom_name");
+                    name = eInfo.customName;
+                }
+                else
+                {
+                    logger.error("Entity must have \"name\" or \"custom_name\" entry");
                     continue;
                 }
 
@@ -421,12 +437,12 @@ public class Config
                     if(eInfo.attackPower < 0)
                     {
                         eInfo.attackPower = 0;
-                        logEntityInvalidValue("attack_power", eInfo.classType.getName(), "0");
+                        logEntityInvalidValue("attack_power", name, "0");
                     }
                 }
                 catch (NullPointerException e)
                 {
-                    logEntityMissingRequiredValue("attack_power", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("attack_power", name);
                     continue;
                 }
 
@@ -436,12 +452,12 @@ public class Config
                     if(eInfo.attackProbability < 0 || eInfo.attackProbability > 100)
                     {
                         eInfo.attackProbability = 35;
-                        logEntityInvalidValue("attack_probability", eInfo.classType.getName(), "35");
+                        logEntityInvalidValue("attack_probability", name, "35");
                     }
                 }
                 catch (NullPointerException e)
                 {
-                    logEntityMissingRequiredValue("attack_probability", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("attack_probability", name);
                     continue;
                 }
 
@@ -454,13 +470,14 @@ public class Config
                         if(eInfo.attackEffectProbability < 0 || eInfo.attackEffectProbability > 100)
                         {
                             eInfo.attackEffectProbability = 35;
-                            logEntityInvalidValue("attack_effect", eInfo.classType.getName(), "35");
+                            logEntityInvalidValue("attack_effect", name, "35");
                         }
                     }
                 }
                 catch (NullPointerException e)
                 {
                     eInfo.attackEffect = EntityInfo.Effect.UNKNOWN;
+                    logEntityMissingOptionalValue("attack_effect", name, "unknown");
                 }
 
                 try
@@ -469,12 +486,13 @@ public class Config
                     if(eInfo.attackVariance < 0)
                     {
                         eInfo.attackVariance = 0;
-                        logEntityInvalidValue("attack_variance", eInfo.classType.getName(), "0");
+                        logEntityInvalidValue("attack_variance", name, "0");
                     }
                 }
                 catch (NullPointerException e)
                 {
                     eInfo.attackVariance = 0;
+                    logEntityMissingOptionalValue("attack_variance", name, "0");
                 }
 
                 try
@@ -483,7 +501,7 @@ public class Config
                     if(eInfo.defenseDamage < 0)
                     {
                         eInfo.defenseDamage = 0;
-                        logEntityInvalidValue("defense_damage", eInfo.classType.getName(), "0");
+                        logEntityInvalidValue("defense_damage", name, "0");
                     }
                     else
                     {
@@ -491,13 +509,14 @@ public class Config
                         if(eInfo.defenseDamageProbability < 0 || eInfo.defenseDamageProbability > 100)
                         {
                             eInfo.defenseDamageProbability = 35;
-                            logEntityInvalidValue("defense_damage_probability", eInfo.classType.getName(), "35");
+                            logEntityInvalidValue("defense_damage_probability", name, "35");
                         }
                     }
                 }
                 catch (NullPointerException e)
                 {
                     eInfo.defenseDamage = 0;
+                    logEntityMissingOptionalValue("defense_damage", name, "0");
                 }
 
                 try
@@ -506,12 +525,12 @@ public class Config
                     if(eInfo.evasion < 0 || eInfo.evasion > 100)
                     {
                         eInfo.evasion = 20;
-                        logEntityInvalidValue("evasion", eInfo.classType.getName(), "20");
+                        logEntityInvalidValue("evasion", name, "20");
                     }
                 }
                 catch (NullPointerException e)
                 {
-                    logEntityMissingRequiredValue("evasion", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("evasion", name);
                     continue;
                 }
 
@@ -521,7 +540,8 @@ public class Config
                 }
                 catch (NullPointerException e)
                 {
-                    logEntityMissingRequiredValue("speed", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("speed", name);
+                    continue;
                 }
 
                 try
@@ -531,12 +551,13 @@ public class Config
                 catch (NullPointerException e)
                 {
                     eInfo.ignoreBattle = false;
+                    logEntityMissingOptionalValue("ignore_battle", name, "false");
                 }
 
                 eInfo.category = entity.getString("category");
                 if(eInfo.category == null)
                 {
-                    logEntityMissingRequiredValue("category", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("category", name);
                     continue;
                 }
 
@@ -546,7 +567,7 @@ public class Config
                 }
                 catch (NullPointerException e)
                 {
-                    logEntityMissingRequiredValue("decision_attack_probability", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("decision_attack_probability", name);
                     continue;
                 }
 
@@ -556,7 +577,7 @@ public class Config
                 }
                 catch (NullPointerException e)
                 {
-                    logEntityMissingRequiredValue("decision_defend_probability", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("decision_defend_probability", name);
                     continue;
                 }
 
@@ -566,11 +587,22 @@ public class Config
                 }
                 catch (NullPointerException e)
                 {
-                    logEntityMissingRequiredValue("decision_flee_probability", eInfo.classType.getName());
+                    logEntityMissingRequiredValue("decision_flee_probability", name);
                     continue;
                 }
 
-                entityInfoMap.put(eInfo.classType.getName(), eInfo);
+                if(eInfo.classType != null)
+                {
+                    entityInfoMap.put(eInfo.classType.getName(), eInfo);
+                }
+                else if(!eInfo.customName.isEmpty())
+                {
+                    customEntityInfoMap.put(eInfo.customName, eInfo);
+                }
+                else
+                {
+                    logger.error("Cannot add entity to internal config, no \"name\" or \"custom_name\"");
+                }
             }
         }
         return true;
@@ -596,22 +628,51 @@ public class Config
         logger.error("Entity \"" + name + "\" does not have option \"" + option + "\", skipping...");
     }
 
+    private void logEntityMissingOptionalValue(String option, String name, String defaultValue)
+    {
+        logger.info("Entity \"" + name + "\" does not have optional option \"" + option + "\", defaulting to \"" + defaultValue + "\"...");
+    }
+
     private String getRegexEntityName(String name)
     {
         String regex = "^\\s*name\\s*=\\s*";
         regex += "(\"" + name + "\"";
-        regex += "|'" + name + "')";
+        regex += "|'" + name + "'";
+        regex += "|\"\"\"" + name + "\"\"\"";
+        regex += "|'''" + name + "''')";
+        return regex;
+    }
+
+    private String getRegexCustomEntityName(String name)
+    {
+        String regex = "^\\s*custom_name\\s*=\\s*";
+        regex += "(\"" + name + "\"";
+        regex += "|'" + name + "'";
+        regex += "|\"\"\"" + name + "\"\"\"";
+        regex += "|'''" + name + "''')";
         return regex;
     }
 
     private boolean addEntityEntry(EntityInfo eInfo)
     {
+        if(eInfo.classType == null && eInfo.customName.isEmpty())
+        {
+            logger.error("addEntityEntry: Got invalid eInfo, no name of any type");
+            return false;
+        }
         try
         {
             File config = new File(TurnBasedMinecraftMod.CONFIG_FILE_PATH);
             FileWriter fw = new FileWriter(config, true);
             fw.write("[[server_config.entity]]\n");
-            fw.write("name = \"" + eInfo.classType.getName() + "\"\n");
+            if(eInfo.classType != null)
+            {
+                fw.write("name = \"" + eInfo.classType.getName() + "\"\n");
+            }
+            else
+            {
+                fw.write("custom_name = \"" + eInfo.customName + "\"\n");
+            }
             fw.write("attack_power = " + eInfo.attackPower + "\n");
             fw.write("attack_probability = " + eInfo.attackProbability + "\n");
             if(eInfo.attackVariance > 0)
@@ -632,7 +693,7 @@ public class Config
             fw.write("speed = " + eInfo.speed + "\n");
             if(eInfo.ignoreBattle)
             {
-                fw.write("ignoreBattle = true\n");
+                fw.write("ignore_battle = true\n");
             }
             fw.write("category = \"" + eInfo.category + "\"\n");
             fw.write("decision_attack_probability = " + eInfo.decisionAttack + "\n");
@@ -640,11 +701,25 @@ public class Config
             fw.write("decision_flee_probability = " + eInfo.decisionFlee + "\n");
             fw.close();
 
-            entityInfoMap.put(eInfo.classType.getName(), eInfo);
+                       if(eInfo.classType != null)
+                       {
+                               entityInfoMap.put(eInfo.classType.getName(), eInfo);
+                       }
+                       else
+                       {
+                               customEntityInfoMap.put(eInfo.customName, eInfo);
+                       }
         }
         catch (Throwable t)
         {
-            logger.error("Failed to add entity entry (name = \"" + eInfo.classType.getName() + "\")");
+                       if(eInfo.classType != null)
+                       {
+                               logger.error("Failed to add entity entry (name = \"" + eInfo.classType.getName() + "\")");
+                       }
+                       else
+                       {
+                               logger.error("Failed to add custom entity entry (custom_name = \"" + eInfo.customName + "\")");
+                       }
             return false;
         }
         return true;
@@ -670,6 +745,7 @@ public class Config
             }
 
             int nameIndex = -1;
+            if(eInfo.classType != null)
             {
                 Pattern p = Pattern.compile(getRegexEntityName(eInfo.classType.getName()), Pattern.MULTILINE);
                 Matcher m = p.matcher(cached);
@@ -678,6 +754,20 @@ public class Config
                     nameIndex = m.start();
                 }
             }
+            else if(!eInfo.customName.isEmpty())
+            {
+                Pattern p = Pattern.compile(getRegexCustomEntityName(eInfo.customName), Pattern.MULTILINE);
+                Matcher m = p.matcher(cached);
+                if(m.find())
+                {
+                    nameIndex = m.start();
+                }
+            }
+            else
+            {
+                logger.error("EntityInfo does not have classType or customName, cannot edit/add");
+                return false;
+            }
             int entryIndex = -1;
             int nextIndex = -1;
             if(nameIndex != -1)
@@ -706,7 +796,14 @@ public class Config
             }
             else
             {
-                logger.warn("editEntityEntry: could not find entry for \"" + eInfo.classType.getName() + "\", skipping to adding it...");
+                if(eInfo.classType != null)
+                {
+                    logger.warn("editEntityEntry: could not find entry for \"" + eInfo.classType.getName() + "\", skipping to adding it...");
+                }
+                else if(!eInfo.customName.isEmpty())
+                {
+                    logger.warn("editEntityEntry: could not find entry for \"" + eInfo.customName + "\", skipping to adding it...");
+                }
                 return addEntityEntry(eInfo);
             }
 
@@ -781,7 +878,12 @@ public class Config
      */
     public EntityInfo getEntityInfo(String classFullName)
     {
-        return entityInfoMap.get(classFullName).clone();
+        EntityInfo eInfo = entityInfoMap.get(classFullName);
+        if(eInfo != null)
+        {
+            eInfo = eInfo.clone();
+        }
+        return eInfo;
     }
 
     protected EntityInfo getEntityInfoReference(String classFullName)
@@ -803,6 +905,26 @@ public class Config
         return null;
     }
 
+    /**
+     * Returns a clone of an EntityInfo (to prevent editing it).
+     * @param customName
+     * @return a clone of the stored custom EntityInfo or null if invalid String
+     */
+    public EntityInfo getCustomEntityInfo(String customName)
+    {
+        EntityInfo eInfo = customEntityInfoMap.get(customName);
+        if(eInfo != null)
+        {
+            eInfo = eInfo.clone();
+        }
+        return eInfo;
+    }
+
+    protected EntityInfo getCustomEntityInfoReference(String customName)
+    {
+        return customEntityInfoMap.get(customName);
+    }
+
     private int getConfigFileVersion(InputStream io)
     {
         int version = 0;
index 02737f2cef7034126c8db27083c5d990b265b5ba..6ae4178ab6e121a896926aed5e757cea24f2ed6a 100644 (file)
@@ -7,12 +7,14 @@ public class EditingInfo
     public EntityPlayer editor;
     public EntityInfo entityInfo;
     public boolean isPendingEntitySelection;
+    public boolean isEditingCustomName;
 
     public EditingInfo()
     {
         editor = null;
         entityInfo = null;
         isPendingEntitySelection = true;
+        isEditingCustomName = false;
     }
 
     public EditingInfo(EntityPlayer player)
@@ -20,5 +22,6 @@ public class EditingInfo
         editor = player;
         entityInfo = null;
         isPendingEntitySelection = true;
+        isEditingCustomName = false;
     }
 }
index 06f27c480af3156c39a52cb1e8171d34ba139b70..6b86eae6d6a7674485bce548d8eebca4b7cec675 100644 (file)
@@ -21,6 +21,7 @@ public class EntityInfo
     public int decisionAttack;
     public int decisionDefend;
     public int decisionFlee;
+    public String customName;
     
     public enum Effect
     {
@@ -379,6 +380,7 @@ public class EntityInfo
         decisionAttack = 70;
         decisionDefend = 20;
         decisionFlee = 10;
+        customName = new String();
     }
     
     public EntityInfo clone()
@@ -399,6 +401,7 @@ public class EntityInfo
         newEntityInfo.decisionAttack = decisionAttack;
         newEntityInfo.decisionDefend = decisionDefend;
         newEntityInfo.decisionFlee = decisionFlee;
+        newEntityInfo.customName = new String(customName);
         return newEntityInfo;
     }
 }
index 7c28a9a4ab977179ccd71cd0b354f937c3c01f39..0d1040c2a02b0f72c98de31cb4c0423e24ca428e 100644 (file)
@@ -21,7 +21,7 @@ public class TurnBasedMinecraftMod
 {
     public static final String MODID = "com.seodisparate.turnbasedminecraft";
     public static final String NAME = "Turn Based Minecraft Mod";
-    public static final String VERSION = "1.6";
+    public static final String VERSION = "1.7";
     public static final String CONFIG_FILENAME = "TBM_Config.toml";
     public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
     public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;
index b2ed44a0ea53c016fe9310682190dad4106c15fd..a402b6b80d0ffbe85f498e79d82e695845fc93b1 100644 (file)
@@ -104,6 +104,7 @@ public class PacketEditingMessage implements IMessage
         entityInfo.decisionAttack = buf.readInt();
         entityInfo.decisionDefend = buf.readInt();
         entityInfo.decisionFlee = buf.readInt();
+        entityInfo.customName = ByteBufUtils.readUTF8String(buf);
     }
 
     @Override
@@ -132,6 +133,7 @@ public class PacketEditingMessage implements IMessage
         buf.writeInt(entityInfo.decisionAttack);
         buf.writeInt(entityInfo.decisionDefend);
         buf.writeInt(entityInfo.decisionFlee);
+        ByteBufUtils.writeUTF8String(buf, entityInfo.customName);
     }
 
     public static class HandlerEditingMessage implements IMessageHandler<PacketEditingMessage, IMessage>
@@ -230,7 +232,7 @@ public class PacketEditingMessage implements IMessage
                 option = new TextComponentString("E");
                 option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion"))
                     .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Evasion")));
-                value = new TextComponentString("(" + message.entityInfo.evasion + ") ");
+                value = new TextComponentString("(" + message.entityInfo.evasion + "%) ");
                 value.getStyle().setColor(TextFormatting.WHITE);
                 option.appendSibling(value);
                 text.appendSibling(option);
index dd0c7edbe73032bccb84176cd793b841a5693c34..4ef75d502b5264f525bf489e8e29129e4151ca18 100644 (file)
@@ -66,7 +66,8 @@ battle_turn_time_seconds = 15
 
 
 # Each "server_config.entity" entry uses the following options:
-# name: full class name of the entity
+# name: full class name of the entity, cannot also have option "custom_name"
+# custom_name: custom name-tag name, cannot also have option "name"
 # attack_power: how much damage an entity does on successful attack
 # attack_probability: percentage of attack success. (Usually calculated with enemy's evasion to determine actual percentage)
 # attack_variance (optional): determines how much a successful attack's damage varies.