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
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
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);
+ }
+ }
}
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;
}
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;
+ }
}
}
}
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
{
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))
private Set<Integer> battleIgnoringPlayers = null;
private boolean onlyOPsSelfDisableTB = true;
private boolean battleDisabledForAll = false;
+ private boolean oldBattleBehaviorEnabled = false;
public Config(Logger logger)
{
{
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"))
{
return battleDisabledForAll;
}
+
+ public boolean isOldBattleBehaviorEnabled()
+ {
+ return oldBattleBehaviorEnabled;
+ }
}
{
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;
<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. -->