Package fr.maxlego08.zshop.zcore.utils
Class Cuboid
java.lang.Object
fr.maxlego08.zshop.zcore.utils.Cuboid
- All Implemented Interfaces:
Cloneable,Iterable<org.bukkit.block.Block>,org.bukkit.configuration.serialization.ConfigurationSerializable
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCopy constructor.Construct a Cuboid using a map with the following keys: worldName, x1, x2, y1, y2, z1, z2Cuboid(org.bukkit.Location l1) Construct a one-block Cuboid at the given Location of the Cuboid.Cuboid(org.bukkit.Location l1, org.bukkit.Location l2) Construct a Cuboid given two Location objects which represent any two corners of the Cuboid.Cuboid(org.bukkit.World world, int x1, int y1, int z1, int x2, int y2, int z2) Construct a Cuboid in the given World and xyz co-ordinates -
Method Summary
Modifier and TypeMethodDescriptionclone()booleancontains(int x, int y, int z) Return true if the point at (x,y,z) is contained within this Cuboid.booleancontains(org.bukkit.block.Block b) Check if the given Block is contained within this Cuboid.booleancontains(org.bukkit.Location l) Check if the given Location is contained within this Cuboid.booleancontainsOnly(int blockId) Check if the Cuboid contains only blocks of the given typecontract()Contract the Cuboid, returning a Cuboid with any air around the edges removed, just large enough to include all non-air blocks.Contract the Cuboid in the given direction, returning a new Cuboid which has no exterior empty space.org.bukkit.block.Block[]corners()Get the Blocks at the eight corners of the Cuboid.expand(Cuboid.CuboidDirection dir, int amount) Expand the Cuboid in the given direction by the given amount.byteGet the average light level of all empty (air) blocks in the Cuboid.List<org.bukkit.block.Block>Get the blocks in the Cuboid.List<org.bukkit.block.Block>getBlocks(org.bukkit.Material material) Get the blocks in the Cuboid.getBoundingCuboid(Cuboid other) Get the Cuboid big enough to hold both this Cuboid and the given one.org.bukkit.LocationGet the the centre of the Cuboid.List<org.bukkit.Chunk>Get a list of the chunks which are fully or partially contained in this cuboid.Get the Cuboid representing the face of this Cuboid.org.bukkit.LocationGet the Location of the lower northeast corner of the Cuboid (minimum XYZ co-ordinates).intGet the minimum X co-ordinate of this CuboidintGet the minimum Y co-ordinate of this CuboidintGet the minimum Z co-ordinate of this Cuboidorg.bukkit.block.BlockgetRelativeBlock(int x, int y, int z) Get a block relative to the lower NE point of the Cuboid.org.bukkit.block.BlockgetRelativeBlock(org.bukkit.World w, int x, int y, int z) Get a block relative to the lower NE point of the Cuboid in the given World.intgetSizeX()Get the size of this Cuboid along the X axisintgetSizeY()Get the size of this Cuboid along the Y axisintgetSizeZ()Get the size of this Cuboid along the Z axisorg.bukkit.LocationGet the Location of the upper southwest corner of the Cuboid (maximum XYZ co-ordinates).intGet the maximum X co-ordinate of this CuboidintGet the maximum Y co-ordinate of this CuboidintGet the maximum Z co-ordinate of this CuboidintGet the volume of this Cuboid.org.bukkit.WorldgetWorld()Get the Cuboid's world.inset(Cuboid.CuboidDirection dir, int amount) Inset (shrink) the Cuboid in the given direction by the given amount.Iterator<org.bukkit.block.Block>iterator()outset(Cuboid.CuboidDirection dir, int amount) Outset (grow) the Cuboid in the given direction by the given amount.shift(Cuboid.CuboidDirection dir, int amount) Shift the Cuboid in the given direction by the given amount.toString()Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
worldName
This class is a region/cuboid from one location to another. It can be used for blocks protection and things like WorldEdit. -
x1
protected final int x1 -
y1
protected final int y1 -
z1
protected final int z1 -
x2
protected final int x2 -
y2
protected final int y2 -
z2
protected final int z2
-
-
Constructor Details
-
Cuboid
public Cuboid(org.bukkit.Location l1, org.bukkit.Location l2) Construct a Cuboid given two Location objects which represent any two corners of the Cuboid. Note: The 2 locations must be on the same world.- Parameters:
l1- - One of the cornersl2- - The other corner
-
Cuboid
public Cuboid(org.bukkit.Location l1) Construct a one-block Cuboid at the given Location of the Cuboid.- Parameters:
l1- location of the Cuboid
-
Cuboid
Copy constructor.- Parameters:
other- - The Cuboid to copy
-
Cuboid
public Cuboid(org.bukkit.World world, int x1, int y1, int z1, int x2, int y2, int z2) Construct a Cuboid in the given World and xyz co-ordinates- Parameters:
world- - The Cuboid's worldx1- - X co-ordinate of corner 1y1- - Y co-ordinate of corner 1z1- - Z co-ordinate of corner 1x2- - X co-ordinate of corner 2y2- - Y co-ordinate of corner 2z2- - Z co-ordinate of corner 2
-
Cuboid
Construct a Cuboid using a map with the following keys: worldName, x1, x2, y1, y2, z1, z2- Parameters:
map- - The map of keys.
-
-
Method Details
-
serialize
- Specified by:
serializein interfaceorg.bukkit.configuration.serialization.ConfigurationSerializable
-
getLowerNE
public org.bukkit.Location getLowerNE()Get the Location of the lower northeast corner of the Cuboid (minimum XYZ co-ordinates).- Returns:
- Location of the lower northeast corner
-
getUpperSW
public org.bukkit.Location getUpperSW()Get the Location of the upper southwest corner of the Cuboid (maximum XYZ co-ordinates).- Returns:
- Location of the upper southwest corner
-
getBlocks
Get the blocks in the Cuboid.- Returns:
- The blocks in the Cuboid
-
getBlocks
Get the blocks in the Cuboid.- Returns:
- The blocks in the Cuboid
-
getCenter
public org.bukkit.Location getCenter()Get the the centre of the Cuboid.- Returns:
- Location at the centre of the Cuboid
-
getWorld
public org.bukkit.World getWorld()Get the Cuboid's world.- Returns:
- The World object representing this Cuboid's world
- Throws:
IllegalStateException- if the world is not loaded
-
getSizeX
public int getSizeX()Get the size of this Cuboid along the X axis- Returns:
- Size of Cuboid along the X axis
-
getSizeY
public int getSizeY()Get the size of this Cuboid along the Y axis- Returns:
- Size of Cuboid along the Y axis
-
getSizeZ
public int getSizeZ()Get the size of this Cuboid along the Z axis- Returns:
- Size of Cuboid along the Z axis
-
getLowerX
public int getLowerX()Get the minimum X co-ordinate of this Cuboid- Returns:
- the minimum X co-ordinate
-
getLowerY
public int getLowerY()Get the minimum Y co-ordinate of this Cuboid- Returns:
- the minimum Y co-ordinate
-
getLowerZ
public int getLowerZ()Get the minimum Z co-ordinate of this Cuboid- Returns:
- the minimum Z co-ordinate
-
getUpperX
public int getUpperX()Get the maximum X co-ordinate of this Cuboid- Returns:
- the maximum X co-ordinate
-
getUpperY
public int getUpperY()Get the maximum Y co-ordinate of this Cuboid- Returns:
- the maximum Y co-ordinate
-
getUpperZ
public int getUpperZ()Get the maximum Z co-ordinate of this Cuboid- Returns:
- the maximum Z co-ordinate
-
corners
public org.bukkit.block.Block[] corners()Get the Blocks at the eight corners of the Cuboid.- Returns:
- array of Block objects representing the Cuboid corners
-
expand
Expand the Cuboid in the given direction by the given amount. Negative amounts will shrink the Cuboid in the given direction. Shrinking a cuboid's face past the opposite face is not an error and will return a valid Cuboid.- Parameters:
dir- - The direction in which to expandamount- - The number of blocks by which to expand- Returns:
- A new Cuboid expanded by the given direction and amount
-
shift
Shift the Cuboid in the given direction by the given amount.- Parameters:
dir- - The direction in which to shiftamount- - The number of blocks by which to shift- Returns:
- A new Cuboid shifted by the given direction and amount
-
outset
Outset (grow) the Cuboid in the given direction by the given amount.- Parameters:
dir- - The direction in which to outset (must be Horizontal, Vertical, or Both)amount- - The number of blocks by which to outset- Returns:
- A new Cuboid outset by the given direction and amount
-
inset
Inset (shrink) the Cuboid in the given direction by the given amount. Equivalent to calling outset() with a negative amount.- Parameters:
dir- - The direction in which to inset (must be Horizontal, Vertical, or Both)amount- - The number of blocks by which to inset- Returns:
- A new Cuboid inset by the given direction and amount
-
contains
public boolean contains(int x, int y, int z) Return true if the point at (x,y,z) is contained within this Cuboid.- Parameters:
x- - The X co-ordinatey- - The Y co-ordinatez- - The Z co-ordinate- Returns:
- true if the given point is within this Cuboid, false otherwise
-
contains
public boolean contains(org.bukkit.block.Block b) Check if the given Block is contained within this Cuboid.- Parameters:
b- - The Block to check for- Returns:
- true if the Block is within this Cuboid, false otherwise
-
contains
public boolean contains(org.bukkit.Location l) Check if the given Location is contained within this Cuboid.- Parameters:
l- - The Location to check for- Returns:
- true if the Location is within this Cuboid, false otherwise
-
getVolume
public int getVolume()Get the volume of this Cuboid.- Returns:
- The Cuboid volume, in blocks
-
getAverageLightLevel
public byte getAverageLightLevel()Get the average light level of all empty (air) blocks in the Cuboid. Returns 0 if there are no empty blocks.- Returns:
- The average light level of this Cuboid
-
contract
Contract the Cuboid, returning a Cuboid with any air around the edges removed, just large enough to include all non-air blocks.- Returns:
- A new Cuboid with no external air blocks
-
contract
Contract the Cuboid in the given direction, returning a new Cuboid which has no exterior empty space. E.g. A direction of Down will push the top face downwards as much as possible.- Parameters:
dir- - The direction in which to contract- Returns:
- A new Cuboid contracted in the given direction
-
getFace
Get the Cuboid representing the face of this Cuboid. The resulting Cuboid will be one block thick in the axis perpendicular to the requested face.- Parameters:
dir- - which face of the Cuboid to get- Returns:
- The Cuboid representing this Cuboid's requested face
-
containsOnly
public boolean containsOnly(int blockId) Check if the Cuboid contains only blocks of the given type- Parameters:
blockId- - The block ID to check for- Returns:
- true if this Cuboid contains only blocks of the given type
-
getBoundingCuboid
Get the Cuboid big enough to hold both this Cuboid and the given one.- Parameters:
other- - The other cuboid.- Returns:
- A new Cuboid large enough to hold this Cuboid and the given Cuboid
-
getRelativeBlock
public org.bukkit.block.Block getRelativeBlock(int x, int y, int z) Get a block relative to the lower NE point of the Cuboid.- Parameters:
x- - The X co-ordinatey- - The Y co-ordinatez- - The Z co-ordinate- Returns:
- The block at the given position
-
getRelativeBlock
public org.bukkit.block.Block getRelativeBlock(org.bukkit.World w, int x, int y, int z) Get a block relative to the lower NE point of the Cuboid in the given World. This version of getRelativeBlock() should be used if being called many times, to avoid excessive calls to getWorld().- Parameters:
w- - The worldx- - The X co-ordinatey- - The Y co-ordinatez- - The Z co-ordinate- Returns:
- The block at the given position
-
getChunks
Get a list of the chunks which are fully or partially contained in this cuboid.- Returns:
- A list of Chunk objects
-
iterator
-
clone
-
toString
-