Class AABB

java.lang.Object
net.minecraft.world.phys.AABB

public class AABB extends Object
  • Field Details

    • EPSILON

      private static final double EPSILON
      See Also:
    • INFINITE

      public static final AABB INFINITE
    • minX

      public final double minX
    • minY

      public final double minY
    • minZ

      public final double minZ
    • maxX

      public final double maxX
    • maxY

      public final double maxY
    • maxZ

      public final double maxZ
  • Constructor Details

    • AABB

      public AABB(double pX1, double pY1, double pZ1, double pX2, double pY2, double pZ2)
    • AABB

      public AABB(BlockPos pPos)
    • AABB

      public AABB(Vec3 pStart, Vec3 pEnd)
  • Method Details

    • of

      public static AABB of(BoundingBox pMutableBox)
    • unitCubeFromLowerCorner

      public static AABB unitCubeFromLowerCorner(Vec3 pVector)
    • encapsulatingFullBlocks

      public static AABB encapsulatingFullBlocks(BlockPos pStartPos, BlockPos pEndPos)
    • setMinX

      public AABB setMinX(double pMinX)
    • setMinY

      public AABB setMinY(double pMinY)
    • setMinZ

      public AABB setMinZ(double pMinZ)
    • setMaxX

      public AABB setMaxX(double pMaxX)
    • setMaxY

      public AABB setMaxY(double pMaxY)
    • setMaxZ

      public AABB setMaxZ(double pMaxZ)
    • min

      public double min(Direction.Axis pAxis)
    • max

      public double max(Direction.Axis pAxis)
    • equals

      public boolean equals(Object pOther)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • contract

      public AABB contract(double pX, double pY, double pZ)
      Creates a new
      invalid reference
      AxisAlignedBB
      that has been contracted by the given amount, with positive changes decreasing max values and negative changes increasing min values.
      If the amount to contract by is larger than the length of a side, then the side will wrap (still creating a valid AABB - see last sample).

      Samples:

      InputResult
      new AxisAlignedBB(0, 0, 0, 4, 4, 4).contract(2, 2, 2)
      box[0.0, 0.0, 0.0 -> 2.0, 2.0, 2.0]
      new AxisAlignedBB(0, 0, 0, 4, 4, 4).contract(-2, -2, -2)
      box[2.0, 2.0, 2.0 -> 4.0, 4.0, 4.0]
      new AxisAlignedBB(5, 5, 5, 7, 7, 7).contract(0, 1, -1)
      box[5.0, 5.0, 6.0 -> 7.0, 6.0, 7.0]
      new AxisAlignedBB(-2, -2, -2, 2, 2, 2).contract(4, -4, 0)
      box[-8.0, 2.0, -2.0 -> -2.0, 8.0, 2.0]

      See Also:

      • invalid reference
        #expand(double, double, double)
        - like this, except for expanding.
      • invalid reference
        #grow(double, double, double)
        and
        invalid reference
        #grow(double)
        - expands in all directions.
      • invalid reference
        #shrink(double)
        - contracts in all directions (like
        invalid reference
        #grow(double)
        )
      Returns:
      A new modified bounding box.
    • expandTowards

      public AABB expandTowards(Vec3 pVector)
    • expandTowards

      public AABB expandTowards(double pX, double pY, double pZ)
      Creates a new
      invalid reference
      AxisAlignedBB
      that has been expanded by the given amount, with positive changes increasing max values and negative changes decreasing min values.

      Samples:

      InputResult
      new AxisAlignedBB(0, 0, 0, 1, 1, 1).expand(2, 2, 2)
      box[0, 0, 0 -> 3, 3, 3]
      new AxisAlignedBB(0, 0, 0, 1, 1, 1).expand(-2, -2, -2)
      box[-2, -2, -2 -> 1, 1, 1]
      new AxisAlignedBB(5, 5, 5, 7, 7, 7).expand(0, 1, -1)
      box[5, 5, 4, 7, 8, 7]

      See Also:

      • contract(double, double, double) - like this, except for shrinking.
      • invalid reference
        #grow(double, double, double)
        and
        invalid reference
        #grow(double)
        - expands in all directions.
      • invalid reference
        #shrink(double)
        - contracts in all directions (like
        invalid reference
        #grow(double)
        )
      Returns:
      A modified bounding box that will always be equal or greater in volume to this bounding box.
    • inflate

      public AABB inflate(double pX, double pY, double pZ)
      Creates a new
      invalid reference
      AxisAlignedBB
      that has been contracted by the given amount in both directions. Negative values will shrink the AABB instead of expanding it.
      Side lengths will be increased by 2 times the value of the parameters, since both min and max are changed.
      If contracting and the amount to contract by is larger than the length of a side, then the side will wrap (still creating a valid AABB - see last ample).

      Samples:

      InputResult
      new AxisAlignedBB(0, 0, 0, 1, 1, 1).grow(2, 2, 2)
      box[-2.0, -2.0, -2.0 -> 3.0, 3.0, 3.0]
      new AxisAlignedBB(0, 0, 0, 6, 6, 6).grow(-2, -2, -2)
      box[2.0, 2.0, 2.0 -> 4.0, 4.0, 4.0]
      new AxisAlignedBB(5, 5, 5, 7, 7, 7).grow(0, 1, -1)
      box[5.0, 4.0, 6.0 -> 7.0, 8.0, 6.0]
      new AxisAlignedBB(1, 1, 1, 3, 3, 3).grow(-4, -2, -3)
      box[-1.0, 1.0, 0.0 -> 5.0, 3.0, 4.0]

      See Also:

      • invalid reference
        #expand(double, double, double)
        - expands in only one direction.
      • contract(double, double, double) - contracts in only one direction.
      • invalid reference
        #grow(double)
        - version of this that expands in all directions from one parameter.
      • invalid reference
        #shrink(double)
        - contracts in all directions
      Returns:
      A modified bounding box.
    • inflate

      public AABB inflate(double pValue)
      Creates a new
      invalid reference
      AxisAlignedBB
      that is expanded by the given value in all directions. Equivalent to
      invalid reference
      #grow(double, double, double)
      with the given value for all 3 params. Negative values will shrink the AABB.
      Side lengths will be increased by 2 times the value of the parameter, since both min and max are changed.
      If contracting and the amount to contract by is larger than the length of a side, then the side will wrap (still creating a valid AABB - see samples on
      invalid reference
      #grow(double, double, double)
      ).
      Returns:
      A modified AABB.
    • intersect

      public AABB intersect(AABB pOther)
    • minmax

      public AABB minmax(AABB pOther)
    • move

      public AABB move(double pX, double pY, double pZ)
      Offsets the current bounding box by the specified amount.
    • move

      public AABB move(BlockPos pPos)
    • move

      public AABB move(Vec3 pVec)
    • move

      public AABB move(org.joml.Vector3f p_346297_)
    • intersects

      public boolean intersects(AABB pOther)
      Checks if the bounding box intersects with another.
    • intersects

      public boolean intersects(double pX1, double pY1, double pZ1, double pX2, double pY2, double pZ2)
    • intersects

      public boolean intersects(Vec3 pMin, Vec3 pMax)
    • contains

      public boolean contains(Vec3 pVec)
      Returns if the supplied Vec3D is completely inside the bounding box
    • contains

      public boolean contains(double pX, double pY, double pZ)
    • getSize

      public double getSize()
    • getXsize

      public double getXsize()
    • getYsize

      public double getYsize()
    • getZsize

      public double getZsize()
    • deflate

      public AABB deflate(double pX, double pY, double pZ)
    • deflate

      public AABB deflate(double pValue)
      Creates a new
      invalid reference
      AxisAlignedBB
      that is expanded by the given value in all directions. Equivalent to
      invalid reference
      #grow(double)
      with value set to the negative of the value provided here. Passing a negative value to this method values will grow the AABB.
      Side lengths will be decreased by 2 times the value of the parameter, since both min and max are changed.
      If contracting and the amount to contract by is larger than the length of a side, then the side will wrap (still creating a valid AABB - see samples on
      invalid reference
      #grow(double, double, double)
      ).
      Returns:
      A modified AABB.
    • clip

      public Optional<Vec3> clip(Vec3 pFrom, Vec3 pTo)
    • clip

      @Nullable public static BlockHitResult clip(Iterable<AABB> pBoxes, Vec3 pStart, Vec3 pEnd, BlockPos pPos)
    • getDirection

      @Nullable private static Direction getDirection(AABB pAabb, Vec3 pStart, double[] pMinDistance, @Nullable Direction pFacing, double pDeltaX, double pDeltaY, double pDeltaZ)
    • clipPoint

      @Nullable private static Direction clipPoint(double[] pMinDistance, @Nullable Direction pPrevDirection, double pDistanceSide, double pDistanceOtherA, double pDistanceOtherB, double pMinSide, double pMinOtherA, double pMaxOtherA, double pMinOtherB, double pMaxOtherB, Direction pHitSide, double pStartSide, double pStartOtherA, double pStartOtherB)
    • distanceToSqr

      public double distanceToSqr(Vec3 pVec)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasNaN

      public boolean hasNaN()
    • getCenter

      public Vec3 getCenter()
    • getBottomCenter

      public Vec3 getBottomCenter()
    • getMinPosition

      public Vec3 getMinPosition()
    • getMaxPosition

      public Vec3 getMaxPosition()
    • ofSize

      public static AABB ofSize(Vec3 pCenter, double pXSize, double pYSize, double pZSize)
    • isInfinite

      public boolean isInfinite()
      Returns true if this AABB is infinite in all directions.
      Returns:
      true if this AABB is infinite in all directions