mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 02:55:47 +01:00
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
63 lines
3.6 KiB
Diff
63 lines
3.6 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/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
index 37787a725725d22b0870dcab0f3bec8b94cfd130..79b43b1b0f8e223f256c2aaec1925426931a9a54 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -3091,6 +3091,7 @@ public abstract class LivingEntity extends Entity {
|
|
Vec3 vec3d = new Vec3(this.getX(), this.getEyeY(), this.getZ());
|
|
Vec3 vec3d1 = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ());
|
|
|
|
+ // Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists
|
|
return this.level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS;
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 1c9321cef1a05c5e8a22dd52bc63a5103eaf7311..312ed9c693cc5108d51ad90e15d6be4bb21904e1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -315,6 +315,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;
|
|
+ Vec3 vec3d = new Vec3(from.getX(), from.getY(), from.getZ());
|
|
+ Vec3 vec3d1 = new Vec3(to.getX(), to.getY(), to.getZ());
|
|
+
|
|
+ return this.getHandle().clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)).getType() == HitResult.Type.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 25ba7a26c951fc5e4638bdb0db36e94d3e08fb2e..cd42edd8f36cea3acad76974c39eb0cd1585f73d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
@@ -549,6 +549,17 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|
return getHandle().canSee(((CraftEntity) other).getHandle());
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public boolean hasLineOfSight(Location loc) {
|
|
+ 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());
|
|
+
|
|
+ return this.getHandle().level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this.getHandle())).getType() == HitResult.Type.MISS;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public boolean getRemoveWhenFarAway() {
|
|
return getHandle() instanceof Mob && !((Mob) getHandle()).persistenceRequired;
|