com.quartercode.quarterbukkit.api
Class Cuboid

java.lang.Object
  extended by com.quartercode.quarterbukkit.api.Cuboid

public class Cuboid
extends java.lang.Object

This class represents a cuboid between to different locations saved as Vectors.

The cuboid can't get modified after construction, so it's final. You can only read values in different ways.

All constructors delivers their cooridnates to Cuboid(double, double, double, double, double, double) which sorts them to a larger and a smaller Vector. This will lose the original locations, but you can work better with the data later on.

getVector1() returns the larger one, getVector2() the smaller one. You can also read those values by using the getXXX1() and getXXX2() methods.

Here's an example how the sorting works: We have two locations with the coordinates 5, 10, 7 and 12, 6, 18, the Vectors will be the larger one 12, 10, 18 and the smaller one 5, 6, 7.


Constructor Summary
Cuboid(double x1, double y1, double z1, double x2, double y2, double z2)
           Creates a new cuboid out of two locations given by six doubles, three for each location.
Cuboid(org.bukkit.Location location1, org.bukkit.Location location2)
           Creates a new cuboid out of two locations given by two Locations.
Cuboid(org.bukkit.util.Vector vector1, org.bukkit.util.Vector vector2)
           Creates a new cuboid out of two locations given by two Vectors.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 org.bukkit.util.Vector getBlockCenter()
           This method returns the center position of the cuboid as a block location by subtracting the half of every distance from every larger coordinate and calculating the block location of every result coordinate.
 java.util.List<org.bukkit.util.Vector> getBlocks()
           This method returns a list of all blocks which are located in the cuboid as a list of Vectors.
 int getBlockX1()
           This method returns the larger x-coordinate of both locations as a block location.
 int getBlockX2()
           This method returns the smaller x-coordinate of both locations as a block location.
 double getBlockXDistance()
           This method returns the distance between the two x-block-coordinates (you can use this to get the distance between the two x-walls as a block-value) by subtracting the smaller from the larger one and round.
 int getBlockY1()
           This method returns the larger y-coordinate of both locations as a block location.
 int getBlockY2()
           This method returns the smaller y-coordinate of both locations as a block location.
 double getBlockYDistance()
           This method returns the distance between the two y-block-coordinates (you can use this to get the distance between the two y-walls as a block-value) by subtracting the smaller from the larger one and round.
 int getBlockZ1()
           This method returns the larger z-coordinate of both locations as a block location.
 int getBlockZ2()
           This method returns the smaller z-coordinate of both locations as a block location.
 double getBlockZDistance()
           This method returns the distance between the two z-block-coordinates (you can use this to get the distance between the two z-walls as a block-value) by subtracting the smaller from the larger one and round.
 org.bukkit.util.Vector getCenter()
           This method returns the center position of the cuboid by subtracting the half of every distance from every larger coordinate.
 org.bukkit.util.Vector getVector1()
           This method returns the first cuboid Vector with the larger coordinates.
 org.bukkit.util.Vector getVector2()
           This method returns the second cuboid Vector with the smaller coordinates.
 double getX1()
           This method returns the larger x-coordinate of both locations.
 double getX2()
           This method returns the smaller x-coordinate of both locations.
 double getXDistance()
           This method returns the distance between the two x-coordinates (you can use this to get the distance between the two x-walls) by subtracting the smaller from the larger one.
 double getY1()
           This method returns the larger y-coordinate of both locations.
 double getY2()
           This method returns the smaller y-coordinate of both locations.
 double getYDistance()
           This method returns the distance between the two y-coordinates (you can use this to get the distance between the two y-walls) by subtracting the smaller from the larger one.
 double getZ1()
           This method returns the larger z-coordinate of both locations.
 double getZ2()
           This method returns the smaller z-coordinate of both locations.
 double getZDistance()
           This method returns the distance between the two z-coordinates (you can use this to get the distance between the two z-walls) by subtracting the smaller from the larger one.
 int hashCode()
           
 boolean intersects(double x, double y, double z)
           This method checks if an other location actually intersects with the cuboid.
 boolean intersects(org.bukkit.Location location)
           This method checks if an other location actually intersects with the cuboid.
 boolean intersects(org.bukkit.util.Vector vector)
           This method checks if an other location actually intersects with the cuboid.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cuboid

public Cuboid(double x1,
              double y1,
              double z1,
              double x2,
              double y2,
              double z2)

Creates a new cuboid out of two locations given by six doubles, three for each location.

This constructor sorts the coordinates to a larger and a smaller Vector. The larger one contains all the larger values, the smaller one contains all coordinates with the smaller values. This will lose the original locations, but you can work better with the data later on.

Here's an example how the sorting works: We have two locations with the coordinates 5, 10, 7 and 12, 6, 18, the Vectors will be the larger one 12, 10, 18 and the smaller one 5, 6, 7.

Parameters:
x1 - The x-coordinate for the first location.
y1 - The y-coordinate for the first location.
z1 - The z-coordinate for the first location.
x2 - The x-coordinate for the second location.
y2 - The y-coordinate for the second location.
z2 - The z-coordinate for the second location,

Cuboid

public Cuboid(org.bukkit.util.Vector vector1,
              org.bukkit.util.Vector vector2)

Creates a new cuboid out of two locations given by two Vectors.

This constructor sorts the coordinates to a larger and a smaller Vector. The larger one contains all the larger values, the smaller one contains all coordinates with the smaller values. This will lose the original locations, but you can work better with the data later on.

Here's an example how the sorting works: We have two locations with the coordinates 5, 10, 7 and 12, 6, 18, the Vectors will be the larger one 12, 10, 18 and the smaller one 5, 6, 7.

Parameters:
vector1 - The Vector for the first location.
vector2 - The Vector for the second location.

Cuboid

public Cuboid(org.bukkit.Location location1,
              org.bukkit.Location location2)

Creates a new cuboid out of two locations given by two Locations.

This constructor sorts the coordinates to a larger and a smaller Vector. The larger one contains all the larger values, the smaller one contains all coordinates with the smaller values. This will lose the original locations, but you can work better with the data later on.

Here's an example how the sorting works: We have two locations with the coordinates 5, 10, 7 and 12, 6, 18, the Vectors will be the larger one 12, 10, 18 and the smaller one 5, 6, 7.

Parameters:
location1 - The Location for the first location.
location2 - The Location for the second location.
Method Detail

getVector1

public org.bukkit.util.Vector getVector1()

This method returns the first cuboid Vector with the larger coordinates.

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the one with the larger values.

Returns:
The first cuboid Vector with the larger coordinates.

getVector2

public org.bukkit.util.Vector getVector2()

This method returns the second cuboid Vector with the smaller coordinates.

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the one with the smaller values.

Returns:
The second cuboid Vector with the smaller coordinates.

getX1

public double getX1()

This method returns the larger x-coordinate of both locations. You could also use the Vector.getX()-method of the Vector you're getting by getVector1().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the x-coordinate of the one with the larger values.

Returns:
The larger x-coordinate of both locations.

getBlockX1

public int getBlockX1()

This method returns the larger x-coordinate of both locations as a block location. You could also use the Vector.getBlockX()-method of the Vector you're getting by getVector1().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the x-coordinate of the one with the larger values as a block location.

Returns:
The larger x-coordinate of both locations as a block location.

getY1

public double getY1()

This method returns the larger y-coordinate of both locations. You could also use the Vector.getY()-method of the Vector you're getting by getVector1().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the y-coordinate of the one with the larger values.

Returns:
The larger y-coordinate of both locations.

getBlockY1

public int getBlockY1()

This method returns the larger y-coordinate of both locations as a block location. You could also use the Vector.getBlockY()-method of the Vector you're getting by getVector1().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the y-coordinate of the one with the larger values as a block location.

Returns:
The larger y-coordinate of both locations as a block location.

getZ1

public double getZ1()

This method returns the larger z-coordinate of both locations. You could also use the Vector.getZ()-method of the Vector you're getting by getVector1().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the z-coordinate of the one with the larger values.

Returns:
The larger z-coordinate of both locations.

getBlockZ1

public int getBlockZ1()

This method returns the larger z-coordinate of both locations as a block location. You could also use the Vector.getBlockZ()-method of the Vector you get by getVector1().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the z-coordinate of the one with the larger values as a block location.

Returns:
The larger z-coordinate of both locations as a block location.

getX2

public double getX2()

This method returns the smaller x-coordinate of both locations. You could also use the Vector.getX()-method of the Vector you're getting by getVector2().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the x-coordinate of the one with the smaller values.

Returns:
The smaller x-coordinate of both locations.

getBlockX2

public int getBlockX2()

This method returns the smaller x-coordinate of both locations as a block location. You could also use the Vector.getBlockX()-method of the Vector you get by getVector2().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the x-coordinate of the one with the smaller values as a block location.

Returns:
The smaller x-coordinate of both locations as a block location.

getY2

public double getY2()

This method returns the smaller y-coordinate of both locations. You could also use the Vector.getY()-method of the Vector you're getting by getVector2().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the y-coordinate of the one with the smaller values.

Returns:
The smaller y-coordinate of both locations.

getBlockY2

public int getBlockY2()

This method returns the smaller y-coordinate of both locations as a block location. You could also use the Vector.getBlockY()-method of the Vector you get by getVector2().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the y-coordinate of the one with the smaller values as a block location.

Returns:
The smaller y-coordinate of both locations as a block location.

getZ2

public double getZ2()

This method returns the smaller z-coordinate of both locations. You could also use the Vector.getZ()-method of the Vector you're getting by getVector2().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the z-coordinate of the one with the smaller values.

Returns:
The smaller z-coordinate of both locations.

getBlockZ2

public int getBlockZ2()

This method returns the smaller z-coordinate of both locations as a block location. You could also use the Vector.getBlockX()-method of the Vector you get by getVector2().

The save Vectors aren't the input locations, the coordinates of both locations are sorted into one with the larger and one with the smaller ones. This will returns the z-coordinate of the one with the smaller values as a block location.

Returns:
The smaller z-coordinate of both locations as a block location.

getXDistance

public double getXDistance()

This method returns the distance between the two x-coordinates (you can use this to get the distance between the two x-walls) by subtracting the smaller from the larger one. This will always return a positive distance.

Returns:
The distance between the two x-coordinates (you can use this to get the distance between the two x-walls).

getBlockXDistance

public double getBlockXDistance()

This method returns the distance between the two x-block-coordinates (you can use this to get the distance between the two x-walls as a block-value) by subtracting the smaller from the larger one and round. This will always return a positive distance.

Returns:
The distance between the two x-block-coordinates (you can use this to get the distance between the two x-walls as a block-value).

getYDistance

public double getYDistance()

This method returns the distance between the two y-coordinates (you can use this to get the distance between the two y-walls) by subtracting the smaller from the larger one. This will always return a positive distance.

Returns:
The distance between the two y-coordinates (you can use this to get the distance between the two y-walls).

getBlockYDistance

public double getBlockYDistance()

This method returns the distance between the two y-block-coordinates (you can use this to get the distance between the two y-walls as a block-value) by subtracting the smaller from the larger one and round. This will always return a positive distance.

Returns:
The distance between the two y-block-coordinates (you can use this to get the distance between the two y-walls as a block-value).

getZDistance

public double getZDistance()

This method returns the distance between the two z-coordinates (you can use this to get the distance between the two z-walls) by subtracting the smaller from the larger one. This will always return a positive distance.

Returns:
The distance between the two z-coordinates (you can use this to get the distance between the two z-walls).

getBlockZDistance

public double getBlockZDistance()

This method returns the distance between the two z-block-coordinates (you can use this to get the distance between the two z-walls as a block-value) by subtracting the smaller from the larger one and round. This will always return a positive distance.

Returns:
The distance between the two z-block-coordinates (you can use this to get the distance between the two z-walls as a block-value).

getCenter

public org.bukkit.util.Vector getCenter()

This method returns the center position of the cuboid by subtracting the half of every distance from every larger coordinate. You can use this to get the center of gravity of the cuboid.

Returns:
The center position of the cuboid.

getBlockCenter

public org.bukkit.util.Vector getBlockCenter()

This method returns the center position of the cuboid as a block location by subtracting the half of every distance from every larger coordinate and calculating the block location of every result coordinate. You can use this to get the center of gravity of the cuboid as a block location.

Returns:
The center position of the cuboid as a block location.

intersects

public boolean intersects(double x,
                          double y,
                          double z)

This method checks if an other location actually intersects with the cuboid. The location is given by three doubles representing the x-, y- and z-coordinate and returning the result as a boolean.

There will only be a positive result if all coordinates are intersecting the cuboid.

Parameters:
x - The x-coordinate for checking if it's intersecting the cuboid.
y - The y-coordinate for checking if it's intersecting the cuboid.
z - The z-coordinate for checking if it's intersecting the cuboid.
Returns:
If the other location actually intersects with the cuboid.

intersects

public boolean intersects(org.bukkit.util.Vector vector)

This method checks if an other location actually intersects with the cuboid. The location is given by a Vector and returning the result as a boolean.

There will only be a positive result if all coordinates of the Vector are intersecting the cuboid.

Parameters:
vector - The Vector for checking if it's intersecting the cuboid.
Returns:
If the other location actually intersects with the cuboid.

intersects

public boolean intersects(org.bukkit.Location location)

This method checks if an other location actually intersects with the cuboid. The location is given by a Location and returning the result as a boolean.

There will only be a positive result if all coordinates of the Location are intersecting the cuboid.

Parameters:
location - The Location for checking if it's intersecting the cuboid.
Returns:
If the other location actually intersects with the cuboid.

getBlocks

public java.util.List<org.bukkit.util.Vector> getBlocks()

This method returns a list of all blocks which are located in the cuboid as a list of Vectors.

You can iterate over the list and doing anything you want with the blocks like this:

 for (Vector vector : getBlocks()) {
     vector.toLocation(world).getBlock()...
 }
 

Returns:
A list of all blocks which are located in the cuboid as a list of Vectors.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object