Fix default pathfinding range and updating pathfinding range

This commit is contained in:
fullwall 2013-07-05 15:44:18 +08:00
parent a381c3e12d
commit 01ede533f8
5 changed files with 27 additions and 10 deletions

View File

@ -28,8 +28,9 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
navigation = NMS.getNavigation(handle);
navigation.a(parameters.avoidWater());
navigation.a(dest.getX(), dest.getY(), dest.getZ(), parameters.speed());
if (NMS.isNavigationFinished(navigation))
if (NMS.isNavigationFinished(navigation)) {
setCancelReason(CancelReason.STUCK);
}
}
@Override

View File

@ -166,7 +166,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
private class NavigationFieldWrapper implements TargetNavigator {
boolean j = true, k, l, m;
private final Navigation navigation;
float speed;
float range;
private NavigationFieldWrapper(Navigation navigation) {
this.navigation = navigation;
@ -175,26 +175,26 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
try {
if (navigation instanceof PlayerNavigation) {
if (P_NAV_E != null)
speed = (float) ((AttributeInstance) P_NAV_E.get(navigation)).e();
range = (float) ((AttributeInstance) P_NAV_E.get(navigation)).e();
if (P_NAV_J != null)
j = P_NAV_J.getBoolean(navigation);
if (P_NAV_M != null)
m = P_NAV_M.getBoolean(navigation);
} else {
if (E_NAV_E != null)
speed = (float) ((AttributeInstance) E_NAV_E.get(navigation)).e();
range = (float) ((AttributeInstance) E_NAV_E.get(navigation)).e();
if (E_NAV_J != null)
j = E_NAV_J.getBoolean(navigation);
if (E_NAV_M != null)
m = E_NAV_M.getBoolean(navigation);
}
} catch (Exception ex) {
speed = parameters.speed();
range = parameters.speed();
}
}
public PathEntity findPath(Entity from, Entity to) {
return handle.world.findPath(from, to, speed, j, k, l, m);
return handle.world.findPath(from, to, range, j, k, l, m);
}
@Override

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.net.Socket;
import java.util.List;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
@ -144,8 +145,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
AttributeInstance range = this.aT().a(GenericAttributes.b);
if (range == null) {
range = this.aT().b(GenericAttributes.b);
range.a(16D);
}
range.a(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
controllerJump = new PlayerControllerJump(this);
controllerLook = new PlayerControllerLook(this);
controllerMove = new PlayerControllerMove(this);
@ -252,7 +253,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
}
public void updatePathfindingRange(float pathfindingRange) {
this.navigation.a(pathfindingRange);
this.navigation.setRange(pathfindingRange);
}
public static class PlayerNPC extends CraftPlayer implements NPCHolder {

View File

@ -380,9 +380,18 @@ public class NMS {
}
return;
}
if (PATHFINDING_RANGE == null)
return;
EntityInsentient handle = (EntityInsentient) en;
Navigation navigation = handle.getNavigation();
navigation.a(pathfindingRange);
try {
AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation);
inst.a(pathfindingRange);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private static final float DEFAULT_SPEED = 1F;
@ -393,8 +402,8 @@ public class NMS {
private static final Field JUMP_FIELD = getField(EntityLiving.class, "bd");
private static Field NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b");
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE = getField(Navigation.class, "e");
private static final Random RANDOM = Util.getFastRandom();
private static Field THREAD_STOPPER = getField(NetworkManager.class, "n");
// true field above false and three synchronised lists

View File

@ -382,6 +382,12 @@ public class PlayerNavigation extends Navigation {
}
}
public void setRange(float pathfindingRange) {
if (this.e != null) {
this.e.a(pathfindingRange);
}
}
private static EntityInsentient getDummyInsentient(EntityHumanNPC from) {
return new EntityInsentient(null) {
};