From d81fd123cec8be263a3ea1cdd371044bb1ac8969 Mon Sep 17 00:00:00 2001 From: Xemorr <31805746+Xemorr@users.noreply.github.com> Date: Wed, 7 Jul 2021 20:58:54 +0100 Subject: [PATCH] Swapped out Vec3#distanceTo call with a Vec3#distanceToSqr call to remove calls to Math.sqrt --- ...sight-methods.patch => Line-Of-Sight-Changes.patch} | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) rename patches/server/{Add-more-line-of-sight-methods.patch => Line-Of-Sight-Changes.patch} (87%) diff --git a/patches/server/Add-more-line-of-sight-methods.patch b/patches/server/Line-Of-Sight-Changes.patch similarity index 87% rename from patches/server/Add-more-line-of-sight-methods.patch rename to patches/server/Line-Of-Sight-Changes.patch index 416e08904a..b83f12a5f0 100644 --- a/patches/server/Add-more-line-of-sight-methods.patch +++ b/patches/server/Line-Of-Sight-Changes.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: TwoLeggedCat <80929284+TwoLeggedCat@users.noreply.github.com> Date: Sat, 29 May 2021 14:33:25 -0500 -Subject: [PATCH] Add more line of sight methods +Subject: [PATCH] Line Of Sight Changes diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -12,10 +12,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 Vec3 vec3d = new Vec3(this.getX(), this.getEyeY(), this.getZ()); Vec3 vec3d1 = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ()); +- return vec3d1.distanceTo(vec3d) > 128.0D ? false : this.level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS; + // Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists - return vec3d1.distanceTo(vec3d) > 128.0D ? false : this.level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS; ++ return vec3d1.distanceToSqr(vec3d) > 128D * 128D ? false : this.level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS; // Paper - use distanceToSqr } } + diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -32,7 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (from.getWorld() != to.getWorld()) return false; + Vec3 vec3d = new Vec3(from.getX(), from.getY(), from.getZ()); + Vec3 vec3d1 = new Vec3(to.getX(), to.getY(), to.getZ()); -+ if (vec3d1.distanceTo(vec3d) > 128.0D) return false; ++ if (vec3d1.distanceToSqr(vec3d) > 128D * 128D) return false; //Return early if the distance is greater than 128 blocks + + return this.getHandle().clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)).getType() == HitResult.Type.MISS; + } @@ -63,7 +65,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.getHandle().level != ((CraftWorld) loc.getWorld()).getHandle()) return false; + Vec3 vec3d = new Vec3(this.getHandle().getX(), this.getHandle().getEyeY(), this.getHandle().getZ()); + Vec3 vec3d1 = new Vec3(loc.getX(), loc.getY(), loc.getZ()); -+ if (vec3d1.distanceTo(vec3d) > 128.0D) return false; ++ if (vec3d1.distanceToSqr(vec3d) > 128D * 128D) return false; //Return early if the distance is greater than 128 blocks + + return this.getHandle().level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this.getHandle())).getType() == HitResult.Type.MISS; + }