Class BoundingBox
- All Implemented Interfaces:
- Cloneable,- ConfigurationSerializable
This basically represents a rectangular box (specified by minimum and maximum corners) that can for example be used to describe the position and extents of an object (such as an entity, block, or rectangular region) in 3D space. Its edges and faces are parallel to the axes of the cartesian coordinate system.
The bounding box may be degenerate (one or more sides having the length 0).
 Because bounding boxes are mutable, storing them long term may be dangerous
 if they get modified later. If you want to keep around a bounding box, it may
 be wise to call clone() in order to get a copy.
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new (degenerate) bounding box with all corner coordinates at0.BoundingBox(double x1, double y1, double z1, double x2, double y2, double z2) Creates a new bounding box from the given corner coordinates.
- 
Method SummaryModifier and TypeMethodDescriptionclone()Creates a copy of this bounding box.booleancontains(double x, double y, double z) Checks if this bounding box contains the specified position.booleancontains(BoundingBox other) Checks if this bounding box fully contains the given bounding box.booleanChecks if this bounding box contains the specified position.booleanChecks if this bounding box fully contains the bounding box that is defined by the given corners.copy(BoundingBox other) Copies another bounding box.static BoundingBoxdeserialize(Map<String, Object> args) booleanexpand(double expansion) Expands this bounding box uniformly by the given value in all directions.expand(double x, double y, double z) Expands this bounding box uniformly by the given values in both positive and negative directions.expand(double dirX, double dirY, double dirZ, double expansion) Expands this bounding box in the specified direction.expand(double negativeX, double negativeY, double negativeZ, double positiveX, double positiveY, double positiveZ) Expands this bounding box by the given values in the corresponding directions.Expands this bounding box in the direction specified by the given block face.Expands this bounding box uniformly by the given values in both positive and negative directions.Expands this bounding box in the specified direction.expandDirectional(double dirX, double dirY, double dirZ) Expands this bounding box in the specified direction.expandDirectional(Vector direction) Expands this bounding box in the specified direction.Gets the center of the bounding box.doubleGets the x coordinate of the center of the bounding box.doubleGets the y coordinate of the center of the bounding box.doubleGets the z coordinate of the center of the bounding box.doubleGets the height of the bounding box.getMax()Gets the maximum corner as vector.doublegetMaxX()Gets the maximum x value.doublegetMaxY()Gets the maximum y value.doublegetMaxZ()Gets the maximum z value.getMin()Gets the minimum corner as vector.doublegetMinX()Gets the minimum x value.doublegetMinY()Gets the minimum y value.doublegetMinZ()Gets the minimum z value.doubleGets the volume of the bounding box.doubleGets the width of the bounding box in the x direction.doubleGets the width of the bounding box in the z direction.inthashCode()intersection(BoundingBox other) Resizes this bounding box to represent the intersection of this and the given bounding box.static BoundingBoxCreates a new 1x1x1 sized bounding box containing the given block.static BoundingBoxCreates a new bounding box using the coordinates of the given blocks as corners.static BoundingBoxCreates a new bounding box using the given center and extents.static BoundingBoxCreates a new bounding box using the coordinates of the given locations as corners.static BoundingBoxCreates a new bounding box using the given center and extents.static BoundingBoxCreates a new bounding box using the coordinates of the given vectors as corners.booleanoverlaps(BoundingBox other) Checks if this bounding box overlaps with the given bounding box.booleanChecks if this bounding box overlaps with the bounding box that is defined by the given corners.Calculates the intersection of this bounding box with the specified line segment.resize(double x1, double y1, double z1, double x2, double y2, double z2) Resizes this bounding box.Creates a Map representation of this class.shift(double shiftX, double shiftY, double shiftZ) Shifts this bounding box by the given amounts.Shifts this bounding box by the given amounts.Shifts this bounding box by the given amounts.toString()union(double posX, double posY, double posZ) Expands this bounding box to contain (or border) the specified position.Expands this bounding box to contain (or border) the specified position.union(BoundingBox other) Expands this bounding box to contain both this and the given bounding box.Expands this bounding box to contain (or border) the specified position.
- 
Constructor Details- 
BoundingBoxpublic BoundingBox()Creates a new (degenerate) bounding box with all corner coordinates at0.
- 
BoundingBoxpublic BoundingBox(double x1, double y1, double z1, double x2, double y2, double z2) Creates a new bounding box from the given corner coordinates.- Parameters:
- x1- the first corner's x value
- y1- the first corner's y value
- z1- the first corner's z value
- x2- the second corner's x value
- y2- the second corner's y value
- z2- the second corner's z value
 
 
- 
- 
Method Details- 
ofCreates a new bounding box using the coordinates of the given vectors as corners.- Parameters:
- corner1- the first corner
- corner2- the second corner
- Returns:
- the bounding box
 
- 
ofCreates a new bounding box using the coordinates of the given locations as corners.- Parameters:
- corner1- the first corner
- corner2- the second corner
- Returns:
- the bounding box
 
- 
ofCreates a new bounding box using the coordinates of the given blocks as corners.The bounding box will be sized to fully contain both blocks. - Parameters:
- corner1- the first corner block
- corner2- the second corner block
- Returns:
- the bounding box
 
- 
ofCreates a new 1x1x1 sized bounding box containing the given block.- Parameters:
- block- the block
- Returns:
- the bounding box
 
- 
ofCreates a new bounding box using the given center and extents.- Parameters:
- center- the center
- x- 1/2 the size of the bounding box along the x axis
- y- 1/2 the size of the bounding box along the y axis
- z- 1/2 the size of the bounding box along the z axis
- Returns:
- the bounding box
 
- 
ofCreates a new bounding box using the given center and extents.- Parameters:
- center- the center
- x- 1/2 the size of the bounding box along the x axis
- y- 1/2 the size of the bounding box along the y axis
- z- 1/2 the size of the bounding box along the z axis
- Returns:
- the bounding box
 
- 
resize@NotNull public BoundingBox resize(double x1, double y1, double z1, double x2, double y2, double z2) Resizes this bounding box.- Parameters:
- x1- the first corner's x value
- y1- the first corner's y value
- z1- the first corner's z value
- x2- the second corner's x value
- y2- the second corner's y value
- z2- the second corner's z value
- Returns:
- this bounding box (resized)
 
- 
getMinXpublic double getMinX()Gets the minimum x value.- Returns:
- the minimum x value
 
- 
getMinYpublic double getMinY()Gets the minimum y value.- Returns:
- the minimum y value
 
- 
getMinZpublic double getMinZ()Gets the minimum z value.- Returns:
- the minimum z value
 
- 
getMinGets the minimum corner as vector.- Returns:
- the minimum corner as vector
 
- 
getMaxXpublic double getMaxX()Gets the maximum x value.- Returns:
- the maximum x value
 
- 
getMaxYpublic double getMaxY()Gets the maximum y value.- Returns:
- the maximum y value
 
- 
getMaxZpublic double getMaxZ()Gets the maximum z value.- Returns:
- the maximum z value
 
- 
getMaxGets the maximum corner as vector.- Returns:
- the maximum corner vector
 
- 
getWidthXpublic double getWidthX()Gets the width of the bounding box in the x direction.- Returns:
- the width in the x direction
 
- 
getWidthZpublic double getWidthZ()Gets the width of the bounding box in the z direction.- Returns:
- the width in the z direction
 
- 
getHeightpublic double getHeight()Gets the height of the bounding box.- Returns:
- the height
 
- 
getVolumepublic double getVolume()Gets the volume of the bounding box.- Returns:
- the volume
 
- 
getCenterXpublic double getCenterX()Gets the x coordinate of the center of the bounding box.- Returns:
- the center's x coordinate
 
- 
getCenterYpublic double getCenterY()Gets the y coordinate of the center of the bounding box.- Returns:
- the center's y coordinate
 
- 
getCenterZpublic double getCenterZ()Gets the z coordinate of the center of the bounding box.- Returns:
- the center's z coordinate
 
- 
getCenterGets the center of the bounding box.- Returns:
- the center
 
- 
copyCopies another bounding box.- Parameters:
- other- the other bounding box
- Returns:
- this bounding box
 
- 
expand@NotNull public BoundingBox expand(double negativeX, double negativeY, double negativeZ, double positiveX, double positiveY, double positiveZ) Expands this bounding box by the given values in the corresponding directions.Negative values will shrink the bounding box in the corresponding direction. Shrinking will be limited to the point where the affected opposite faces would meet if the they shrank at uniform speeds. - Parameters:
- negativeX- the amount of expansion in the negative x direction
- negativeY- the amount of expansion in the negative y direction
- negativeZ- the amount of expansion in the negative z direction
- positiveX- the amount of expansion in the positive x direction
- positiveY- the amount of expansion in the positive y direction
- positiveZ- the amount of expansion in the positive z direction
- Returns:
- this bounding box (now expanded)
 
- 
expandExpands this bounding box uniformly by the given values in both positive and negative directions.Negative values will shrink the bounding box. Shrinking will be limited to the bounding box's current size. - Parameters:
- x- the amount of expansion in both positive and negative x direction
- y- the amount of expansion in both positive and negative y direction
- z- the amount of expansion in both positive and negative z direction
- Returns:
- this bounding box (now expanded)
 
- 
expandExpands this bounding box uniformly by the given values in both positive and negative directions.Negative values will shrink the bounding box. Shrinking will be limited to the bounding box's current size. - Parameters:
- expansion- the expansion values
- Returns:
- this bounding box (now expanded)
 
- 
expandExpands this bounding box uniformly by the given value in all directions.A negative value will shrink the bounding box. Shrinking will be limited to the bounding box's current size. - Parameters:
- expansion- the amount of expansion
- Returns:
- this bounding box (now expanded)
 
- 
expandExpands this bounding box in the specified direction.The magnitude of the direction will scale the expansion. A negative expansion value will shrink the bounding box in this direction. Shrinking will be limited to the bounding box's current size. - Parameters:
- dirX- the x direction component
- dirY- the y direction component
- dirZ- the z direction component
- expansion- the amount of expansion
- Returns:
- this bounding box (now expanded)
 
- 
expandExpands this bounding box in the specified direction.The magnitude of the direction will scale the expansion. A negative expansion value will shrink the bounding box in this direction. Shrinking will be limited to the bounding box's current size. - Parameters:
- direction- the direction
- expansion- the amount of expansion
- Returns:
- this bounding box (now expanded)
 
- 
expandExpands this bounding box in the direction specified by the given block face.A negative expansion value will shrink the bounding box in this direction. Shrinking will be limited to the bounding box's current size. - Parameters:
- blockFace- the block face
- expansion- the amount of expansion
- Returns:
- this bounding box (now expanded)
 
- 
expandDirectionalExpands this bounding box in the specified direction.Negative values will expand the bounding box in the negative direction, positive values will expand it in the positive direction. The magnitudes of the direction components determine the corresponding amounts of expansion. - Parameters:
- dirX- the x direction component
- dirY- the y direction component
- dirZ- the z direction component
- Returns:
- this bounding box (now expanded)
 
- 
expandDirectionalExpands this bounding box in the specified direction.Negative values will expand the bounding box in the negative direction, positive values will expand it in the positive direction. The magnitude of the direction vector determines the amount of expansion. - Parameters:
- direction- the direction and magnitude of the expansion
- Returns:
- this bounding box (now expanded)
 
- 
unionExpands this bounding box to contain (or border) the specified position.- Parameters:
- posX- the x position value
- posY- the y position value
- posZ- the z position value
- Returns:
- this bounding box (now expanded)
- See Also:
 
- 
unionExpands this bounding box to contain (or border) the specified position.- Parameters:
- position- the position
- Returns:
- this bounding box (now expanded)
- See Also:
 
- 
unionExpands this bounding box to contain (or border) the specified position.- Parameters:
- position- the position
- Returns:
- this bounding box (now expanded)
- See Also:
 
- 
unionExpands this bounding box to contain both this and the given bounding box.- Parameters:
- other- the other bounding box
- Returns:
- this bounding box (now expanded)
 
- 
intersectionResizes this bounding box to represent the intersection of this and the given bounding box.- Parameters:
- other- the other bounding box
- Returns:
- this bounding box (now representing the intersection)
- Throws:
- IllegalArgumentException- if the bounding boxes don't overlap
 
- 
shiftShifts this bounding box by the given amounts.- Parameters:
- shiftX- the shift in x direction
- shiftY- the shift in y direction
- shiftZ- the shift in z direction
- Returns:
- this bounding box (now shifted)
 
- 
shiftShifts this bounding box by the given amounts.- Parameters:
- shift- the shift
- Returns:
- this bounding box (now shifted)
 
- 
shiftShifts this bounding box by the given amounts.- Parameters:
- shift- the shift
- Returns:
- this bounding box (now shifted)
 
- 
overlapsChecks if this bounding box overlaps with the given bounding box.Bounding boxes that are only intersecting at the borders are not considered overlapping. - Parameters:
- other- the other bounding box
- Returns:
- trueif overlapping
 
- 
overlapsChecks if this bounding box overlaps with the bounding box that is defined by the given corners.Bounding boxes that are only intersecting at the borders are not considered overlapping. - Parameters:
- min- the first corner
- max- the second corner
- Returns:
- trueif overlapping
 
- 
containspublic boolean contains(double x, double y, double z) Checks if this bounding box contains the specified position.Positions exactly on the minimum borders of the bounding box are considered to be inside the bounding box, while positions exactly on the maximum borders are considered to be outside. This allows bounding boxes to reside directly next to each other with positions always only residing in exactly one of them. - Parameters:
- x- the position's x coordinates
- y- the position's y coordinates
- z- the position's z coordinates
- Returns:
- trueif the bounding box contains the position
 
- 
containsChecks if this bounding box contains the specified position.Positions exactly on the minimum borders of the bounding box are considered to be inside the bounding box, while positions exactly on the maximum borders are considered to be outside. This allows bounding boxes to reside directly next to each other with positions always only residing in exactly one of them. - Parameters:
- position- the position
- Returns:
- trueif the bounding box contains the position
 
- 
containsChecks if this bounding box fully contains the given bounding box.- Parameters:
- other- the other bounding box
- Returns:
- trueif the bounding box contains the given bounding box
 
- 
containsChecks if this bounding box fully contains the bounding box that is defined by the given corners.- Parameters:
- min- the first corner
- max- the second corner
- Returns:
- trueif the bounding box contains the specified bounding box
 
- 
rayTrace@Nullable public RayTraceResult rayTrace(@NotNull Vector start, @NotNull Vector direction, double maxDistance) Calculates the intersection of this bounding box with the specified line segment.Intersections at edges and corners yield one of the affected block faces as hit result, but it is not defined which of them. - Parameters:
- start- the start position
- direction- the ray direction
- maxDistance- the maximum distance
- Returns:
- the ray trace hit result, or nullif there is no hit
 
- 
hashCodepublic int hashCode()
- 
equals
- 
toString
- 
cloneCreates a copy of this bounding box.
- 
serializeDescription copied from interface:ConfigurationSerializableCreates a Map representation of this class.This class must provide a method to restore this class, as defined in the ConfigurationSerializableinterface javadocs.- Specified by:
- serializein interface- ConfigurationSerializable
- Returns:
- Map containing the current state of this class
 
- 
deserialize
 
-