Class BlockPos

java.lang.Object
net.minecraft.util.math.Vec3i
net.minecraft.util.math.BlockPos
All Implemented Interfaces:
Comparable<Vec3i>
Direct Known Subclasses:
BlockPos.Mutable

@Immutable
public class BlockPos
extends Vec3i
Represents the position of a block in a three-dimensional volume.

The position is integer-valued.

A block position may be mutable; hence, when using block positions obtained from other places as map keys, etc., you should call toImmutable() to obtain an immutable block position.

  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<BlockPos> CODEC
    • LOGGER

      private static final Logger LOGGER
    • ORIGIN

      public static final BlockPos ORIGIN
      The block position which x, y, and z values are all zero.
    • SIZE_BITS_X

      private static final int SIZE_BITS_X
    • SIZE_BITS_Z

      private static final int SIZE_BITS_Z
    • SIZE_BITS_Y

      private static final int SIZE_BITS_Y
    • BITS_X

      private static final long BITS_X
    • BITS_Y

      private static final long BITS_Y
    • BITS_Z

      private static final long BITS_Z
    • BIT_SHIFT_Z

      private static final int BIT_SHIFT_Z
    • BIT_SHIFT_X

      private static final int BIT_SHIFT_X
  • Constructor Details

    • BlockPos

      public BlockPos​(int x, int y, int z)
    • BlockPos

      public BlockPos​(double x, double y, double z)
    • BlockPos

      public BlockPos​(Vec3d pos)
    • BlockPos

      public BlockPos​(Position pos)
    • BlockPos

      public BlockPos​(Vec3i pos)
  • Method Details

    • offset

      public static long offset​(long value, Direction direction)
    • add

      public static long add​(long value, int x, int y, int z)
    • unpackLongX

      public static int unpackLongX​(long packedPos)
    • unpackLongY

      public static int unpackLongY​(long packedPos)
    • unpackLongZ

      public static int unpackLongZ​(long packedPos)
    • fromLong

      public static BlockPos fromLong​(long packedPos)
    • asLong

      public long asLong()
    • asLong

      public static long asLong​(int x, int y, int z)
    • removeChunkSectionLocalY

      public static long removeChunkSectionLocalY​(long y)
    • add

      public BlockPos add​(double x, double y, double z)
    • add

      public BlockPos add​(int x, int y, int z)
    • add

      public BlockPos add​(Vec3i pos)
    • subtract

      public BlockPos subtract​(Vec3i pos)
    • up

      public BlockPos up()
      Overrides:
      up in class Vec3i
    • up

      public BlockPos up​(int distance)
      Overrides:
      up in class Vec3i
    • down

      public BlockPos down()
      Overrides:
      down in class Vec3i
    • down

      public BlockPos down​(int int2)
      Overrides:
      down in class Vec3i
    • north

      public BlockPos north()
    • north

      public BlockPos north​(int distance)
    • south

      public BlockPos south()
    • south

      public BlockPos south​(int distance)
    • west

      public BlockPos west()
    • west

      public BlockPos west​(int distance)
    • east

      public BlockPos east()
    • east

      public BlockPos east​(int distance)
    • offset

      public BlockPos offset​(Direction direction)
    • offset

      public BlockPos offset​(Direction direction, int int2)
      Overrides:
      offset in class Vec3i
    • offset

      public BlockPos offset​(Direction.Axis axis, int distance)
    • rotate

      public BlockPos rotate​(BlockRotation rotation)
    • crossProduct

      public BlockPos crossProduct​(Vec3i pos)
      Overrides:
      crossProduct in class Vec3i
    • toImmutable

      public BlockPos toImmutable()
      Returns an immutable block position with the same x, y, and z as this position.

      This method should be called when a block position is used as map keys as to prevent side effects of mutations of mutable block positions.

    • mutableCopy

      public BlockPos.Mutable mutableCopy()
      Returns a mutable copy of this block position.

      If this block position is a mutable one, mutation to this block position won't affect the returned position.

    • iterateRandomly

      public static Iterable<BlockPos> iterateRandomly​(Random random, int count, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
      Iterates through count random block positions in the given area.

      The iterator yields positions in no specific order. The same position may be returned multiple times by the iterator.

      Parameters:
      random - the Random object used to compute new positions
      count - the number of positions to iterate
      minX - the minimum x value for returned positions
      minY - the minimum y value for returned positions
      minZ - the minimum z value for returned positions
      maxX - the maximum x value for returned positions
      maxY - the maximum y value for returned positions
      maxZ - the maximum z value for returned positions
    • iterateOutwards

      public static Iterable<BlockPos> iterateOutwards​(BlockPos center, int xRange, int yRange, int zRange)
      Iterates block positions around the center. The iteration order is mainly based on the manhattan distance of the position from the center.

      For the same manhattan distance, the positions are iterated by y offset, from negative to positive. For the same y offset, the positions are iterated by x offset, from negative to positive. For the two positions with the same x and y offsets and the same manhattan distance, the one with a positive z offset is visited first before the one with a negative z offset.

      Parameters:
      center - the center of iteration
      xRange - the maximum x difference from the center
      yRange - the maximum y difference from the center
      zRange - the maximum z difference from the center
    • findClosest

      public static Optional<BlockPos> findClosest​(BlockPos pos, int horizontalRange, int verticalRange, Predicate<BlockPos> condition)
    • streamOutwards

      public static Stream<BlockPos> streamOutwards​(BlockPos center, int maxX, int maxY, int maxZ)
    • iterate

      public static Iterable<BlockPos> iterate​(BlockPos start, BlockPos end)
    • stream

      public static Stream<BlockPos> stream​(BlockPos start, BlockPos end)
    • stream

      public static Stream<BlockPos> stream​(BlockBox box)
    • stream

      public static Stream<BlockPos> stream​(Box box)
    • stream

      public static Stream<BlockPos> stream​(int startX, int startY, int startZ, int endX, int endY, int endZ)
    • iterate

      public static Iterable<BlockPos> iterate​(int startX, int startY, int startZ, int endX, int endY, int endZ)
    • method_30512

      public static Iterable<BlockPos.Mutable> method_30512​(BlockPos blockPos, int int2, Direction direction, Direction direction2)