2021-06-11 14:02:28 +02:00
|
|
|
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
|
2021-07-07 21:58:54 +02:00
|
|
|
Subject: [PATCH] Line Of Sight Changes
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2023-12-06 04:57:46 +01:00
|
|
|
index d6b80be711b11758ef0bb3187dbcb6e597ef35d3..4a11bf06a725a5c1927e24ac4ad066f7631a430a 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2023-12-06 04:57:46 +01:00
|
|
|
@@ -3606,7 +3606,8 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2021-06-15 06:55:46 +02:00
|
|
|
Vec3 vec3d = new Vec3(this.getX(), this.getEyeY(), this.getZ());
|
|
|
|
Vec3 vec3d1 = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ());
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2023-09-10 04:28:03 +02:00
|
|
|
- return vec3d1.distanceTo(vec3d) > 128.0D ? false : this.level().clipDirect(vec3d, vec3d1, net.minecraft.world.phys.shapes.CollisionContext.of(this)) == HitResult.Type.MISS; // Paper
|
2021-06-15 06:55:46 +02:00
|
|
|
+ // Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists
|
2023-09-12 01:56:24 +02:00
|
|
|
+ return vec3d1.distanceToSqr(vec3d) > 128.0D * 128.0D ? false : this.level().clipDirect(vec3d, vec3d1, net.minecraft.world.phys.shapes.CollisionContext.of(this)) == HitResult.Type.MISS; // Paper
|
2021-06-15 06:55:46 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2021-07-07 21:58:54 +02:00
|
|
|
|
2022-06-05 22:51:44 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
2023-12-06 04:57:46 +01:00
|
|
|
index 29369cab2ccdd1d43fc67dbe2e666e477f96b26d..a31df5b8de2a18ad08f1c38fb2ccf7a1f8c9e5e8 100644
|
2022-06-05 22:51:44 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
2023-12-06 04:57:46 +01:00
|
|
|
@@ -1027,5 +1027,21 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
2022-06-05 22:51:44 +02:00
|
|
|
public org.bukkit.NamespacedKey getKey() {
|
|
|
|
return org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.getHandle().getLevel().dimension().location());
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public boolean lineOfSightExists(Location from, Location to) {
|
2022-06-05 22:51:44 +02:00
|
|
|
+ Preconditions.checkArgument(from != null, "from parameter in lineOfSightExists cannot be null");
|
|
|
|
+ Preconditions.checkArgument(to != null, "to parameter in lineOfSightExists cannot be null");
|
2023-09-10 04:28:03 +02:00
|
|
|
+ if (from.getWorld() != to.getWorld()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
2023-09-10 04:28:03 +02:00
|
|
|
+ net.minecraft.world.phys.Vec3 start = new net.minecraft.world.phys.Vec3(from.getX(), from.getY(), from.getZ());
|
|
|
|
+ net.minecraft.world.phys.Vec3 end = new net.minecraft.world.phys.Vec3(to.getX(), to.getY(), to.getZ());
|
|
|
|
+ if (end.distanceToSqr(start) > 128D * 128D) {
|
|
|
|
+ return false; // Return early if the distance is greater than 128 blocks
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return this.getHandle().clip(new net.minecraft.world.level.ClipContext(start, end, net.minecraft.world.level.ClipContext.Block.COLLIDER, net.minecraft.world.level.ClipContext.Fluid.NONE, null)).getType() == net.minecraft.world.phys.HitResult.Type.MISS;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
// Paper end
|
2022-06-05 22:51:44 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2023-12-06 04:57:46 +01:00
|
|
|
index d54a67c9942b986adc9e0a06640c90d99bdcdada..72fd16ad8bc08dd3189e56d504000453a8d5cd92 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2023-12-06 04:57:46 +01:00
|
|
|
@@ -588,6 +588,23 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
2021-06-15 06:55:46 +02:00
|
|
|
return this.getHandle().hasLineOfSight(((CraftEntity) other).getHandle());
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public boolean hasLineOfSight(Location loc) {
|
2023-09-10 04:28:03 +02:00
|
|
|
+ if (this.getHandle().level() != ((CraftWorld) loc.getWorld()).getHandle()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ net.minecraft.world.phys.Vec3 start = new net.minecraft.world.phys.Vec3(this.getHandle().getX(), this.getHandle().getEyeY(), this.getHandle().getZ());
|
|
|
|
+ net.minecraft.world.phys.Vec3 end = new net.minecraft.world.phys.Vec3(loc.getX(), loc.getY(), loc.getZ());
|
|
|
|
+ if (end.distanceToSqr(start) > 128D * 128D) {
|
|
|
|
+ return false; // Return early if the distance is greater than 128 blocks
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
2023-09-10 04:28:03 +02:00
|
|
|
+ return this.getHandle().level().clipDirect(start, end, net.minecraft.world.phys.shapes.CollisionContext.of(this.getHandle())) == net.minecraft.world.phys.HitResult.Type.MISS;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public boolean getRemoveWhenFarAway() {
|
2021-07-22 20:11:56 +02:00
|
|
|
return this.getHandle() instanceof Mob && !((Mob) this.getHandle()).isPersistenceRequired();
|