/** * Constructs the BlockIterator. * * @param loc The location for the start of the ray trace * @param yOffset The trace begins vertically offset from the start vector * by this value */ public BlockIterator(Location loc, double yOffset) { this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, 0); }
/** * Constructs the BlockIterator * * @param loc The location for the start of the ray trace * @param yOffset The trace begins vertically offset from the start vector * by this value * @param maxDistance This is the maximum distance in blocks for the * trace. Setting this value above 140 may lead to problems with * unloaded chunks. A value of 0 indicates no limit */ public BlockIterator(Location loc, double yOffset, int maxDistance) { this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, maxDistance); }
public static Vector getRayBetween(Location target, Location source) { return target.clone().subtract(source).toVector(); } }
/** * Sets the point where this shulker is attached, or null to detach the shulker. * * @param attachment the new attachment point, or null to detach */ public void setAttachment(Location attachment) { this.attachment = attachment; if (attachment != null) { this.metadata.set(MetadataIndex.SHULKER_ATTACHMENT_POSITION, new BlockVector(attachment.toVector())); } else { this.metadata.set(MetadataIndex.SHULKER_ATTACHMENT_POSITION, null); } }
.filter(entity -> entity instanceof LivingEntity && !entity.isDead()) .forEach(entity -> { Vector pos = entity.getLocation().toVector(); int minY = getHighestBlockYAt(pos.getBlockX(), pos.getBlockZ()); if (pos.getBlockY() >= minY) { .get(ThreadLocalRandom.current().nextInt(livingEntities.size())); Vector newTarget = entity.getLocation().toVector(); x = newTarget.getBlockX(); z = newTarget.getBlockZ();
@Override public List<Entity> getNearbyEntities(double x, double y, double z) { // This behavior is similar to CraftBukkit, where a call with args // (0, 0, 0) finds any entities whose bounding boxes intersect that of // this entity. BoundingBox searchBox; if (boundingBox == null) { searchBox = BoundingBox.fromPositionAndSize(location.toVector(), new Vector(0, 0, 0)); } else { searchBox = BoundingBox.copyOf(boundingBox); } Vector vec = new Vector(x, y, z); searchBox.minCorner.subtract(vec); searchBox.maxCorner.add(vec); return world.getEntityManager().getEntitiesInside(searchBox, this); }
@Override public List<Entity> getNearbyEntities(double x, double y, double z) { // This behavior is similar to CraftBukkit, where a call with args // (0, 0, 0) finds any entities whose bounding boxes intersect that of // this entity. BoundingBox searchBox = BoundingBox .fromPositionAndSize(location.toVector(), new Vector(0, 0, 0)); Vector vec = new Vector(x, y, z); Vector vec2 = new Vector(0, 0.5 * y, 0); searchBox.minCorner.subtract(vec).add(vec2); searchBox.maxCorner.add(vec).add(vec2); return world.getEntityManager().getEntitiesInside(searchBox, this); }
final Set<Material> blockedMaterials) { Map<Vector, Double> neighbors = new HashMap<>(); final Vector start = location.toVector();
Vector delta = newLocation.clone().subtract(oldLocation).toVector(); delta.setX(Math.abs(delta.getX())); delta.setY(Math.abs(delta.getY()));
@Override public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) { super.entityInteract(player, message); if (message.getAction() == InteractEntityMessage.Action.INTERACT.ordinal()) { if (player.getGameMode().equals(GameMode.CREATIVE) || player.getGameMode() .equals(GameMode.SPECTATOR)) { return false; } if (!isAdult()) { return false; } ItemStack hand = InventoryUtil .itemOrEmpty(player.getInventory().getItem(message.getHandSlot())); if (!hand.getType().equals(Material.BUCKET)) { return false; } player.getInventory().consumeItemInHand(message.getHandSlot()); if (player.getInventory().firstEmpty() == -1) { GlowItem item = player.getWorld() .dropItem(player.getLocation().clone().add(0, 1, 0), new ItemStack(Material.MILK_BUCKET, 1)); item.setVelocity(getLocation().add(0, -1, 0).clone().toVector() .subtract(player.getLocation().clone().add(0, 1, 0).toVector()).multiply(0.3)); } else { player.getInventory().addItem(new ItemStack(Material.MILK_BUCKET, 1)); } } return true; }
Vector delta = newLocation.clone().subtract(oldLocation).toVector(); delta.setX(Math.abs(delta.getX())); delta.setY(Math.abs(delta.getY()));
/** * Construct an immutable floating point 3D vector from a location object. * * @param location - the location to copy. */ public TARDISVector3D(Location location) { this(location.toVector()); }
@Override protected boolean contains(Location location) { return bounds.contains(location.toVector()); } }
default boolean isFacingLocation(Location from, Location at, float yawLimitDegrees, float pitchLimitDegrees) { Vector direction = from.toVector().subtract(at.toVector()).normalize(); float pitch = 90 - (float) Math.toDegrees(Math.acos(direction.getY())); if (from.getPitch() > pitch + pitchLimitDegrees || from.getPitch() < pitch - pitchLimitDegrees) { return false; } return isFacingLocation(from, at, yawLimitDegrees); }
default Location faceLocation(Location from, Location at) { Vector direction = from.toVector().subtract(at.toVector()).normalize(); Location newLocation = from.clone(); newLocation.setYaw(180 - (float) Math.toDegrees(Math.atan2(direction.getX(), direction.getZ()))); newLocation.setPitch(90 - (float) Math.toDegrees(Math.acos(direction.getY()))); return newLocation; }
public VectorGoal(Location dest, float range) { if (!MinecraftBlockExaminer.canStandIn(dest.getBlock().getType())) { dest = MinecraftBlockExaminer.findValidLocation(dest, 1); } this.leeway = range; this.goal = dest.toVector(); goal.setX(goal.getBlockX()).setY(goal.getBlockY()).setZ(goal.getBlockZ()); }