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;
@ -92,7 +93,7 @@ public class BlockBreaker extends BehaviorGoalAdapter {
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier(); float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
if (damage >= 1F) { if (damage >= 1F) {
entity.world.getWorld().getBlockAt(x, y, z) entity.world.getWorld().getBlockAt(x, y, z)
.breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem())); .breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
return BehaviorStatus.SUCCESS; return BehaviorStatus.SUCCESS;
} }
int modifiedDamage = (int) (damage * 10.0F); int modifiedDamage = (int) (damage * 10.0F);

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,11 +35,11 @@ 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)
: new AStarTargeter(); : new AStarTargeter();
this.aggro = aggro; this.aggro = aggro;
} }
@ -163,7 +162,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
private void setStrategy() { private void setStrategy() {
Location location = target.getBukkitEntity().getLocation(TARGET_LOCATION); Location location = target.getBukkitEntity().getLocation(TARGET_LOCATION);
strategy = npc.isFlyable() ? new FlyingAStarNavigationStrategy(npc, location, parameters) strategy = npc.isFlyable() ? new FlyingAStarNavigationStrategy(npc, location, parameters)
: new AStarNavigationStrategy(npc, location, parameters); : new AStarNavigationStrategy(npc, location, parameters);
} }
@Override @Override

View File

@ -166,7 +166,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
moveOnCurrentHeading(); moveOnCurrentHeading();
} else if (motX != 0 || motZ != 0 || motY != 0) { } else if (motX != 0 || motZ != 0 || motY != 0) {
e(0, 0); // is this necessary? it does controllable but sometimes e(0, 0); // is this necessary? it does controllable but sometimes
// players sink into the ground // players sink into the ground
} }
if (noDamageTicks > 0) { if (noDamageTicks > 0) {

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);
} }
} }