]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Version 1.3, Fixes, improvements
authorStephen Seo <seo.disparate@gmail.com>
Wed, 17 Oct 2018 08:15:23 +0000 (17:15 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 17 Oct 2018 08:15:23 +0000 (17:15 +0900)
Changed turn-based-battle start behavior to also start when a hostile
mob targets a player or entity in battle.
Added config option to revert to old-style battle starting behavior.
(Since config version updated, older config will be moved and the new
config will take its place.)
Changed mob attack target in Battle to whatever they were targeting (via
a call to "getAttackTarget()").

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/Config.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java
src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml

index 05c110e6f5c29e2a3ac06b72eded869290112239..2c0d145d228e04bf89fcc56bec4a9e9f34646d95 100644 (file)
@@ -10,7 +10,7 @@ buildscript {
 apply plugin: 'net.minecraftforge.gradle.forge'\r
 //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.\r
 \r
-version = "1.2"\r
+version = "1.3"\r
 group = "com.seodisparate.TurnBasedMinecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html\r
 archivesBaseName = "TurnBasedMinecraft"\r
 \r
index 0a7a1a9b1c722bc68554088b1948d2d2bb122d46..4a33b592090fdd480cfd8940b4c81db2fca09a6c 100644 (file)
@@ -6,6 +6,7 @@ import java.util.Queue;
 import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
 
 import net.minecraftforge.event.entity.living.LivingAttackEvent;
+import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
 import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
 
 public class AttackEventHandler
@@ -83,4 +84,20 @@ public class AttackEventHandler
             TurnBasedMinecraftMod.proxy.setAttackingDamage((int) event.getAmount());
         }
     }
+    
+    @SubscribeEvent
+    public void entityTargeted(LivingSetAttackTargetEvent event)
+    {
+        if(event.getEntity().world.isRemote || TurnBasedMinecraftMod.proxy.getConfig().isOldBattleBehaviorEnabled())
+        {
+            return;
+        }
+        else if(event.getEntity() != null
+                && event.getTarget() != null
+                && !TurnBasedMinecraftMod.proxy.getConfig().getBattleIgnoringPlayers().contains(event.getEntity().getEntityId())
+                && !TurnBasedMinecraftMod.proxy.getConfig().getBattleIgnoringPlayers().contains(event.getTarget().getEntityId()))
+        {
+            TurnBasedMinecraftMod.proxy.getBattleManager().checkTargeted(event);
+        }
+    }
 }
index 8958f1afb92dba9ffe27e750e9cbc32068dd6643..d40ca3f441ea640dc44e3482c8744f42a5e500af 100644 (file)
@@ -15,6 +15,7 @@ import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
 import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
 
 import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLiving;
 import net.minecraft.entity.EntityLivingBase;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.entity.player.EntityPlayerMP;
@@ -885,27 +886,35 @@ public class Battle
                         }
                         else
                         {
-                            if(next.isSideA)
+                            EntityLivingBase attackTarget = ((EntityLiving)next.entity).getAttackTarget();
+                            if(attackTarget != null && hasCombatant(attackTarget.getEntityId()))
+                            {
+                                target = getCombatantByID(attackTarget.getEntityId());
+                            }
+                            else
                             {
-                                int randomTargetIndex = (int)(Math.random() * sideB.size());
-                                for(Combatant c : sideB.values())
+                                if(next.isSideA)
                                 {
-                                    if(randomTargetIndex-- == 0)
+                                    int randomTargetIndex = (int)(Math.random() * sideB.size());
+                                    for(Combatant c : sideB.values())
                                     {
-                                        target = c;
-                                        break;
+                                        if(randomTargetIndex-- == 0)
+                                        {
+                                            target = c;
+                                            break;
+                                        }
                                     }
                                 }
-                            }
-                            else
-                            {
-                                int randomTargetIndex = (int)(Math.random() * sideA.size());
-                                for(Combatant c : sideA.values())
+                                else
                                 {
-                                    if(randomTargetIndex-- == 0)
+                                    int randomTargetIndex = (int)(Math.random() * sideA.size());
+                                    for(Combatant c : sideA.values())
                                     {
-                                        target = c;
-                                        break;
+                                        if(randomTargetIndex-- == 0)
+                                        {
+                                            target = c;
+                                            break;
+                                        }
                                     }
                                 }
                             }
index 80a8581202aa4087b66e2740da2273fc95d7d754..4532c4f93f2786980b572de55bf85105f8c73a6c 100644 (file)
@@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger;
 import net.minecraft.entity.Entity;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraftforge.event.entity.living.LivingAttackEvent;
+import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
 
 public class BattleManager
 {
@@ -155,6 +156,89 @@ public class BattleManager
         return true;
     }
     
+    public void checkTargeted(LivingSetAttackTargetEvent event)
+    {
+        EntityInfo attackerInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity());
+        EntityInfo targetedInfo = event.getTarget() instanceof EntityPlayer ? null : TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getTarget());
+        if((event.getTarget() instanceof EntityPlayer && ((EntityPlayer)event.getTarget()).isCreative())
+                || attackerInfo == null
+                || attackerInfo.ignoreBattle
+                || TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(attackerInfo.category)
+                || (targetedInfo != null
+                    && (targetedInfo.ignoreBattle
+                        || TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(targetedInfo.category))))
+        {
+            return;
+        }
+        
+        Entity inBattle = null;
+        Entity notInBattle = null;
+        Battle battle = null;
+        
+        for(Battle b : battleMap.values())
+        {
+            if(b.hasCombatant(event.getEntity().getEntityId()))
+            {
+                if(inBattle != null)
+                {
+                    // both entities already in battle
+                    return;
+                }
+                else
+                {
+                    inBattle = event.getEntity();
+                    notInBattle = event.getTarget();
+                    battle = b;
+                }
+            }
+            if(b.hasCombatant(event.getTarget().getEntityId()))
+            {
+                if(inBattle != null)
+                {
+                    // both entities already in battle
+                    return;
+                }
+                else
+                {
+                    inBattle = event.getTarget();
+                    notInBattle = event.getEntity();
+                    battle = b;
+                }
+            }
+        }
+        
+        if(battle == null)
+        {
+            // neither in battle
+            if(event.getEntity() instanceof EntityPlayer || event.getTarget() instanceof EntityPlayer)
+            {
+                // at least one is a player, create battle
+                Collection<Entity> sideA = new ArrayList<Entity>(1);
+                Collection<Entity> sideB = new ArrayList<Entity>(1);
+                sideA.add(event.getEntity());
+                sideB.add(event.getTarget());
+                createBattle(sideA, sideB);
+            }
+        }
+        else
+        {
+            // add entity to battle
+            if(battle.getSize() >= TurnBasedMinecraftMod.proxy.getConfig().getMaxInBattle())
+            {
+                // battle max reached, cannot add to battle
+                return;
+            }
+            else if(battle.hasCombatantInSideA(inBattle.getEntityId()))
+            {
+                battle.addCombatantToSideB(notInBattle);
+            }
+            else
+            {
+                battle.addCombatantToSideA(notInBattle);
+            }
+        }
+    }
+    
     private Battle createBattle(Collection<Entity> sideA, Collection<Entity> sideB)
     {
         while(battleMap.containsKey(IDCounter))
index 1ca518fbf0b550b0d171b8a597b2147575cad278..7e868b0c8eb66b7c3c341c9147ab20727e7de756 100644 (file)
@@ -48,6 +48,7 @@ public class Config
     private Set<Integer> battleIgnoringPlayers = null;
     private boolean onlyOPsSelfDisableTB = true;
     private boolean battleDisabledForAll = false;
+    private boolean oldBattleBehaviorEnabled = false;
     
     public Config(Logger logger)
     {
@@ -174,6 +175,17 @@ public class Config
                 {
                     continue;
                 }
+                else if(xmlReader.getLocalName().equals("OldBattleBehavior"))
+                {
+                    if(xmlReader.getElementText().toLowerCase().equals("false"))
+                    {
+                        oldBattleBehaviorEnabled = false;
+                    }
+                    else
+                    {
+                        oldBattleBehaviorEnabled = true;
+                    }
+                }
                 else if(xmlReader.getLocalName().equals("WhoCanDisableTurnBasedForSelf"))
                 {
                     if(xmlReader.getElementText().toLowerCase().equals("any"))
@@ -617,4 +629,9 @@ public class Config
     {
         return battleDisabledForAll;
     }
+    
+    public boolean isOldBattleBehaviorEnabled()
+    {
+        return oldBattleBehaviorEnabled;
+    }
 }
index 5d247a86c7e10dc7ede84f1f1f69da42fbc56bda..29bc32f4c99e899067dee0f983b84c913219f493 100644 (file)
@@ -26,7 +26,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.2";
+    public static final String VERSION = "1.3";
     public static final String CONFIG_FILENAME = "TBM_Config.xml";
     public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
     public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;
index afcea5d82f00845e7163764a64861a034a4151aa..750d4a3b42f3627ad6843aa74588fc1d84eb2e20 100644 (file)
@@ -1,6 +1,9 @@
 <TurnBasedMinecraftConfig>
        <!-- If the mod has a newer version config, it will rename the existing config and place the new config -->
-       <Version>4</Version>
+       <Version>5</Version>
+       <!-- If not "false", uses old battle behavior where battles only start on attack/hit. Otherwise, battles can
+       start when a hostile mob targets a player or another entity in battle. -->
+       <OldBattleBehavior>false</OldBattleBehavior>
        <!-- Determines who can disable turn-based-battle for themselves via command. Must be "op" or "any". If neither, defaults to "op"-->
        <WhoCanDisableTurnBasedForSelf>op</WhoCanDisableTurnBasedForSelf>
        <!-- If there are "MaxInBattle" amount of entities in battle, other entities cannot join until combatants leave battle. -->