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);
Vector destVector = new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5);
/* Proper door movement - gets stuck on corners at times
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) {
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.TargetType;
import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS;
@ -32,6 +33,9 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
MCNavigationStrategy(final NPC npc, Location dest, NavigatorParameters params) {
super(TargetType.LOCATION);
if (!MinecraftBlockExaminer.canStandIn(dest.getBlock().getType())) {
dest = MinecraftBlockExaminer.findValidLocationAbove(dest, 2);
}
this.target = dest;
this.parameters = params;
handle = npc.getEntity();

View File

@ -311,7 +311,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
if (event.getClickedBlock() == null)
return;
event.setCancelled(true);
Location at = event.getClickedBlock().getLocation();
Location at = event.getClickedBlock().getLocation().add(0, 1, 0);
Location prev = getLastWaypoint();
if (prev != null && prev.getWorld() == at.getWorld()) {
@ -327,7 +327,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
Waypoint element = new Waypoint(at);
waypoints.add(element);
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),
waypoints.size());

View File

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

View File

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