Adjust minecraft pathfinder to look less frequently and pathfind closer to destination in players

This commit is contained in:
fullwall 2022-06-21 23:52:25 +08:00
parent cd652db2f7
commit 318596c715
17 changed files with 35 additions and 28 deletions

View File

@ -36,7 +36,7 @@
</repository> </repository>
<repository> <repository>
<id>placeholderapi</id> <id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url> <url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository> </repository>
<repository> <repository>
<id>sk89q-repo</id> <id>sk89q-repo</id>

View File

@ -86,8 +86,8 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
double dX = target.getX() - loc.getX(); double dX = target.getX() - loc.getX();
double dZ = target.getZ() - loc.getZ(); double dZ = target.getZ() - loc.getZ();
double dY = target.getY() - loc.getY(); double dY = target.getY() - loc.getY();
double xzDistance = dX * dX + dZ * dZ; double xzDistance = Math.sqrt(dX * dX + dZ * dZ);
if (Math.abs(dY) < 1 && Math.sqrt(xzDistance) <= parameters.distanceMargin()) { if (Math.abs(dY) < 1 && xzDistance <= parameters.distanceMargin()) {
stop(); stop();
return true; return true;
} }

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -16,7 +16,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -16,7 +16,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -110,14 +110,16 @@ public class PlayerMoveControl extends MoveControl {
double dX = this.tx - this.entity.getX(); double dX = this.tx - this.entity.getX();
double dZ = this.tz - this.entity.getZ(); double dZ = this.tz - this.entity.getZ();
double dY = this.ty - this.entity.getY(); double dY = this.ty - this.entity.getY();
double dXZ = dX * dX + dZ * dZ; double dXZ = Math.sqrt(dX * dX + dZ * dZ);
if (Math.abs(dY) < 1.0 && dXZ < 0.0075) { if (Math.abs(dY) < 1.0 && dXZ < 0.01) {
this.entity.zza = 0.0F; this.entity.zza = 0.0F;
return; return;
} }
float f = (float) (Mth.atan2(dZ, dX) * 57.2957763671875D) - 90.0F; if (dXZ > 0.4) {
this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); float f = (float) (Mth.atan2(dZ, dX) * 57.2957763671875D) - 90.0F;
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot()); this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F));
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot());
}
AttributeInstance speed = this.entity.getAttribute(Attributes.MOVEMENT_SPEED); AttributeInstance speed = this.entity.getAttribute(Attributes.MOVEMENT_SPEED);
float movement = (float) (this.speed * speed.getValue()); float movement = (float) (this.speed * speed.getValue());
this.entity.setSpeed(movement); this.entity.setSpeed(movement);

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -110,13 +110,15 @@ public class PlayerMoveControl extends MoveControl {
double dZ = this.tz - this.entity.getZ(); double dZ = this.tz - this.entity.getZ();
double dY = this.ty - this.entity.getY(); double dY = this.ty - this.entity.getY();
double dXZ = Math.sqrt(dX * dX + dZ * dZ); double dXZ = Math.sqrt(dX * dX + dZ * dZ);
if (Math.abs(dY) < 1.0 && dXZ < 0.09) { if (Math.abs(dY) < 1.0 && dXZ < 0.01) {
// this.entity.zza = 0.0F; // this.entity.zza = 0.0F;
return; return;
} }
float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F; if (dXZ > 0.4) {
this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F;
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot()); this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F));
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot());
}
float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue());
this.entity.setSpeed(movement); this.entity.setSpeed(movement);
this.entity.zza = movement; this.entity.zza = movement;

View File

@ -16,7 +16,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>

View File

@ -84,6 +84,7 @@ public class PlayerMoveControl extends MoveControl {
@Override @Override
public void setWantedPosition(double d0, double d1, double d2, double d3) { public void setWantedPosition(double d0, double d1, double d2, double d3) {
System.out.println("set pos: " + d0 + " " + d2);
this.tx = d0; this.tx = d0;
this.ty = d1; this.ty = d1;
this.tz = d2; this.tz = d2;
@ -110,13 +111,15 @@ public class PlayerMoveControl extends MoveControl {
double dZ = this.tz - this.entity.getZ(); double dZ = this.tz - this.entity.getZ();
double dY = this.ty - this.entity.getY(); double dY = this.ty - this.entity.getY();
double dXZ = Math.sqrt(dX * dX + dZ * dZ); double dXZ = Math.sqrt(dX * dX + dZ * dZ);
if (Math.abs(dY) < 1.0 && dXZ < 0.09) { if (Math.abs(dY) < 1.0 && dXZ < 0.01) {
// this.entity.zza = 0.0F; // this.entity.zza = 0.0F;
return; return;
} }
float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F; if (dXZ > 0.4) {
this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F;
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot()); this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F));
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot());
}
float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue());
this.entity.setSpeed(movement); this.entity.setSpeed(movement);
this.entity.zza = movement; this.entity.zza = movement;

View File

@ -147,7 +147,7 @@ public class PlayerNavigation extends PathNavigation {
} }
return true; return true;
} }
private boolean canWalkOn(int var0, int var1, int var2, int var3, int var4, int var5, Vec3 var6, double var7, private boolean canWalkOn(int var0, int var1, int var2, int var3, int var4, int var5, Vec3 var6, double var7,
double var9) { double var9) {
int var11 = var0 - var3 / 2; int var11 = var0 - var3 / 2;

View File

@ -18,7 +18,7 @@
<repositories> <repositories>
<repository> <repository>
<id>everything</id> <id>everything</id>
<url>http://repo.citizensnpcs.co</url> <url>https://repo.citizensnpcs.co</url>
</repository> </repository>
</repositories> </repositories>