mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-25 18:47:40 +01:00
Div by zero check for NMS#look in 1.18
This commit is contained in:
parent
89e06a3e67
commit
b31f1a351c
@ -697,6 +697,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
navigation.setSpeedModifier(params.speed());
|
||||
return navigation.isDone();
|
||||
}
|
||||
@ -922,9 +923,10 @@ public class NMSImpl implements NMSBridge {
|
||||
double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
|
||||
double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
|
||||
|
||||
double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ));
|
||||
double pitch = Math.toDegrees(Math.acos(yDiff / distanceY))
|
||||
- (handle.getBukkitEntity().getType() == EntityType.PHANTOM ? 45 : 90);
|
||||
double yaw = distanceXZ == 0 ? 0 : Math.toDegrees(Math.acos(xDiff / distanceXZ));
|
||||
double pitch = distanceY == 0 ? 0
|
||||
: Math.toDegrees(Math.acos(yDiff / distanceY))
|
||||
- (handle.getBukkitEntity().getType() == EntityType.PHANTOM ? 45 : 90);
|
||||
if (zDiff < 0.0)
|
||||
yaw += Math.abs(180 - yaw) * 2;
|
||||
if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) {
|
||||
|
@ -21,53 +21,6 @@ public class PlayerLookControl {
|
||||
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) {
|
||||
this.a(var0, var2, var4, 10, 40);
|
||||
}
|
||||
@ -133,6 +86,53 @@ public class PlayerLookControl {
|
||||
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) {
|
||||
return var0 instanceof LivingEntity ? var0.getY() + var0.getEyeY()
|
||||
: (var0.getBoundingBox().minY + var0.getBoundingBox().maxY) / 2.0D;
|
||||
|
@ -111,7 +111,7 @@ public class PlayerMoveControl extends MoveControl {
|
||||
double dZ = this.tz - this.entity.getZ();
|
||||
double dY = this.ty - this.entity.getY();
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import net.minecraft.world.level.pathfinder.BlockPathTypes;
|
||||
import net.minecraft.world.level.pathfinder.Node;
|
||||
import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
||||
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.WalkNodeEvaluator;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
@ -134,7 +133,7 @@ public class PlayerNavigation extends PathNavigation {
|
||||
protected boolean canUpdatePath() {
|
||||
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,
|
||||
double var9) {
|
||||
for (BlockPos var12 : BlockPos.betweenClosed(new BlockPos(var0, var1, var2),
|
||||
@ -148,7 +147,7 @@ public class PlayerNavigation extends PathNavigation {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean canWalkOn(int var0, int var1, int var2, int var3, int var4, int var5, Vec3 var6, double var7,
|
||||
double var9) {
|
||||
int var11 = var0 - var3 / 2;
|
||||
@ -176,7 +175,7 @@ public class PlayerNavigation extends PathNavigation {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public Path createPath(BlockPos var0, int var1) {
|
||||
|
Loading…
Reference in New Issue
Block a user