/** * Gets all the entities that are in the line of sight of the given entity, * up to a given distance. This ignores occluders like blocks or other * entities. That is to say, the returned entities might not actually be * visible. Only the entities that pass the filter test are added. * * @param looker The looking entity * @param distance The distance of the ray (from the start) * @param filter The filter test * @return The intersecting entities in no particular order, with the * associated intersection point and normal */ default Set<EntityHit> getIntersectingEntities(Entity looker, double distance, Predicate<EntityHit> filter) { checkNotNull(looker, "looker"); final Vector3d rotation = looker.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Optional<EyeLocationProperty> data = looker.getProperty(EyeLocationProperty.class); final Vector3d start = data.map(EyeLocationProperty::getValue).orElse(looker.getLocation().getPosition()); return getIntersectingEntities(start, direction, distance, filter); }
/** * Initializes a block ray builder for the entity's eye. * If the eye location isn't defined for the entity, the * regular location is used. This sets both the starting * point and direction. * * @param entity The entity * @return A new block ray builder */ public static BlockRayBuilder<World> from(Entity entity) { checkNotNull(entity, "entity"); final Vector3d rotation = entity.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Location<World> location = entity.getLocation(); final Optional<EyeLocationProperty> data = entity.getProperty(EyeLocationProperty.class); final Vector3d position = data.map(EyeLocationProperty::getValue).orElse(location.getPosition()); return from(location.getExtent(), position).direction(direction); }
/** * Gets all the entities that are in the line of sight of the given entity, * up to a given distance. This ignores occluders like blocks or other * entities. That is to say, the returned entities might not actually be * visible. Only the entities that pass the filter test are added. * * @param looker The looking entity * @param distance The distance of the ray (from the start) * @param filter The filter test * @return The intersecting entities in no particular order, with the * associated intersection point and normal */ default Set<EntityHit> getIntersectingEntities(Entity looker, double distance, Predicate<EntityHit> filter) { checkNotNull(looker, "looker"); final Vector3d rotation = looker.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Optional<EyeLocationProperty> data = looker.getProperty(EyeLocationProperty.class); final Vector3d start = data.map(EyeLocationProperty::getValue).orElse(looker.getLocation().getPosition()); return getIntersectingEntities(start, direction, distance, filter); }
/** * Initializes a block ray builder for the entity's eye. * If the eye location isn't defined for the entity, the * regular location is used. This sets both the starting * point and direction. * * @param entity The entity * @return A new block ray builder */ public static BlockRayBuilder<World> from(Entity entity) { checkNotNull(entity, "entity"); final Vector3d rotation = entity.getRotation(); final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); final Location<World> location = entity.getLocation(); final Optional<EyeLocationProperty> data = entity.getProperty(EyeLocationProperty.class); final Vector3d position = data.map(EyeLocationProperty::getValue).orElse(location.getPosition()); return from(location.getExtent(), position).direction(direction); }