summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-01-07 10:32:36 +0000
committerDinnerbone <dinnerbone@dinnerbone.com>2011-01-07 10:33:29 +0000
commitd82b900597311ded168111fe887dde9694b9f625 (patch)
tree9c2b4bca40d62d50e083820f630d7c4c7f37041a /src
parent5d2a8ae74c73970bb94682d39d8dad8161657bfa (diff)
downloadbukkit-d82b900597311ded168111fe887dde9694b9f625.tar
bukkit-d82b900597311ded168111fe887dde9694b9f625.tar.gz
bukkit-d82b900597311ded168111fe887dde9694b9f625.tar.lz
bukkit-d82b900597311ded168111fe887dde9694b9f625.tar.xz
bukkit-d82b900597311ded168111fe887dde9694b9f625.zip
Some BlockFace improvements
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/Block.java40
-rw-r--r--src/main/java/org/bukkit/BlockFace.java10
2 files changed, 49 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/Block.java b/src/main/java/org/bukkit/Block.java
index 8909de4d..63cabda8 100644
--- a/src/main/java/org/bukkit/Block.java
+++ b/src/main/java/org/bukkit/Block.java
@@ -12,14 +12,34 @@ public interface Block {
byte getData();
/**
- * Gets the block at the given face
+ * Gets the block at the given face<br />
+ * <br />
+ * This method is equal to getFace(face, 1)
*
* @param face Face of this block to return
* @return Block at the given face
+ * @see Block.getFace(BlockFace face, int distance);
*/
Block getFace(BlockFace face);
/**
+ * Gets the block at the given distance of the given face<br />
+ * <br />
+ * For example, the following method places water at 100,102,100; two blocks
+ * above 100,100,100.
+ * <pre>
+ * Block block = world.getBlockAt(100,100,100);
+ * Block shower = block.getFace(BlockFace.Up, 2);
+ * shower.setType(Material.WATER);
+ * </pre>
+ *
+ * @param face Face of this block to return
+ * @param distance Distance to get the block at
+ * @return Block at the given face
+ */
+ Block getFace(BlockFace face, int distance);
+
+ /**
* Gets the block at the given offsets
*
* @param modX X-coordinate offset
@@ -105,4 +125,22 @@ public interface Block {
* @param type Type-ID to change this block to
*/
void setTypeID(int type);
+
+ /**
+ * Gets the face relation of this block compared to the given block<br />
+ * <br />
+ * For example:
+ * <pre>
+ * Block current = world.getBlockAt(100, 100, 100);
+ * Block target = world.getBlockAt(100, 101, 100);
+ *
+ * current.getFace(target) == BlockFace.Up;
+ * </pre>
+ * <br />
+ * If the given block is not connected to this block, null may be returned
+ *
+ * @param block Block to compare against this block
+ * @return BlockFace of this block which has the requested block, or null
+ */
+ BlockFace getFace(Block block);
}
diff --git a/src/main/java/org/bukkit/BlockFace.java b/src/main/java/org/bukkit/BlockFace.java
index aba16cbf..12eb2c54 100644
--- a/src/main/java/org/bukkit/BlockFace.java
+++ b/src/main/java/org/bukkit/BlockFace.java
@@ -10,6 +10,10 @@ public enum BlockFace {
West(0, 0, 1),
Up(0, 1, 0),
Down(0, -1, 0),
+ NorthEast(North, East),
+ NorthWest(North, West),
+ SouthEast(South, East),
+ SouthWest(South, West),
Self(0, 0, 0);
private final int modX;
@@ -22,6 +26,12 @@ public enum BlockFace {
this.modZ = modZ;
}
+ private BlockFace(final BlockFace face1, final BlockFace face2) {
+ this.modX = face1.getModX() + face2.getModX();
+ this.modY = face1.getModY() + face2.getModY();
+ this.modZ = face1.getModZ() + face2.getModZ();
+ }
+
/**
* Get the amount of X-coordinates to modify to get the represented block
* @return Amount of X-coordinates to modify