Fixes, add maximum-distance to aggro-start-battle
Ugly fix for still not found freeze bug in BattleUpdater. Added maximum-distance for monsters initiating battle when targeting a player or entity in battle. Updated config version to 6.
This commit is contained in:
parent
00961768b3
commit
d67fef2842
6 changed files with 78 additions and 11 deletions
|
@ -95,7 +95,8 @@ public class AttackEventHandler
|
|||
if(event.getEntity().world.isRemote
|
||||
|| config.isOldBattleBehaviorEnabled()
|
||||
|| (event.getEntity() != null && battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId()))
|
||||
|| (event.getTarget() != null && battleManager.isRecentlyLeftBattle(event.getTarget().getEntityId())))
|
||||
|| (event.getTarget() != null && battleManager.isRecentlyLeftBattle(event.getTarget().getEntityId()))
|
||||
|| (event.getEntity() != null && event.getTarget() != null && Utility.distanceBetweenEntities(event.getEntity(), event.getTarget()) > (double)config.getAggroStartBattleDistance()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -839,17 +839,14 @@ public class Battle
|
|||
Combatant target = null;
|
||||
if(next.entity instanceof EntityPlayer)
|
||||
{
|
||||
if(next.isSideA)
|
||||
target = sideA.get(next.targetEntityID);
|
||||
if(target == null)
|
||||
{
|
||||
target = sideB.get(next.targetEntityID);
|
||||
}
|
||||
else
|
||||
if(target == null || !target.entity.isEntityAlive() || target == next)
|
||||
{
|
||||
target = sideA.get(next.targetEntityID);
|
||||
}
|
||||
if(target == null || !target.entity.isEntityAlive())
|
||||
{
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
ItemStack heldItemStack = ((EntityPlayer)next.entity).getHeldItemMainhand();
|
||||
if(heldItemStack.getItem() instanceof ItemBow)
|
||||
|
@ -980,7 +977,7 @@ public class Battle
|
|||
}
|
||||
}
|
||||
}
|
||||
if(target == null || !target.entity.isEntityAlive())
|
||||
if(target == null || !target.entity.isEntityAlive() || target == next)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,35 @@ public class BattleUpdater implements Runnable
|
|||
private BattleManager manager;
|
||||
private AtomicBoolean isRunning;
|
||||
|
||||
private class UpdateRunnable implements Runnable
|
||||
{
|
||||
private Battle battle;
|
||||
private AtomicBoolean finished = new AtomicBoolean(false);
|
||||
private AtomicBoolean battleFinished = new AtomicBoolean(false);
|
||||
|
||||
public UpdateRunnable(Battle battle)
|
||||
{
|
||||
this.battle = battle;
|
||||
}
|
||||
|
||||
public boolean isFinished()
|
||||
{
|
||||
return finished.get();
|
||||
}
|
||||
|
||||
public boolean isBattleFinished()
|
||||
{
|
||||
return battleFinished.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
battleFinished.set(battle.update());
|
||||
finished.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
public BattleUpdater(BattleManager manager)
|
||||
{
|
||||
this.manager = manager;
|
||||
|
@ -25,7 +54,20 @@ public class BattleUpdater implements Runnable
|
|||
for(Iterator<Map.Entry<Integer, Battle>> iter = manager.battleMap.entrySet().iterator(); iter.hasNext();)
|
||||
{
|
||||
Map.Entry<Integer, Battle> entry = iter.next();
|
||||
if(entry.getValue().update())
|
||||
UpdateRunnable updateRunnable = new UpdateRunnable(entry.getValue());
|
||||
Thread updateThread = new Thread(updateRunnable);
|
||||
updateThread.start();
|
||||
try
|
||||
{
|
||||
updateThread.join(3000);
|
||||
} catch(InterruptedException e){ /* exception ignored */ }
|
||||
if(!updateRunnable.isFinished())
|
||||
{
|
||||
// TODO this is an ugly fix to a still-not-found freeze bug in Battle.update()
|
||||
TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + ") update timed out!");
|
||||
updateThread.stop();
|
||||
}
|
||||
else if(updateRunnable.isBattleFinished())
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class Config
|
|||
private boolean battleDisabledForAll = false;
|
||||
private boolean oldBattleBehaviorEnabled = false;
|
||||
private int leaveBattleCooldownSeconds = 5;
|
||||
private int aggroStartBattleDistance = 8;
|
||||
|
||||
public Config(Logger logger)
|
||||
{
|
||||
|
@ -187,6 +188,18 @@ public class Config
|
|||
leaveBattleCooldownSeconds = 10;
|
||||
}
|
||||
}
|
||||
else if(xmlReader.getLocalName().equals("AggroStartBattleDistance"))
|
||||
{
|
||||
aggroStartBattleDistance = Integer.parseInt(xmlReader.getElementText());
|
||||
if(aggroStartBattleDistance < 5)
|
||||
{
|
||||
aggroStartBattleDistance = 5;
|
||||
}
|
||||
else if(aggroStartBattleDistance > 50)
|
||||
{
|
||||
aggroStartBattleDistance = 50;
|
||||
}
|
||||
}
|
||||
else if(xmlReader.getLocalName().equals("OldBattleBehavior"))
|
||||
{
|
||||
if(xmlReader.getElementText().toLowerCase().equals("false"))
|
||||
|
@ -656,4 +669,9 @@ public class Config
|
|||
{
|
||||
return (long)leaveBattleCooldownSeconds * 1000000000L;
|
||||
}
|
||||
|
||||
public int getAggroStartBattleDistance()
|
||||
{
|
||||
return aggroStartBattleDistance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemArrow;
|
||||
|
||||
|
@ -43,4 +44,9 @@ public class Utility
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static double distanceBetweenEntities(Entity a, Entity b)
|
||||
{
|
||||
return Math.sqrt(Math.pow(a.posX - b.posX, 2.0) + Math.pow(a.posY - b.posY, 2.0) + Math.pow(a.posZ - b.posZ, 2.0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
<TurnBasedMinecraftConfig>
|
||||
<!-- If the mod has a newer version config, it will rename the existing config and place the new config -->
|
||||
<Version>5</Version>
|
||||
<Version>6</Version>
|
||||
<!-- Number of seconds that an entity cannot enter battle after having just left one. Minimum 1, maximum 10-->
|
||||
<LeaveBattleCooldown>5</LeaveBattleCooldown>
|
||||
<!-- Maximum distance for a monster to start battle by targeting a player or other entity in turn-based-battle.
|
||||
Minimum 5, maximum 50. -->
|
||||
<AggroStartBattleDistance>8</AggroStartBattleDistance>
|
||||
<!-- 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>
|
||||
|
|
Loading…
Reference in a new issue