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
|
2024-04-28 03:00:01 +02:00
|
|
|
index 541debdee83cbef985aafa0c3cb344a5bee18625..5f9c39b18ab55c80e78ac578de6821fe282c04bb 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
|
2024-04-28 03:00:01 +02:00
|
|
|
@@ -3720,7 +3720,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
|
|
|
|
2024-01-23 15:43:48 +01:00
|
|
|
- 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;
|
2021-06-15 06:55:46 +02:00
|
|
|
+ // Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists
|
2024-01-23 15:43:48 +01:00
|
|
|
+ return vec3d1.distanceToSqr(vec3d) > 128.0D * 128.0D ? false : this.level().clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS; // Paper - Perf: Use distance squared
|
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
|
2024-04-24 16:29:12 +02:00
|
|
|
index 1e720b96f0367652db6924b8654deaa9467e3d2c..4932ba59a6b70b405f7dd05358f6bb00b629d34c 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
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
@@ -516,5 +516,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
|
|
|
|
+ }
|
|
|
|
+
|
2023-12-06 20:40:37 +01:00
|
|
|
+ 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, net.minecraft.world.phys.shapes.CollisionContext.empty())).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
|
2024-04-25 18:42:50 +02:00
|
|
|
index 2701e53086f4be07c341cd1e4fcd7a351e77c486..1cfc3d18fb785410f5acfcf3c338776858efe25a 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
|
2024-04-24 16:29:12 +02:00
|
|
|
@@ -627,6 +627,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();
|