mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-08-14 08:42:48 +02:00
A* jumping fix
This commit is contained in:
parent
02cc53d2a2
commit
5b6f55ec50
|
@ -31,9 +31,8 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
|
||||||
this.destination = dest;
|
this.destination = dest;
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
Location location = npc.getBukkitEntity().getEyeLocation();
|
Location location = npc.getBukkitEntity().getEyeLocation();
|
||||||
plan = ASTAR.runFully(new VectorGoal(dest),
|
plan = ASTAR.runFully(new VectorGoal(dest, (float) params.distanceMargin()), new VectorNode(location,
|
||||||
new VectorNode(location, new ChunkBlockSource(location, params.range()), params.examiners()),
|
new ChunkBlockSource(location, params.range()), params.examiners()), (int) (params.range() * 10));
|
||||||
(int) (params.range() * 10));
|
|
||||||
if (plan == null || plan.isComplete()) {
|
if (plan == null || plan.isComplete()) {
|
||||||
setCancelReason(CancelReason.STUCK);
|
setCancelReason(CancelReason.STUCK);
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,13 +52,15 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update() {
|
public boolean update() {
|
||||||
if (getCancelReason() != null || plan == null || plan.isComplete())
|
if (getCancelReason() != null || plan == null || plan.isComplete()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
if (npc.getBukkitEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params
|
if (npc.getBukkitEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params
|
||||||
.distanceMargin()) {
|
.distanceMargin()) {
|
||||||
plan.update(npc);
|
plan.update(npc);
|
||||||
if (plan.isComplete())
|
if (plan.isComplete()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
vector = plan.getCurrentVector();
|
vector = plan.getCurrentVector();
|
||||||
World world = npc.getBukkitEntity().getWorld();
|
World world = npc.getBukkitEntity().getWorld();
|
||||||
world.playEffect(vector.toLocation(world), Effect.STEP_SOUND, Material.STONE.getId());
|
world.playEffect(vector.toLocation(world), Effect.STEP_SOUND, Material.STONE.getId());
|
||||||
|
@ -70,8 +71,8 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
|
||||||
double dY = vector.getY() - handle.locY;
|
double dY = vector.getY() - handle.locY;
|
||||||
double xzDistance = dX * dX + dZ * dZ;
|
double xzDistance = dX * dX + dZ * dZ;
|
||||||
double distance = xzDistance + dY * dY;
|
double distance = xzDistance + dY * dY;
|
||||||
|
if (distance > 0 && dY > 0 && xzDistance <= 4.205) {
|
||||||
if (distance >= 0.00001 && (dY > 0 && xzDistance <= 2.75)) {
|
// 2.75 -> 4.205 (allow for diagonal jumping)
|
||||||
NMS.setShouldJump(npc.getBukkitEntity());
|
NMS.setShouldJump(npc.getBukkitEntity());
|
||||||
}
|
}
|
||||||
NMS.setDestination(npc.getBukkitEntity(), vector.getX(), vector.getY(), vector.getZ(), params.speed());
|
NMS.setDestination(npc.getBukkitEntity(), vector.getX(), vector.getY(), vector.getZ(), params.speed());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user