mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-26 01:01:42 +01:00
Implement the defaultAttackStrategy
This commit is contained in:
parent
0f156caf6a
commit
dfc7f7e553
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user