/** * Gets the location next to this one in the given direction. * Always moves by a unit amount, even diagonally. * * @param direction The direction to move in * @return The location in that direction */ public Location<E> getRelative(Direction direction) { return add(direction.asOffset()); }
/** * Gets the direction of the axis along the given {@link AxisDirection}. * * @param axis The axis * @param direction The direction along the axis * @return The direction */ public static Direction getFromAxis(final Axis axis, final AxisDirection direction) { switch (direction) { case PLUS: return getFromAxis(axis); case ZERO: return NONE; case MINUS: return getFromAxis(axis).getOpposite(); default: throw new IllegalArgumentException(axis.name()); } }
/** * Gets the location next to this one in the given direction. * Always moves by a block amount, even diagonally. * * <p>{@link org.spongepowered.api.util.Direction.Division#SECONDARY_ORDINAL} * directions are not a valid argument. These will throw an exception. * </p> * * @param direction The direction to move in * @return The location in that direction * @throws IllegalArgumentException If the direction is a * {@link org.spongepowered.api.util.Direction.Division#SECONDARY_ORDINAL} */ public Location<E> getBlockRelative(Direction direction) { checkArgument(!direction.isSecondaryOrdinal(), "Secondary cardinal directions can't be used here"); return add(direction.asBlockOffset()); }
private void addChair(Player player, Location<World> location) { Entity entity = location.getExtent().createEntity(EntityTypes.ARMOR_STAND, location.getBlockPosition().toDouble().sub(-0.5, 1.2, -0.5)); entity.offer(Keys.INVISIBLE, true); entity.offer(Keys.HAS_GRAVITY, false); if (faceCorrectDirection.getValue() && location.supports(Keys.DIRECTION)) { Vector3d euler = LocationUtil.cartesianToEuler(location.get(Keys.DIRECTION).orElse(Direction.NONE).getOpposite().asOffset()); entity.setRotation(euler); player.setRotation(euler); } Sponge.getCauseStackManager().pushCause(player); location.getExtent().spawnEntity(entity); Sponge.getCauseStackManager().popCause(); Chair<?> chair = new Chair<>((ArmorStand) entity, location, player.getLocation()); entity.addPassenger(player); player.sendMessage(Text.of(TextColors.YELLOW, "You sit down!")); chairs.put(player.getUniqueId(), chair); }
@Override public List<Location<World>> findPotentialOutputs(Location<World> location, ItemStack itemStack, Direction inputSide) { return Lists.newArrayList(location.getRelative(inputSide.getOpposite())); } }
/** * Gets the closest horizontal direction from the given vector. If the * vector is the 0-Vector (ignoring y), this method returns {@link #NONE}. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @return The closest horizontal direction. */ public static Direction getClosestHorizontal(Vector3d vector) { return getClosestHorizontal(vector, Division.SECONDARY_ORDINAL); }
@Override public int compareTo(Property<?, ?> other) { if (other == null) { return 1; } return this.getValue().compareTo(Coerce.toEnum(other.getValue(), Direction.class, Direction.NONE)); }
/** * Gets the closest direction from the given vector. If the vector is the * 0-Vector, this method returns {@link #NONE}. If the vector has the same * horizontal and vertical length, a horizontal direction will be returned. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @return The closest horizontal direction. */ public static Direction getClosest(Vector3d vector) { return getClosest(vector, Division.SECONDARY_ORDINAL); }
/** * Gets the relative direction of 'other' from 'base'. * * @param base The location of base. * @param other The location of other. * @return The relative direction */ public static Direction getFacing(Location<World> base, Location<World> other) { for (Direction dir : Direction.values()) { if (base.getRelative(dir).getPosition().equals(other.getPosition())) return dir; } return null; }
/** * @param sign treated as sign post if it is such, or else assumed to be a wall sign (i.e., * if you ask about a stone block, it's considered a wall * sign). * @return the blank side of the sign opposite the text. In the case of a wall sign, * the block in this direction is the block to which the sign is * attached. This is also the direction a player would be facing when reading the sign; see {@link #getFront(Location)}. */ public static Direction getBack(Location<World> sign) { Direction front = getFront(sign); if (front == null) return Direction.NONE; return front.getOpposite(); }
/** * Gets the closest direction from the given vector. If the vector is the * 0-Vector, this method returns {@link #NONE}. If the vector has the same * horizontal and vertical length, a horizontal direction will be returned. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @param smallestDivision The smallest compass division that can be * returned * @return The closest horizontal direction. */ public static Direction getClosest(Vector3d vector, Division smallestDivision) { if (vector.getY() * vector.getY() <= vector.getX() * vector.getX() + vector.getZ() * vector.getZ()) { return getClosestHorizontal(vector, smallestDivision); } else if (vector.getY() > 0) { return UP; } else { return DOWN; } }
@Override public int compareTo(Property<?, ?> other) { if (other == null) { return 1; } return this.getValue().compareTo(Coerce.toEnum(other.getValue(), Direction.class, Direction.NONE)); }
/** * Gets the closest direction from the given vector. If the vector is the * 0-Vector, this method returns {@link #NONE}. If the vector has the same * horizontal and vertical length, a horizontal direction will be returned. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @return The closest horizontal direction. */ public static Direction getClosest(Vector3d vector) { return getClosest(vector, Division.SECONDARY_ORDINAL); }
/** * Gets the location next to this one in the given direction. * Always moves by a unit amount, even diagonally. * * @param direction The direction to move in * @return The location in that direction */ public Location<E> getRelative(Direction direction) { return add(direction.asOffset()); }
/** * Moves chunk coordinates a number of steps in the given direction. Returns * nothing if the new coordinates are not valid. * {@link Division#SECONDARY_ORDINAL} directions are not a valid * argument. These will throw an exception. * * @param chunkCoords The chunk coordinates to move from * @param direction The direction in which to move * @param steps The number of steps to take * @return The new chunk coordinates if they are valid * @throws IllegalArgumentException If the direction is a * {@link Division#SECONDARY_ORDINAL} */ default Optional<Vector3i> moveToChunk(Vector3i chunkCoords, Direction direction, int steps) { checkNotNull(direction, "direction"); checkArgument(!direction.isSecondaryOrdinal(), "Secondary cardinal directions can't be used here"); return addToChunk(chunkCoords, direction.asBlockOffset().mul(steps)); }
/** * Gets the direction of the axis along the given {@link AxisDirection}. * * @param axis The axis * @param direction The direction along the axis * @return The direction */ public static Direction getFromAxis(final Axis axis, final AxisDirection direction) { switch (direction) { case PLUS: return getFromAxis(axis); case ZERO: return NONE; case MINUS: return getFromAxis(axis).getOpposite(); default: throw new IllegalArgumentException(axis.name()); } }
signLocations.addAll(BlockUtil.getAdjacentExcept(location, event.getTargetSide())); } else { signLocations.add(location.getRelative(event.getTargetSide().getOpposite()));
/** * Gets the closest horizontal direction from the given vector. If the * vector is the 0-Vector (ignoring y), this method returns {@link #NONE}. * If the vector is halfway between two directions the clockwise next will * be selected. * * @param vector The vector to convert to a direction * @return The closest horizontal direction. */ public static Direction getClosestHorizontal(Vector3d vector) { return getClosestHorizontal(vector, Division.SECONDARY_ORDINAL); }
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> offset = dispenser.getLocation().getRelative(face); int distance = 0; while (offset.getBlockType() == BlockTypes.AIR && distance < 5) { for (Entity e : LocationUtil.getEntitiesAtLocation(offset)) { e.setVelocity(face.asOffset().mul(5 - distance)); } distance ++; offset = offset.getRelative(face); } return true; } return false; } }
/** * Gets the location next to this one in the given direction. * Always moves by a block amount, even diagonally. * * <p>{@link org.spongepowered.api.util.Direction.Division#SECONDARY_ORDINAL} * directions are not a valid argument. These will throw an exception. * </p> * * @param direction The direction to move in * @return The location in that direction * @throws IllegalArgumentException If the direction is a * {@link org.spongepowered.api.util.Direction.Division#SECONDARY_ORDINAL} */ public Location<E> getBlockRelative(Direction direction) { checkArgument(!direction.isSecondaryOrdinal(), "Secondary cardinal directions can't be used here"); return add(direction.asBlockOffset()); }