Line Of Sight Changes

This commit is contained in:
TwoLeggedCat
2021-05-29 14:33:25 -05:00
parent c002a90053
commit 750a4590ce
3 changed files with 89 additions and 40 deletions

View File

@@ -643,6 +643,23 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return this.getHandle().hasLineOfSight(((CraftEntity) other).getHandle());
}
// Paper start
@Override
public boolean hasLineOfSight(Location loc) {
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
}
return this.getHandle().level().clipDirect(start, end, net.minecraft.world.phys.shapes.CollisionContext.of(this.getHandle())) == net.minecraft.world.phys.HitResult.Type.MISS;
}
// Paper end
@Override
public boolean getRemoveWhenFarAway() {
return this.getHandle() instanceof Mob && !((Mob) this.getHandle()).isPersistenceRequired();