程序包 org.bukkit.util

类 BoundingBox

java.lang.Object
org.bukkit.util.BoundingBox
所有已实现的接口:
Cloneable, ConfigurationSerializable

public class BoundingBox extends Object implements Cloneable, ConfigurationSerializable
A mutable axis aligned bounding box (AABB).

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.

  • 构造器详细资料

    • BoundingBox

      public BoundingBox()
      Creates a new (degenerate) bounding box with all corner coordinates at 0.
    • BoundingBox

      public BoundingBox(double x1, double y1, double z1, double x2, double y2, double z2)
      Creates a new bounding box from the given corner coordinates.
      参数:
      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
  • 方法详细资料

    • of

      Creates a new bounding box using the coordinates of the given vectors as corners.
      参数:
      corner1 - the first corner
      corner2 - the second corner
      返回:
      the bounding box
    • of

      Creates a new bounding box using the coordinates of the given locations as corners.
      参数:
      corner1 - the first corner
      corner2 - the second corner
      返回:
      the bounding box
    • of

      @NotNull public static @NotNull BoundingBox of(@NotNull @NotNull Block corner1, @NotNull @NotNull Block corner2)
      Creates a new bounding box using the coordinates of the given blocks as corners.

      The bounding box will be sized to fully contain both blocks.

      参数:
      corner1 - the first corner block
      corner2 - the second corner block
      返回:
      the bounding box
    • of

      @NotNull public static @NotNull BoundingBox of(@NotNull @NotNull Block block)
      Creates a new 1x1x1 sized bounding box containing the given block.
      参数:
      block - the block
      返回:
      the bounding box
    • of

      @NotNull public static @NotNull BoundingBox of(@NotNull @NotNull Vector center, double x, double y, double z)
      Creates a new bounding box using the given center and extents.
      参数:
      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
      返回:
      the bounding box
    • of

      @NotNull public static @NotNull BoundingBox of(@NotNull @NotNull Location center, double x, double y, double z)
      Creates a new bounding box using the given center and extents.
      参数:
      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
      返回:
      the bounding box
    • resize

      @NotNull public @NotNull BoundingBox resize(double x1, double y1, double z1, double x2, double y2, double z2)
      Resizes this bounding box.
      参数:
      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
      返回:
      this bounding box (resized)
    • getMinX

      public double getMinX()
      Gets the minimum x value.
      返回:
      the minimum x value
    • getMinY

      public double getMinY()
      Gets the minimum y value.
      返回:
      the minimum y value
    • getMinZ

      public double getMinZ()
      Gets the minimum z value.
      返回:
      the minimum z value
    • getMin

      @NotNull public @NotNull Vector getMin()
      Gets the minimum corner as vector.
      返回:
      the minimum corner as vector
    • getMaxX

      public double getMaxX()
      Gets the maximum x value.
      返回:
      the maximum x value
    • getMaxY

      public double getMaxY()
      Gets the maximum y value.
      返回:
      the maximum y value
    • getMaxZ

      public double getMaxZ()
      Gets the maximum z value.
      返回:
      the maximum z value
    • getMax

      @NotNull public @NotNull Vector getMax()
      Gets the maximum corner as vector.
      返回:
      the maximum corner vector
    • getWidthX

      public double getWidthX()
      Gets the width of the bounding box in the x direction.
      返回:
      the width in the x direction
    • getWidthZ

      public double getWidthZ()
      Gets the width of the bounding box in the z direction.
      返回:
      the width in the z direction
    • getHeight

      public double getHeight()
      Gets the height of the bounding box.
      返回:
      the height
    • getVolume

      public double getVolume()
      Gets the volume of the bounding box.
      返回:
      the volume
    • getCenterX

      public double getCenterX()
      Gets the x coordinate of the center of the bounding box.
      返回:
      the center's x coordinate
    • getCenterY

      public double getCenterY()
      Gets the y coordinate of the center of the bounding box.
      返回:
      the center's y coordinate
    • getCenterZ

      public double getCenterZ()
      Gets the z coordinate of the center of the bounding box.
      返回:
      the center's z coordinate
    • getCenter

      @NotNull public @NotNull Vector getCenter()
      Gets the center of the bounding box.
      返回:
      the center
    • copy

      Copies another bounding box.
      参数:
      other - the other bounding box
      返回:
      this bounding box
    • expand

      @NotNull public @NotNull 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.

      参数:
      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
      返回:
      this bounding box (now expanded)
    • expand

      @NotNull public @NotNull BoundingBox expand(double x, double y, double z)
      Expands 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.

      参数:
      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
      返回:
      this bounding box (now expanded)
    • expand

      @NotNull public @NotNull BoundingBox expand(@NotNull @NotNull Vector expansion)
      Expands 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.

      参数:
      expansion - the expansion values
      返回:
      this bounding box (now expanded)
    • expand

      @NotNull public @NotNull BoundingBox expand(double expansion)
      Expands 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.

      参数:
      expansion - the amount of expansion
      返回:
      this bounding box (now expanded)
    • expand

      @NotNull public @NotNull BoundingBox expand(double dirX, double dirY, double dirZ, double expansion)
      Expands 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.

      参数:
      dirX - the x direction component
      dirY - the y direction component
      dirZ - the z direction component
      expansion - the amount of expansion
      返回:
      this bounding box (now expanded)
    • expand

      @NotNull public @NotNull BoundingBox expand(@NotNull @NotNull Vector direction, double expansion)
      Expands 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.

      参数:
      direction - the direction
      expansion - the amount of expansion
      返回:
      this bounding box (now expanded)
    • expand

      @NotNull public @NotNull BoundingBox expand(@NotNull @NotNull BlockFace blockFace, double expansion)
      Expands 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.

      参数:
      blockFace - the block face
      expansion - the amount of expansion
      返回:
      this bounding box (now expanded)
    • expandDirectional

      @NotNull public @NotNull BoundingBox expandDirectional(double dirX, double dirY, double dirZ)
      Expands 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.

      参数:
      dirX - the x direction component
      dirY - the y direction component
      dirZ - the z direction component
      返回:
      this bounding box (now expanded)
    • expandDirectional

      @NotNull public @NotNull BoundingBox expandDirectional(@NotNull @NotNull Vector direction)
      Expands 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.

      参数:
      direction - the direction and magnitude of the expansion
      返回:
      this bounding box (now expanded)
    • union

      @NotNull public @NotNull BoundingBox union(double posX, double posY, double posZ)
      Expands this bounding box to contain (or border) the specified position.
      参数:
      posX - the x position value
      posY - the y position value
      posZ - the z position value
      返回:
      this bounding box (now expanded)
      另请参阅:
    • union

      Expands this bounding box to contain (or border) the specified position.
      参数:
      position - the position
      返回:
      this bounding box (now expanded)
      另请参阅:
    • union

      Expands this bounding box to contain (or border) the specified position.
      参数:
      position - the position
      返回:
      this bounding box (now expanded)
      另请参阅:
    • union

      Expands this bounding box to contain both this and the given bounding box.
      参数:
      other - the other bounding box
      返回:
      this bounding box (now expanded)
    • intersection

      Resizes this bounding box to represent the intersection of this and the given bounding box.
      参数:
      other - the other bounding box
      返回:
      this bounding box (now representing the intersection)
      抛出:
      IllegalArgumentException - if the bounding boxes don't overlap
    • shift

      @NotNull public @NotNull BoundingBox shift(double shiftX, double shiftY, double shiftZ)
      Shifts this bounding box by the given amounts.
      参数:
      shiftX - the shift in x direction
      shiftY - the shift in y direction
      shiftZ - the shift in z direction
      返回:
      this bounding box (now shifted)
    • shift

      Shifts this bounding box by the given amounts.
      参数:
      shift - the shift
      返回:
      this bounding box (now shifted)
    • shift

      Shifts this bounding box by the given amounts.
      参数:
      shift - the shift
      返回:
      this bounding box (now shifted)
    • overlaps

      public boolean overlaps(@NotNull @NotNull BoundingBox other)
      Checks if this bounding box overlaps with the given bounding box.

      Bounding boxes that are only intersecting at the borders are not considered overlapping.

      参数:
      other - the other bounding box
      返回:
      true if overlapping
    • overlaps

      public boolean overlaps(@NotNull @NotNull Vector min, @NotNull @NotNull Vector max)
      Checks 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.

      参数:
      min - the first corner
      max - the second corner
      返回:
      true if overlapping
    • contains

      public 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.

      参数:
      x - the position's x coordinates
      y - the position's y coordinates
      z - the position's z coordinates
      返回:
      true if the bounding box contains the position
    • contains

      public boolean contains(@NotNull @NotNull Vector position)
      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.

      参数:
      position - the position
      返回:
      true if the bounding box contains the position
    • contains

      public boolean contains(@NotNull @NotNull BoundingBox other)
      Checks if this bounding box fully contains the given bounding box.
      参数:
      other - the other bounding box
      返回:
      true if the bounding box contains the given bounding box
    • contains

      public boolean contains(@NotNull @NotNull Vector min, @NotNull @NotNull Vector max)
      Checks if this bounding box fully contains the bounding box that is defined by the given corners.
      参数:
      min - the first corner
      max - the second corner
      返回:
      true if the bounding box contains the specified bounding box
    • rayTrace

      @Nullable public @Nullable RayTraceResult rayTrace(@NotNull @NotNull Vector start, @NotNull @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.

      参数:
      start - the start position
      direction - the ray direction
      maxDistance - the maximum distance
      返回:
      the ray trace hit result, or null if there is no hit
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • equals

      public boolean equals(Object obj)
      覆盖:
      equals 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • clone

      @NotNull public @NotNull BoundingBox clone()
      Creates a copy of this bounding box.
      覆盖:
      clone 在类中 Object
      返回:
      the cloned bounding box
    • serialize

      @NotNull public @NotNull Map<String,Object> serialize()
      从接口复制的说明: ConfigurationSerializable
      Creates a Map representation of this class.

      This class must provide a method to restore this class, as defined in the ConfigurationSerializable interface javadocs.

      指定者:
      serialize 在接口中 ConfigurationSerializable
      返回:
      Map containing the current state of this class
    • deserialize

      @NotNull public static @NotNull BoundingBox deserialize(@NotNull @NotNull Map<String,Object> args)