Force new pathfinder with nonliving NPCs

This commit is contained in:
fullwall 2014-01-09 16:25:32 +08:00
parent 6cc922a115
commit 34fc6ab029
5 changed files with 12 additions and 12 deletions

View File

@ -82,8 +82,9 @@ public class BlockBreaker extends BehaviorGoalAdapter {
startDigTick = currentTick; startDigTick = currentTick;
return BehaviorStatus.RUNNING; return BehaviorStatus.RUNNING;
} }
if (entity instanceof EntityPlayer) if (entity instanceof EntityPlayer) {
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity()); PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
}
Block block = entity.world.getType(x, y, z); Block block = entity.world.getType(x, y, z);
if (block == null) { if (block == null) {
return BehaviorStatus.SUCCESS; return BehaviorStatus.SUCCESS;

View File

@ -180,7 +180,7 @@ public class CitizensNavigator implements Navigator, Runnable {
PathStrategy newStrategy; PathStrategy newStrategy;
if (npc.isFlyable()) { if (npc.isFlyable()) {
newStrategy = new FlyingAStarNavigationStrategy(npc, target, localParams); newStrategy = new FlyingAStarNavigationStrategy(npc, target, localParams);
} else if (localParams.useNewPathfinder()) { } else if (localParams.useNewPathfinder() || !(npc.getEntity() instanceof LivingEntity)) {
newStrategy = new AStarNavigationStrategy(npc, target, localParams); newStrategy = new AStarNavigationStrategy(npc, target, localParams);
} else { } else {
newStrategy = new MCNavigationStrategy(npc, target, localParams); newStrategy = new MCNavigationStrategy(npc, target, localParams);

View File

@ -20,14 +20,13 @@ import net.minecraft.server.v1_7_R1.PathEntity;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftLivingEntity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
public class MCTargetStrategy implements PathStrategy, EntityTarget { public class MCTargetStrategy implements PathStrategy, EntityTarget {
private final boolean aggro; private final boolean aggro;
private int attackTicks; private int attackTicks;
private CancelReason cancelReason; private CancelReason cancelReason;
private final EntityLiving handle; private final Entity handle;
private final NPC npc; private final NPC npc;
private final NavigatorParameters parameters; private final NavigatorParameters parameters;
private final Entity target; private final Entity target;
@ -36,7 +35,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
public MCTargetStrategy(NPC npc, org.bukkit.entity.Entity target, boolean aggro, NavigatorParameters params) { public MCTargetStrategy(NPC npc, org.bukkit.entity.Entity target, boolean aggro, NavigatorParameters params) {
this.npc = npc; this.npc = npc;
this.parameters = params; this.parameters = params;
this.handle = ((CraftLivingEntity) npc.getEntity()).getHandle(); this.handle = ((CraftEntity) npc.getEntity()).getHandle();
this.target = ((CraftEntity) target).getHandle(); this.target = ((CraftEntity) target).getHandle();
Navigation nav = NMS.getNavigation(this.handle); Navigation nav = NMS.getNavigation(this.handle);
this.targetNavigator = nav != null && !params.useNewPathfinder() ? new NavigationFieldWrapper(nav) this.targetNavigator = nav != null && !params.useNewPathfinder() ? new NavigationFieldWrapper(nav)

View File

@ -207,7 +207,7 @@ public class NMS {
return handle.aP; return handle.aP;
} }
public static Navigation getNavigation(EntityLiving handle) { public static Navigation getNavigation(Entity handle) {
return handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() return handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null;
} }
@ -249,11 +249,11 @@ public class NMS {
((CraftServer) Bukkit.getServer()).enablePlugins(PluginLoadOrder.POSTWORLD); ((CraftServer) Bukkit.getServer()).enablePlugins(PluginLoadOrder.POSTWORLD);
} }
public static void look(EntityLiving handle, Entity target) { public static void look(Entity handle, Entity target) {
if (handle instanceof EntityInsentient) { if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerLook().a(target, 10.0F, ((EntityInsentient) handle).x()); ((EntityInsentient) handle).getControllerLook().a(target, 10.0F, ((EntityInsentient) handle).x());
} else if (handle instanceof EntityHumanNPC) { } else if (handle instanceof EntityHumanNPC) {
((EntityHumanNPC) handle).setTargetLook(target, 10F, 40); ((EntityHumanNPC) handle).setTargetLook(target, 10F, 40F);
} }
} }