Div by zero check for NMS#look in 1.18

This commit is contained in:
fullwall 2022-02-28 16:59:15 +08:00
parent 89e06a3e67
commit b31f1a351c
4 changed files with 56 additions and 55 deletions

View File

@ -697,6 +697,7 @@ public class NMSImpl implements NMSBridge {
} }
} }
} }
navigation.setSpeedModifier(params.speed()); navigation.setSpeedModifier(params.speed());
return navigation.isDone(); return navigation.isDone();
} }
@ -922,9 +923,10 @@ public class NMSImpl implements NMSBridge {
double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff); double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff); double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ)); double yaw = distanceXZ == 0 ? 0 : Math.toDegrees(Math.acos(xDiff / distanceXZ));
double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) double pitch = distanceY == 0 ? 0
- (handle.getBukkitEntity().getType() == EntityType.PHANTOM ? 45 : 90); : Math.toDegrees(Math.acos(yDiff / distanceY))
- (handle.getBukkitEntity().getType() == EntityType.PHANTOM ? 45 : 90);
if (zDiff < 0.0) if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2; yaw += Math.abs(180 - yaw) * 2;
if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) { if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) {

View File

@ -21,53 +21,6 @@ public class PlayerLookControl {
this.control = new PlayerBodyControl(this.a); this.control = new PlayerBodyControl(this.a);
} }
public void tick() {
if (!this.a.getNavigation().isDone()) {
// TODO: use Citizens AI?
// this.a.yHeadRot = Mth.rotateIfNecessary(this.a.yHeadRot, this.a.yBodyRot, 75);
return;
}
if (this.b()) {
// this.a.setXRot(0.0F);
}
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) {
this.a.yHeadRot -= 360F;
}
while (this.a.yHeadRot < -180F) {
this.a.yHeadRot += 360F;
}
double d = this.a.yHeadRot - 40;
while (d >= 180F) {
d -= 360F;
}
while (d < -180F) {
d += 360F;
}
if (d > this.a.getYRot()) {
this.a.setYRot((float) d);
}
if (d != this.a.getYRot()) {
d = this.a.yHeadRot + 40;
while (d >= 180F) {
d -= 360F;
}
while (d < -180F) {
d += 360F;
}
if (d < this.a.getYRot()) {
this.a.setYRot((float) d);
}
}
// this.a.setYRot(this.a(this.a.yHeadRot, this.h(), this.b));
} else {
// this.a.yHeadRot = rotateTowards(this.a.yHeadRot, this.a.yBodyRot, 10.0F);
}
}
public void a(double var0, double var2, double var4) { public void a(double var0, double var2, double var4) {
this.a(var0, var2, var4, 10, 40); this.a(var0, var2, var4, 10, 40);
} }
@ -133,6 +86,53 @@ public class PlayerLookControl {
return var0 + var4; return var0 + var4;
} }
public void tick() {
if (!this.a.getNavigation().isDone()) {
// TODO: use Citizens AI?
// this.a.yHeadRot = Mth.rotateIfNecessary(this.a.yHeadRot, this.a.yBodyRot, 75);
return;
}
if (this.b()) {
// this.a.setXRot(0.0F);
}
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) {
this.a.yHeadRot -= 360F;
}
while (this.a.yHeadRot < -180F) {
this.a.yHeadRot += 360F;
}
double d = this.a.yHeadRot - 40;
while (d >= 180F) {
d -= 360F;
}
while (d < -180F) {
d += 360F;
}
if (d > this.a.getYRot()) {
this.a.setYRot((float) d);
}
if (d != this.a.getYRot()) {
d = this.a.yHeadRot + 40;
while (d >= 180F) {
d -= 360F;
}
while (d < -180F) {
d += 360F;
}
if (d < this.a.getYRot()) {
this.a.setYRot((float) d);
}
}
// this.a.setYRot(this.a(this.a.yHeadRot, this.h(), this.b));
} else {
// this.a.yHeadRot = rotateTowards(this.a.yHeadRot, this.a.yBodyRot, 10.0F);
}
}
private static double b(Entity var0) { private static double b(Entity var0) {
return var0 instanceof LivingEntity ? var0.getY() + var0.getEyeY() return var0 instanceof LivingEntity ? var0.getY() + var0.getEyeY()
: (var0.getBoundingBox().minY + var0.getBoundingBox().maxY) / 2.0D; : (var0.getBoundingBox().minY + var0.getBoundingBox().maxY) / 2.0D;

View File

@ -111,7 +111,7 @@ 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.025) { if (Math.abs(dY) < 1.0 && dXZ <= 0.025) {
// this.entity.zza = 0.0F; // this.entity.zza = 0.0F;
return; return;
} }

View File

@ -25,7 +25,6 @@ import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.level.pathfinder.Node; import net.minecraft.world.level.pathfinder.Node;
import net.minecraft.world.level.pathfinder.NodeEvaluator; import net.minecraft.world.level.pathfinder.NodeEvaluator;
import net.minecraft.world.level.pathfinder.Path; import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.pathfinder.PathFinder; import net.minecraft.world.level.pathfinder.PathFinder;
import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; import net.minecraft.world.level.pathfinder.WalkNodeEvaluator;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -134,7 +133,7 @@ public class PlayerNavigation extends PathNavigation {
protected boolean canUpdatePath() { protected boolean canUpdatePath() {
return (this.mob.isOnGround() || isInLiquid() || this.mob.isPassenger()); return (this.mob.isOnGround() || isInLiquid() || this.mob.isPassenger());
} }
/*
private boolean canWalkAbove(int var0, int var1, int var2, int var3, int var4, int var5, Vec3 var6, double var7, private boolean canWalkAbove(int var0, int var1, int var2, int var3, int var4, int var5, Vec3 var6, double var7,
double var9) { double var9) {
for (BlockPos var12 : BlockPos.betweenClosed(new BlockPos(var0, var1, var2), for (BlockPos var12 : BlockPos.betweenClosed(new BlockPos(var0, var1, var2),
@ -148,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;
@ -176,7 +175,7 @@ public class PlayerNavigation extends PathNavigation {
} }
} }
return true; return true;
} }*/
@Override @Override
public Path createPath(BlockPos var0, int var1) { public Path createPath(BlockPos var0, int var1) {