Fix target location for mc navigator

This commit is contained in:
fullwall 2021-06-29 00:10:24 +08:00
parent 9c8d26e73b
commit 5306a68b6a
5 changed files with 42 additions and 40 deletions

View File

@ -137,7 +137,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
Location currLoc = npc.getEntity().getLocation(NPC_LOCATION); Location currLoc = npc.getEntity().getLocation(NPC_LOCATION);
Vector destVector = new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5); Vector destVector = new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5);
/* Proper door movement - gets stuck on corners at times /* Proper door movement - gets stuck on corners at times
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) { if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData(); Door door = (Door) block.getState().getData();

View File

@ -12,6 +12,7 @@ import net.citizensnpcs.api.ai.AbstractPathStrategy;
import net.citizensnpcs.api.ai.NavigatorParameters; import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.ai.TargetType; import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.api.ai.event.CancelReason; import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
@ -32,6 +33,9 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
MCNavigationStrategy(final NPC npc, Location dest, NavigatorParameters params) { MCNavigationStrategy(final NPC npc, Location dest, NavigatorParameters params) {
super(TargetType.LOCATION); super(TargetType.LOCATION);
if (!MinecraftBlockExaminer.canStandIn(dest.getBlock().getType())) {
dest = MinecraftBlockExaminer.findValidLocationAbove(dest, 2);
}
this.target = dest; this.target = dest;
this.parameters = params; this.parameters = params;
handle = npc.getEntity(); handle = npc.getEntity();

View File

@ -311,7 +311,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
if (event.getClickedBlock() == null) if (event.getClickedBlock() == null)
return; return;
event.setCancelled(true); event.setCancelled(true);
Location at = event.getClickedBlock().getLocation(); Location at = event.getClickedBlock().getLocation().add(0, 1, 0);
Location prev = getLastWaypoint(); Location prev = getLastWaypoint();
if (prev != null && prev.getWorld() == at.getWorld()) { if (prev != null && prev.getWorld() == at.getWorld()) {
@ -327,7 +327,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
Waypoint element = new Waypoint(at); Waypoint element = new Waypoint(at);
waypoints.add(element); waypoints.add(element);
if (showingMarkers) { if (showingMarkers) {
markers.createMarker(element, element.getLocation().clone().add(0, 1, 0)); markers.createMarker(element, element.getLocation().clone());
} }
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at), Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at),
waypoints.size()); waypoints.size());

View File

@ -9,7 +9,7 @@ import net.minecraft.world.phys.Vec3;
public class PlayerLookControl { public class PlayerLookControl {
private final EntityHumanNPC a; private final EntityHumanNPC a;
private final PlayerBodyControl control; private final PlayerBodyControl control;
protected boolean move; protected boolean looking;
protected float tpitch; protected float tpitch;
protected double tx; protected double tx;
protected double ty; protected double ty;
@ -27,8 +27,8 @@ public class PlayerLookControl {
if (this.b()) { if (this.b()) {
// this.a.setXRot(0.0F); // this.a.setXRot(0.0F);
} }
if (this.move) { if (this.looking) {
this.move = false; this.looking = false;
this.a.setXRot(this.rotateTowards(this.a.getXRot(), this.g(), this.tpitch)); this.a.setXRot(this.rotateTowards(this.a.getXRot(), this.g(), this.tpitch));
this.a.yHeadRot = this.rotateTowards(this.a.yHeadRot, this.h(), this.tyaw); this.a.yHeadRot = this.rotateTowards(this.a.yHeadRot, this.h(), this.tyaw);
while (this.a.yHeadRot >= 180F) { while (this.a.yHeadRot >= 180F) {
@ -61,8 +61,7 @@ public class PlayerLookControl {
} }
// this.a.setYRot(this.a(this.a.yHeadRot, this.h(), this.b)); // this.a.setYRot(this.a(this.a.yHeadRot, this.h(), this.b));
} else { } else {
// this.a.setYRot(MathHelper.b(this.a.getYRot(), this.a.yHeadRot, 40F)); // this.a.yHeadRot = rotateTowards(this.a.yHeadRot, this.a.yBodyRot, 10.0F);
// this.a.aK = this.a(this.a.yHeadRot, this.a.aA, 10.0F);
} }
if (!this.a.getNavigation().isDone()) { // TODO: use Citizens AI? if (!this.a.getNavigation().isDone()) { // TODO: use Citizens AI?
this.a.yHeadRot = Mth.rotateIfNecessary(this.a.yHeadRot, this.a.yBodyRot, 75); this.a.yHeadRot = Mth.rotateIfNecessary(this.a.yHeadRot, this.a.yBodyRot, 75);
@ -83,7 +82,7 @@ public class PlayerLookControl {
this.tz = var4; this.tz = var4;
this.tyaw = var6; this.tyaw = var6;
this.tpitch = var7; this.tpitch = var7;
this.move = true; this.looking = true;
} }
public void a(Entity var0, float var1, float var2) { public void a(Entity var0, float var1, float var2) {
@ -99,7 +98,7 @@ public class PlayerLookControl {
} }
public boolean c() { public boolean c() {
return this.move; return this.looking;
} }
public double d() { public double d() {

View File

@ -15,20 +15,20 @@ import net.minecraft.world.entity.monster.Slime;
public class PlayerMoveControl extends MoveControl { public class PlayerMoveControl extends MoveControl {
protected LivingEntity a; protected LivingEntity a;
protected double b;
protected double c;
protected double d;
protected double e;
protected boolean f;
private int h; private int h;
protected boolean moving;
protected double speed;
protected double tx;
protected double ty;
protected double tz;
public PlayerMoveControl(LivingEntity entityinsentient) { public PlayerMoveControl(LivingEntity entityinsentient) {
super(entityinsentient instanceof Mob ? (Mob) entityinsentient super(entityinsentient instanceof Mob ? (Mob) entityinsentient
: new Slime(EntityType.SLIME, entityinsentient.level)); : new Slime(EntityType.SLIME, entityinsentient.level));
this.a = entityinsentient; this.a = entityinsentient;
this.b = entityinsentient.getX(); this.tx = entityinsentient.getX();
this.c = entityinsentient.getY(); this.ty = entityinsentient.getY();
this.d = entityinsentient.getZ(); this.tz = entityinsentient.getZ();
} }
protected int cg() { protected int cg() {
@ -37,27 +37,27 @@ public class PlayerMoveControl extends MoveControl {
@Override @Override
public double getSpeedModifier() { public double getSpeedModifier() {
return this.e; return this.speed;
} }
@Override @Override
public double getWantedX() { public double getWantedX() {
return this.b; return this.tx;
} }
@Override @Override
public double getWantedY() { public double getWantedY() {
return this.c; return this.ty;
} }
@Override @Override
public double getWantedZ() { public double getWantedZ() {
return this.d; return this.tz;
} }
@Override @Override
public boolean hasWanted() { public boolean hasWanted() {
return this.f; return this.moving;
} }
@Override @Override
@ -85,11 +85,11 @@ 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) {
this.b = d0; this.tx = d0;
this.c = d1; this.ty = d1;
this.d = d2; this.tz = d2;
this.e = d3; this.speed = d3;
this.f = true; this.moving = true;
} }
private boolean shouldSlimeJump() { private boolean shouldSlimeJump() {
@ -105,26 +105,25 @@ public class PlayerMoveControl extends MoveControl {
@Override @Override
public void tick() { public void tick() {
this.a.zza = 0; this.a.zza = 0;
if (this.f) { if (this.moving) {
this.f = false; this.moving = false;
int i = Mth.floor(this.a.getBoundingBox().minY + 0.5D); double dX = this.tx - this.a.getX();
double d0 = this.b - this.a.getX(); double dZ = this.tz - this.a.getZ();
double d1 = this.d - this.a.getZ(); double dY = this.ty - this.a.getY();
double d2 = this.c - i; double dXZ = dY * dY + dZ * dZ;
double d3 = d0 * d0 + d2 * d2 + d1 * d1; if (dY * dY < 1.0 && dXZ < 2.500000277905201E-007D) {
if (d3 < 2.500000277905201E-007D) {
this.a.zza = 0.0F; this.a.zza = 0.0F;
return; return;
} }
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F; float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F;
this.a.setYRot(rotlerp(this.a.getYRot(), f, 90.0F)); this.a.setYRot(rotlerp(this.a.getYRot(), f, 90.0F));
NMS.setHeadYaw(a.getBukkitEntity(), this.a.getYRot()); NMS.setHeadYaw(a.getBukkitEntity(), this.a.getYRot());
AttributeInstance speed = this.a.getAttribute(Attributes.MOVEMENT_SPEED); AttributeInstance speed = this.a.getAttribute(Attributes.MOVEMENT_SPEED);
speed.setBaseValue(0.3D * this.e); speed.setBaseValue(0.3D * this.speed);
float movement = (float) (this.e * speed.getValue()); float movement = (float) (this.speed * speed.getValue());
this.a.setSpeed(movement); this.a.setSpeed(movement);
this.a.zza = movement; this.a.zza = movement;
if (shouldSlimeJump() || (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D)) { if (shouldSlimeJump() || (dY >= NMS.getStepHeight(a.getBukkitEntity()) && dXZ < 1.0D)) {
this.h = cg(); this.h = cg();
this.h /= 3; this.h /= 3;
if (this.a instanceof EntityHumanNPC) { if (this.a instanceof EntityHumanNPC) {