/** * Return a collection of entities contained within {@code distance} blocks * of the specified location. This uses a sphere to test distances. * * <p>For world implementations, only some parts of the world is usually * loaded, so this method will only return entities within those loaded * parts.</p> * * @param location The location at the center of the search radius * @param distance The search radius * @return A collection of nearby entities */ default Collection<Entity> getNearbyEntities(Vector3d location, double distance) { checkNotNull(location, "location"); checkArgument(distance > 0, "distance must be > 0"); return this.getIntersectingEntities(new AABB(location.getX() - distance, location.getY() - distance, location.getZ() - distance, location.getX() + distance, location.getY() + distance, location.getZ() + distance), entity -> entity.getLocation().getPosition().distanceSquared(location) <= distance * distance); }
if (this.distanceLimit >= 0 && this.position.distanceSquared(hit.getPosition()) > this.distanceLimit * this.distanceLimit) { throw new NoSuchElementException("Distance limit reached");
public double distanceSquared(float x, float y, float z) { return distanceSquared((double) x, (double) y, (double) z); }
boolean canPlaceFootprint(Vector3d currentPosition) { return position.distanceSquared(currentPosition) > 1; } }
public double distanceSquared(Vector3d v) { return distanceSquared(v.x, v.y, v.z); }
public double distanceSquared(float x, float y, float z) { return distanceSquared((double) x, (double) y, (double) z); }
public double distanceSquared(Vector3d v) { return distanceSquared(v.x, v.y, v.z); }
public double distance(double x, double y, double z) { return (double) Math.sqrt(distanceSquared(x, y, z)); }
public double distance(double x, double y, double z) { return (double) Math.sqrt(distanceSquared(x, y, z)); }
public static double getDistanceSquared(Location<World> location1, Location<World> location2) { if(!location1.getExtent().equals(location2.getExtent())) { return Integer.MAX_VALUE; } else { return location1.getPosition().distanceSquared(location2.getPosition()); } }
private boolean hasSign(Location<World> location, List<Location<World>> searched, Location<World> original) { boolean found = false; for (Direction face : BlockUtil.getDirectFaces()) { Location<World> otherBlock = location.getRelative(face); if (searched.contains(otherBlock)) continue; searched.add(otherBlock); if (found) break; if (location.getPosition().distanceSquared(original.getPosition()) > Math.pow(maxSignDistance.getValue(), 2)) continue; if (SignUtil.isSign(otherBlock) && SignUtil.getFront(otherBlock) == face) { found = true; break; } if (Objects.equals(location.getBlockType(), otherBlock.getBlockType())) { found = hasSign(otherBlock, searched, original); } } return found; }
@Override protected final void arrow(final SnipeData v) { dismount(v); double distance = Double.MAX_VALUE; Entity nearest = null; Vector3d target = this.targetBlock.getPosition(); Collection<Entity> entities = this.inverse ? this.world.getEntities((e) -> e instanceof Living) : this.world.getEntities(); for (Entity e : entities) { double dist = e.getLocation().getPosition().distanceSquared(target); if (dist < distance) { nearest = e; } } if (nearest != null) { Optional<PassengerData> data = nearest.getOrCreate(PassengerData.class); if (data.isPresent()) { PassengerData passengers = data.get(); passengers.addElement(v.owner().getPlayer().getUniqueId()); nearest.offer(passengers); } this.sittingEntity = new WeakReference<>(nearest); } }
@Listener public void onVehicleMove(MoveEntityEvent event, @Getter("getTargetEntity") Minecart minecart) { if (event.getFromTransform().getPosition().distanceSquared(event.getToTransform().getPosition()) > 2 * 2) { return; } CartMechanismBlocks.findByRail(minecart.getLocation()).filter(this::isValid).ifPresent(cartMechanismBlocks -> { Vector3d from = event.getFromTransform().getPosition(); Vector3d to = event.getToTransform().getPosition(); boolean minor = from.getFloorX() == to.getFloorX() && from.getFloorY() == to.getFloorY() && from.getFloorZ() == to.getFloorZ(); impact(minecart, cartMechanismBlocks, minor); }); }
if (this.distanceLimit >= 0 && position.distanceSquared(hit.getPosition()) > this.distanceLimit * this.distanceLimit) { throw new NoSuchElementException("Distance limit reached");
&& destinationLocation.getPosition().distanceSquared(signLocation.getPosition()) > maxRange.getValue() * maxRange.getValue()) { player.sendMessage(Text.of("Destination too far away.")); return;
private BlockState findColumns(Location<World> block, Set<GateColumn> columns, BlockState state) { int x = block.getBlockX(); int y = block.getBlockY(); int z = block.getBlockZ(); Location<World> closestColumn = null; Vector3d blockFlat = new Vector3d(block.getX(), 0, block.getZ()); for (int x1 = x - searchRadius.getValue(); x1 <= x + searchRadius.getValue(); x1++) { for (int y1 = y - searchRadius.getValue(); y1 <= y + searchRadius.getValue() * 2; y1++) { for (int z1 = z - searchRadius.getValue(); z1 <= z + searchRadius.getValue(); z1++) { if (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), block.getExtent().getBlock(x1, y1, z1))) { if(closestColumn == null) closestColumn = block.getExtent().getLocation(x1, y1, z1); else { Vector3d oldClosest = new Vector3d(closestColumn.getX(), 0, closestColumn.getZ()); Vector3d test = new Vector3d(x1, 0, z1); if(blockFlat.distanceSquared(test) < blockFlat.distanceSquared(oldClosest)) closestColumn = block.getExtent().getLocation(x1, y1, z1); } } } } } if(closestColumn != null) state = searchColumn(closestColumn, columns, state); return state; }