Paper/patches/server-unmapped/0757-Add-more-line-of-sight-methods.patch
2021-06-11 14:02:28 +02:00

63 Zeilen
3.7 KiB
Diff

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
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
index 2657dd71213455e2da3a4ff4d338a33896ffe855..b7b07b652b29e6f84f87fc92add99ce68f8bbd09 100644
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
@@ -3094,6 +3094,7 @@ public abstract class EntityLiving extends Entity {
Vec3D vec3d = new Vec3D(this.locX(), this.getHeadY(), this.locZ());
Vec3D vec3d1 = new Vec3D(entity.locX(), entity.getHeadY(), entity.locZ());
+ // Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists
return this.world.rayTrace(new RayTrace(vec3d, vec3d1, RayTrace.BlockCollisionOption.COLLIDER, RayTrace.FluidCollisionOption.NONE, this)).getType() == MovingObjectPosition.EnumMovingObjectType.MISS;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 9d858f91828d6c2787ff1dc677a247bcab172701..02198dbe9e80c2990e8a09b2b763748dae727a03 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -333,6 +333,17 @@ public class CraftWorld implements World {
public io.papermc.paper.world.MoonPhase getMoonPhase() {
return io.papermc.paper.world.MoonPhase.getPhase(getFullTime() / 24000L);
}
+
+ @Override
+ public boolean lineOfSightExists(Location from, Location to) {
+ Validate.notNull(from, "from parameter in lineOfSightExists cannot be null");
+ Validate.notNull(to, "to parameter in lineOfSightExists cannot be null");
+ if (from.getWorld() != to.getWorld()) return false;
+ Vec3D vec3d = new Vec3D(from.getX(), from.getY(), from.getZ());
+ Vec3D vec3d1 = new Vec3D(to.getX(), to.getY(), to.getZ());
+
+ return this.getHandle().rayTrace(new RayTrace(vec3d, vec3d1, RayTrace.BlockCollisionOption.COLLIDER, RayTrace.FluidCollisionOption.NONE, null)).getType() == MovingObjectPosition.EnumMovingObjectType.MISS;
+ }
// Paper end
private static final Random rand = new Random();
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 32428b1260bbc4bae67ec74969c67f71272de418..592dacf8cc924caac339a8810ba5b0d85448ed90 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -561,6 +561,17 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return getHandle().hasLineOfSight(((CraftEntity) other).getHandle());
}
+ // Paper start
+ @Override
+ public boolean hasLineOfSight(Location loc) {
+ if (this.getHandle().world != ((CraftWorld) loc.getWorld()).getHandle()) return false;
+ Vec3D vec3d = new Vec3D(this.getHandle().locX(), this.getHandle().getHeadY(), this.getHandle().locZ());
+ Vec3D vec3d1 = new Vec3D(loc.getX(), loc.getY(), loc.getZ());
+
+ return this.getHandle().world.rayTrace(new RayTrace(vec3d, vec3d1, RayTrace.BlockCollisionOption.COLLIDER, RayTrace.FluidCollisionOption.NONE, this.getHandle())).getType() == MovingObjectPosition.EnumMovingObjectType.MISS;
+ }
+ // Paper end
+
@Override
public boolean getRemoveWhenFarAway() {
return getHandle() instanceof EntityInsentient && !((EntityInsentient) getHandle()).persistent;