Implement the defaultAttackStrategy

This commit is contained in:
fullwall 2013-07-18 00:22:49 +08:00
parent 0f156caf6a
commit dfc7f7e553
2 changed files with 16 additions and 6 deletions

View File

@ -30,6 +30,7 @@ import org.bukkit.util.Vector;
public class CitizensNavigator implements Navigator, Runnable {
private final NavigatorParameters defaultParams = new NavigatorParameters().baseSpeed(UNINITIALISED_SPEED)
.range(Setting.DEFAULT_PATHFINDING_RANGE.asFloat())
.defaultAttackStrategy(MCTargetStrategy.DEFAULT_ATTACK_STRATEGY)
.stationaryTicks(Setting.DEFAULT_STATIONARY_TICKS.asInt()).stuckAction(TeleportStuckAction.INSTANCE)
.examiner(new MinecraftBlockExaminer()).useNewPathfinder(Setting.USE_NEW_PATHFINDER.asBoolean());
private PathStrategy executing;

View File

@ -121,12 +121,6 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
if (aggro && canAttack()) {
AttackStrategy strategy = parameters.attackStrategy();
if (strategy != null && strategy.handle((LivingEntity) handle.getBukkitEntity(), getTarget())) {
} else if (handle instanceof EntityPlayer) {
EntityPlayer humanHandle = (EntityPlayer) handle;
humanHandle.attack(target);
PlayerAnimation.ARM_SWING.play(humanHandle.getBukkitEntity());
} else {
NMS.attack(handle, target);
}
attackTicks = ATTACK_DELAY_TICKS;
}
@ -216,6 +210,21 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
}
private static final int ATTACK_DELAY_TICKS = 20;
static final AttackStrategy DEFAULT_ATTACK_STRATEGY = new AttackStrategy() {
@Override
public boolean handle(LivingEntity attacker, LivingEntity bukkitTarget) {
EntityLiving handle = NMS.getHandle(attacker);
EntityLiving target = NMS.getHandle(bukkitTarget);
if (handle instanceof EntityPlayer) {
EntityPlayer humanHandle = (EntityPlayer) handle;
humanHandle.attack(target);
PlayerAnimation.ARM_SWING.play(humanHandle.getBukkitEntity());
} else {
NMS.attack(handle, target);
}
return false;
}
};
private static Field E_NAV_E, E_NAV_J, E_NAV_M;
private static final Location HANDLE_LOCATION = new Location(null, 0, 0, 0);
private static Field P_NAV_E, P_NAV_J, P_NAV_M;