summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-01-07 10:43:51 +0000
committerDinnerbone <dinnerbone@dinnerbone.com>2011-01-07 10:43:51 +0000
commit14b929f382a3d458021f2b36b9ae067a8fe95fc0 (patch)
treec005c185d0ab32cc732b061f4f31e291a6a9e14e /src/main/java/org/bukkit
parent7d12239ab7efaf1e79606f987136deed7c8e73c5 (diff)
downloadcraftbukkit-14b929f382a3d458021f2b36b9ae067a8fe95fc0.tar
craftbukkit-14b929f382a3d458021f2b36b9ae067a8fe95fc0.tar.gz
craftbukkit-14b929f382a3d458021f2b36b9ae067a8fe95fc0.tar.lz
craftbukkit-14b929f382a3d458021f2b36b9ae067a8fe95fc0.tar.xz
craftbukkit-14b929f382a3d458021f2b36b9ae067a8fe95fc0.zip
Added block.getFace(Block) and block.getFace(BlockFace, int)
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftBlock.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/CraftBlock.java
index 19dce3c7..4048434a 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftBlock.java
@@ -157,6 +157,26 @@ public class CraftBlock implements Block {
}
/**
+ * 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
+ */
+ public Block getFace(final BlockFace face, final int distance) {
+ return getRelative(face.getModX() * distance, face.getModY() * distance,
+ face.getModZ() * distance);
+ }
+
+ /**
* Gets the block at the given offsets
*
* @param modX X-coordinate offset
@@ -168,6 +188,38 @@ public class CraftBlock implements Block {
return getWorld().getBlockAt(getX() + modX, getY() + modY, getZ() + modZ);
}
+ /**
+ * 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
+ */
+ public BlockFace getFace(final Block block) {
+ BlockFace[] values = BlockFace.values();
+
+ for (BlockFace face : values) {
+ if (
+ (this.getX() + face.getModX() == block.getX()) &&
+ (this.getY() + face.getModY() == block.getY()) &&
+ (this.getZ() + face.getModZ() == block.getZ())
+ ) {
+ return face;
+ }
+ }
+
+ return null;
+ }
+
@Override
public String toString() {
return "CraftBlock{" + "world=" + world + "x=" + x + "y=" + y + "z=" + z + "type=" + type + "data=" + data + '}';