diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-07 16:26:06 +0000 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-07 16:26:06 +0000 |
commit | 08a62e37acd26f883980ed025f15f5b6745095d3 (patch) | |
tree | 3cf486a83330be75ee07cd46f5ecd39000b89b29 /src/main | |
parent | 1edd1fa0cac56460ae4cd8808e6a3e2bee0b399f (diff) | |
download | craftbukkit-08a62e37acd26f883980ed025f15f5b6745095d3.tar craftbukkit-08a62e37acd26f883980ed025f15f5b6745095d3.tar.gz craftbukkit-08a62e37acd26f883980ed025f15f5b6745095d3.tar.lz craftbukkit-08a62e37acd26f883980ed025f15f5b6745095d3.tar.xz craftbukkit-08a62e37acd26f883980ed025f15f5b6745095d3.zip |
Implemented CraftBlockState
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftBlock.java | 6 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java | 146 |
2 files changed, 152 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/CraftBlock.java index e706951e..204a25eb 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftBlock.java @@ -2,6 +2,8 @@ package org.bukkit.craftbukkit; import org.bukkit.*; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.block.CraftBlockState; public class CraftBlock implements Block { private final CraftWorld world; @@ -249,4 +251,8 @@ public class CraftBlock implements Block { return BlockFace.Self; } } + + public BlockState getState() { + return new CraftBlockState(world, x, y, z, type, data); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java new file mode 100644 index 00000000..b5320468 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -0,0 +1,146 @@ + +package org.bukkit.craftbukkit.block; + +import org.bukkit.Block; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.CraftChunk; +import org.bukkit.craftbukkit.CraftWorld; + +public class CraftBlockState implements BlockState { + private final CraftWorld world; + private final CraftChunk chunk; + private final int x; + private final int y; + private final int z; + protected int type; + protected byte data; + protected byte light; + + public CraftBlockState(final CraftWorld world, final int x, final int y, final int z, final int type, final byte data) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.type = type; + this.data = data; + this.light = (byte)world.getHandle().i(x, y, z); + this.chunk = (CraftChunk)world.getChunkAt(x << 4, z << 4); + } + + /** + * Gets the world which contains this Block + * + * @return World containing this block + */ + public World getWorld() { + return world; + } + + /** + * Gets the x-coordinate of this block + * + * @return x-coordinate + */ + public int getX() { + return x; + } + + /** + * Gets the y-coordinate of this block + * + * @return y-coordinate + */ + public int getY() { + return y; + } + + /** + * Gets the z-coordinate of this block + * + * @return z-coordinate + */ + public int getZ() { + return z; + } + + /** + * Gets the chunk which contains this block + * + * @return Containing Chunk + */ + public Chunk getChunk() { + return chunk; + } + + /** + * Sets the metadata for this block + * + * @param data New block specific metadata + */ + public void setData(final byte data) { + this.data = data; + world.getHandle().c(x, y, z, data); + } + + /** + * Gets the metadata for this block + * + * @return block specific metadata + */ + public byte getData() { + return data; + } + + /** + * Sets the type of this block + * + * @param type Material to change this block to + */ + public void setType(final Material type) { + setTypeID(type.getID()); + } + + /** + * Sets the type-ID of this block + * + * @param type Type-ID to change this block to + */ + public void setTypeID(final int type) { + this.type = type; + world.getHandle().d(x, y, z, type); + } + + /** + * Gets the type of this block + * + * @return block type + */ + public Material getType() { + return Material.getMaterial(getTypeID()); + } + + /** + * Gets the type-ID of this block + * + * @return block type-ID + */ + public int getTypeID() { + return type; + } + + /** + * Gets the light level between 0-15 + * + * @return light level + */ + public byte getLightLevel() { + return light; + } + + public Block getBlock() { + return world.getBlockAt(x, y, z); + } +} |