diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/Material.java | 20 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Chest.java | 45 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/CocoaPlant.java | 117 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/EnderChest.java | 45 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Lever.java | 22 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Stairs.java | 26 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Step.java | 35 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/TexturedMaterial.java | 22 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Tree.java | 58 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Tripwire.java | 71 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/TripwireHook.java | 115 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/WoodenStep.java | 85 |
12 files changed, 640 insertions, 21 deletions
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 7ae6045f..5ea03379 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -72,7 +72,7 @@ public enum Material { FIRE(51), MOB_SPAWNER(52), WOOD_STAIRS(53, Stairs.class), - CHEST(54), + CHEST(54, Chest.class), REDSTONE_WIRE(55, RedstoneWire.class), DIAMOND_ORE(56), DIAMOND_BLOCK(57), @@ -291,18 +291,18 @@ public enum Material { RECORD_9(2264, 1), RECORD_10(2265, 1), RECORD_11(2266, 1), - WOOD_DOUBLE_STEP(125, Step.class), - WOOD_STEP(126, Step.class), - COCOA(127), + WOOD_DOUBLE_STEP(125, WoodenStep.class), + WOOD_STEP(126, WoodenStep.class), + COCOA(127, CocoaPlant.class), SANDSTONE_STAIRS(128, Stairs.class), EMERALD_ORE(129), - ENDER_CHEST(130), - TRIPWIRE_HOOK(131, Button.class), - TRIPWIRE(132), + ENDER_CHEST(130, EnderChest.class), + TRIPWIRE_HOOK(131, TripwireHook.class), + TRIPWIRE(132, Tripwire.class), EMERALD_BLOCK(133), - SPRUCE_WOOD_STAIRS(134), - BIRCH_WOOD_STAIRS(135), - JUNGLE_WOOD_STAIRS(136), + SPRUCE_WOOD_STAIRS(134, Stairs.class), + BIRCH_WOOD_STAIRS(135, Stairs.class), + JUNGLE_WOOD_STAIRS(136, Stairs.class), BOOK_AND_QUILL(386, 1), WRITTEN_BOOK(387, 1), EMERALD(388, 64); diff --git a/src/main/java/org/bukkit/material/Chest.java b/src/main/java/org/bukkit/material/Chest.java new file mode 100644 index 00000000..8b48eb19 --- /dev/null +++ b/src/main/java/org/bukkit/material/Chest.java @@ -0,0 +1,45 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; + +/** + * Represents a chest + */ +public class Chest extends FurnaceAndDispenser { + + public Chest() { + super(Material.CHEST); + } + + /** + * Instantiate a chest facing in a particular direction. + * + * @param direction the direction the chest's lit opens towards + */ + public Chest(BlockFace direction) { + this(); + setFacingDirection(direction); + } + + public Chest(final int type) { + super(type); + } + + public Chest(final Material type) { + super(type); + } + + public Chest(final int type, final byte data) { + super(type, data); + } + + public Chest(final Material type, final byte data) { + super(type, data); + } + + @Override + public Chest clone() { + return (Chest) super.clone(); + } +} diff --git a/src/main/java/org/bukkit/material/CocoaPlant.java b/src/main/java/org/bukkit/material/CocoaPlant.java new file mode 100644 index 00000000..ad19e052 --- /dev/null +++ b/src/main/java/org/bukkit/material/CocoaPlant.java @@ -0,0 +1,117 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; + +/** + * Represents the cocoa plant + */ +public class CocoaPlant extends MaterialData implements Directional { + + public enum CocoaPlantSize { + SMALL, + MEDIUM, + LARGE + } + + public CocoaPlant() { + super(Material.COCOA); + } + + public CocoaPlant(final int type) { + super(type); + } + + public CocoaPlant(final int type, final byte data) { + super(type, data); + } + + public CocoaPlant(CocoaPlantSize sz) { + this(); + setSize(sz); + } + + public CocoaPlant(CocoaPlantSize sz, BlockFace dir) { + this(); + setSize(sz); + setFacingDirection(dir); + } + + /** + * Get size of plant + * @return size + */ + public CocoaPlantSize getSize() { + switch (getData() & 0xC) { + case 0: + return CocoaPlantSize.SMALL; + case 4: + return CocoaPlantSize.MEDIUM; + default: + return CocoaPlantSize.LARGE; + } + } + + /** + * Set size of plant + * @param sz - size of plant + */ + public void setSize(CocoaPlantSize sz) { + int dat = getData() & 0x3; + switch (sz) { + case SMALL: + break; + case MEDIUM: + dat |= 0x4; + break; + case LARGE: + dat |= 0x8; + break; + } + setData((byte) dat); + } + + public void setFacingDirection(BlockFace face) { + int dat = getData() & 0xC; + switch (face) { + case WEST: + break; + case NORTH: + dat |= 0x1; + break; + case EAST: + dat |= 0x2; + break; + case SOUTH: + dat |= 0x3; + break; + default: + break; + } + setData((byte) dat); + } + + public BlockFace getFacing() { + switch (getData() & 0x3) { + case 0: + return BlockFace.WEST; + case 1: + return BlockFace.NORTH; + case 2: + return BlockFace.EAST; + case 3: + return BlockFace.SOUTH; + } + return null; + } + + @Override + public CocoaPlant clone() { + return (CocoaPlant) super.clone(); + } + + @Override + public String toString() { + return super.toString() + " facing " + getFacing() + " " + getSize(); + } +} diff --git a/src/main/java/org/bukkit/material/EnderChest.java b/src/main/java/org/bukkit/material/EnderChest.java new file mode 100644 index 00000000..f863ed92 --- /dev/null +++ b/src/main/java/org/bukkit/material/EnderChest.java @@ -0,0 +1,45 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; + +/** + * Represents an ender chest + */ +public class EnderChest extends FurnaceAndDispenser { + + public EnderChest() { + super(Material.ENDER_CHEST); + } + + /** + * Instantiate an ender chest facing in a particular direction. + * + * @param direction the direction the ender chest's lid opens towards + */ + public EnderChest(BlockFace direction) { + this(); + setFacingDirection(direction); + } + + public EnderChest(final int type) { + super(type); + } + + public EnderChest(final Material type) { + super(type); + } + + public EnderChest(final int type, final byte data) { + super(type, data); + } + + public EnderChest(final Material type, final byte data) { + super(type, data); + } + + @Override + public EnderChest clone() { + return (EnderChest) super.clone(); + } +} diff --git a/src/main/java/org/bukkit/material/Lever.java b/src/main/java/org/bukkit/material/Lever.java index 9277d77a..395b62ce 100644 --- a/src/main/java/org/bukkit/material/Lever.java +++ b/src/main/java/org/bukkit/material/Lever.java @@ -70,6 +70,11 @@ public class Lever extends SimpleAttachableMaterialData implements Redstone { case 0x5: case 0x6: return BlockFace.DOWN; + + case 0x0: + case 0x7: + return BlockFace.UP; + } return null; @@ -80,8 +85,9 @@ public class Lever extends SimpleAttachableMaterialData implements Redstone { */ public void setFacingDirection(BlockFace face) { byte data = (byte) (getData() & 0x8); - - if (getAttachedFace() == BlockFace.DOWN) { + BlockFace attach = getAttachedFace(); + + if (attach == BlockFace.DOWN) { switch (face) { case WEST: case EAST: @@ -93,6 +99,18 @@ public class Lever extends SimpleAttachableMaterialData implements Redstone { data |= 0x6; break; } + } else if (attach == BlockFace.UP) { + switch (face) { + case WEST: + case EAST: + data |= 0x7; + break; + + case SOUTH: + case NORTH: + data |= 0x0; + break; + } } else { switch (face) { case SOUTH: diff --git a/src/main/java/org/bukkit/material/Stairs.java b/src/main/java/org/bukkit/material/Stairs.java index 04f59b7f..67ff745a 100644 --- a/src/main/java/org/bukkit/material/Stairs.java +++ b/src/main/java/org/bukkit/material/Stairs.java @@ -30,7 +30,7 @@ public class Stairs extends MaterialData implements Directional { public BlockFace getAscendingDirection() { byte data = getData(); - switch (data) { + switch (data & 0x3) { case 0x0: default: return BlockFace.SOUTH; @@ -78,7 +78,7 @@ public class Stairs extends MaterialData implements Directional { break; } - setData(data); + setData((byte) ((getData() & 0xC) | data)); } /** @@ -88,9 +88,29 @@ public class Stairs extends MaterialData implements Directional { return getDescendingDirection(); } + /** + * Test if step is inverted + * @return true if inverted (top half), false if normal (bottom half) + */ + public boolean isInverted() { + return ((getData() & 0x4) != 0); + } + + /** + * Set step inverted state + * @param inv - true if step is inverted (top half), false if step is normal (bottom half) + */ + public void setInverted(boolean inv) { + int dat = getData() & 0x3; + if (inv) { + dat |= 0x4; + } + setData((byte) dat); + } + @Override public String toString() { - return super.toString() + " facing " + getFacing(); + return super.toString() + " facing " + getFacing() + (isInverted()?" inverted":""); } @Override diff --git a/src/main/java/org/bukkit/material/Step.java b/src/main/java/org/bukkit/material/Step.java index ba36bd83..2617bff0 100644 --- a/src/main/java/org/bukkit/material/Step.java +++ b/src/main/java/org/bukkit/material/Step.java @@ -47,8 +47,43 @@ public class Step extends TexturedMaterial { return textures; } + /** + * Test if step is inverted + * @return true if inverted (top half), false if normal (bottom half) + */ + public boolean isInverted() { + return ((getData() & 0x8) != 0); + } + + /** + * Set step inverted state + * @param inv - true if step is inverted (top half), false if step is normal (bottom half) + */ + public void setInverted(boolean inv) { + int dat = getData() & 0x7; + if (inv) { + dat |= 0x8; + } + setData((byte) dat); + } + + @Override + protected int getTextureIndex() { + return getData() & 0x7; + } + + @Override + protected void setTextureIndex(int idx) { + setData((byte) ((getData() & 0x8) | idx)); + } + @Override public Step clone() { return (Step) super.clone(); } + + @Override + public String toString() { + return super.toString() + (isInverted()?"inverted":""); + } } diff --git a/src/main/java/org/bukkit/material/TexturedMaterial.java b/src/main/java/org/bukkit/material/TexturedMaterial.java index 3fbd815f..51587df1 100644 --- a/src/main/java/org/bukkit/material/TexturedMaterial.java +++ b/src/main/java/org/bukkit/material/TexturedMaterial.java @@ -38,7 +38,7 @@ public abstract class TexturedMaterial extends MaterialData { * @return Material of this block */ public Material getMaterial() { - int n = (int) getData(); + int n = getTextureIndex(); if (n > getTextures().size() - 1) { n = 0; } @@ -54,12 +54,28 @@ public abstract class TexturedMaterial extends MaterialData { */ public void setMaterial(Material material) { if (getTextures().contains(material)) { - setData((byte) getTextures().indexOf(material)); + setTextureIndex(getTextures().indexOf(material)); } else { - setData((byte) 0x0); + setTextureIndex(0x0); } } + /** + * Get material index from data + * @return index of data in textures list + */ + protected int getTextureIndex() { + return getData(); // Default to using all bits - override for other mappings + } + + /** + * Set material index + * @param idx - index of data in textures list + */ + protected void setTextureIndex(int idx) { + setData((byte) idx); // Defult to using all bits - override for other mappings + } + @Override public String toString() { return getMaterial() + " " + super.toString(); diff --git a/src/main/java/org/bukkit/material/Tree.java b/src/main/java/org/bukkit/material/Tree.java index 5a909656..31548354 100644 --- a/src/main/java/org/bukkit/material/Tree.java +++ b/src/main/java/org/bukkit/material/Tree.java @@ -2,6 +2,7 @@ package org.bukkit.material; import org.bukkit.Material; import org.bukkit.TreeSpecies; +import org.bukkit.block.BlockFace; /** * Represents the different types of Trees. @@ -16,6 +17,12 @@ public class Tree extends MaterialData { setSpecies(species); } + public Tree(TreeSpecies species, BlockFace dir) { + this(); + setSpecies(species); + setDirection(dir); + } + public Tree(final int type) { super(type); } @@ -38,7 +45,7 @@ public class Tree extends MaterialData { * @return TreeSpecies of this tree */ public TreeSpecies getSpecies() { - return TreeSpecies.getByData(getData()); + return TreeSpecies.getByData((byte) (getData() & 0x3)); } /** @@ -47,12 +54,57 @@ public class Tree extends MaterialData { * @param species New species of this tree */ public void setSpecies(TreeSpecies species) { - setData(species.getData()); + setData((byte) ((getData() & 0xC) | species.getData())); + } + + /** + * Get direction of the log + * + * @return BlockFace.TOP for upright (default), BlockFace.EAST (east-west), BlockFace.NORTH (north-sout), BlockFace.SELF (directionless) + */ + public BlockFace getDirection() { + switch ((getData() >> 2) & 0x3) { + case 0: // Up-down + default: + return BlockFace.UP; + case 1: // North-south + return BlockFace.NORTH; + case 2: // East-west + return BlockFace.EAST; + case 3: // Directionless (bark on all sides) + return BlockFace.SELF; + } + } + /** + * Set direction of the log + * @param dir - direction of end of log (BlockFace.SELF for no direction) + */ + public void setDirection(BlockFace dir) { + int dat; + switch (dir) { + case UP: + case DOWN: + default: + dat = 0; + break; + case NORTH: + case SOUTH: + dat = 1; + break; + case EAST: + case WEST: + dat = 2; + break; + case SELF: + dat = 3; + break; + } + setData((byte) ((getData() & 0x3) | (dat << 2))); } @Override public String toString() { - return getSpecies() + " " + super.toString(); + return getSpecies() + " " + getDirection() + " " + super.toString(); } @Override diff --git a/src/main/java/org/bukkit/material/Tripwire.java b/src/main/java/org/bukkit/material/Tripwire.java new file mode 100644 index 00000000..8eedcc62 --- /dev/null +++ b/src/main/java/org/bukkit/material/Tripwire.java @@ -0,0 +1,71 @@ +package org.bukkit.material; + +import org.bukkit.Material; + +/** + * Represents the tripwire + */ +public class Tripwire extends MaterialData { + + public Tripwire() { + super(Material.TRIPWIRE); + } + + public Tripwire(final int type) { + super(type); + } + + public Tripwire(final int type, final byte data) { + super(type, data); + } + + /** + * Test if tripwire is currently activated + * @return true if activated, false if not + */ + public boolean isActivated() { + return (getData() & 0x4) != 0; + } + + /** + * Set tripwire activated state + * @param act - true if activated, false if not + */ + public void setActivated(boolean act) { + int dat = getData() & (0x8 | 0x3); + if (act) { + dat |= 0x4; + } + setData((byte) dat); + } + + /** + * Test if object triggering this tripwire directly + * @return true if object activating tripwire, false if not + */ + public boolean isObjectTriggering() { + return (getData() & 0x1) != 0; + } + + /** + * Set object triggering state for this tripwire + * @param trig - true if object activating tripwire, false if not + */ + public void setObjectTriggering(boolean trig) { + int dat = getData() & 0xE; + if (trig) { + dat |= 0x1; + } + setData((byte) dat); + } + + @Override + public Tripwire clone() { + return (Tripwire) super.clone(); + } + + @Override + public String toString() { + return super.toString() + (isActivated()?" Activated":"") + (isObjectTriggering()?" Triggered":""); + } +} diff --git a/src/main/java/org/bukkit/material/TripwireHook.java b/src/main/java/org/bukkit/material/TripwireHook.java new file mode 100644 index 00000000..58b8711b --- /dev/null +++ b/src/main/java/org/bukkit/material/TripwireHook.java @@ -0,0 +1,115 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; + +/** + * Represents the tripwire hook + */ +public class TripwireHook extends MaterialData implements Directional, Redstone { + + public TripwireHook() { + super(Material.TRIPWIRE_HOOK); + } + + public TripwireHook(final int type) { + super(type); + } + + public TripwireHook(final int type, final byte data) { + super(type, data); + } + + public TripwireHook(BlockFace dir) { + this(); + setFacingDirection(dir); + } + + /** + * Test if tripwire is connected + * @return true if connected, false if not + */ + public boolean isConnected() { + return (getData() & 0x4) != 0; + } + + /** + * Set tripwire connection state + * @param connected - true if connected, false if not + */ + public void setConnected(boolean connected) { + int dat = getData() & (0x8 | 0x3); + if (connected) { + dat |= 0x4; + } + setData((byte) dat); + } + + /** + * Test if hook is currently activated + * @return true if activated, false if not + */ + public boolean isActivated() { + return (getData() & 0x8) != 0; + } + + /** + * Set hook activated state + * @param act - true if activated, false if not + */ + public void setActivated(boolean act) { + int dat = getData() & (0x4 | 0x3); + if (act) { + dat |= 0x8; + } + setData((byte) dat); + } + + public void setFacingDirection(BlockFace face) { + int dat = getData() & 0xC; + switch (face) { + case EAST: + break; + case SOUTH: + dat |= 0x1; + break; + case WEST: + dat |= 0x2; + break; + case NORTH: + dat |= 0x3; + break; + default: + break; + } + setData((byte) dat); + } + + public BlockFace getFacing() { + switch (getData() & 0x3) { + case 0: + return BlockFace.EAST; + case 1: + return BlockFace.SOUTH; + case 2: + return BlockFace.WEST; + case 3: + return BlockFace.NORTH; + } + return null; + } + + public boolean isPowered() { + return isActivated(); + } + + @Override + public TripwireHook clone() { + return (TripwireHook) super.clone(); + } + + @Override + public String toString() { + return super.toString() + " facing " + getFacing() + (isActivated()?" Activated":"") + (isConnected()?" Connected":""); + } +} diff --git a/src/main/java/org/bukkit/material/WoodenStep.java b/src/main/java/org/bukkit/material/WoodenStep.java new file mode 100644 index 00000000..d6ce9330 --- /dev/null +++ b/src/main/java/org/bukkit/material/WoodenStep.java @@ -0,0 +1,85 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.TreeSpecies; + +/** + * Represents the different types of wooden steps. + */ +public class WoodenStep extends MaterialData { + + public WoodenStep() { + super(Material.WOOD_STEP); + } + + public WoodenStep(final int type) { + super(type); + } + + public WoodenStep(TreeSpecies species) { + this(); + setSpecies(species); + } + + public WoodenStep(TreeSpecies species, boolean inv) { + this(); + setSpecies(species); + setInverted(inv); + } + + public WoodenStep(final int type, final byte data) { + super(type, data); + } + + public WoodenStep(final Material type, final byte data) { + super(type, data); + } + + /** + * Gets the current species of this tree + * + * @return TreeSpecies of this tree + */ + public TreeSpecies getSpecies() { + return TreeSpecies.getByData((byte) (getData() & 0x3)); + } + + /** + * Sets the species of this tree + * + * @param species New species of this tree + */ + public void setSpecies(TreeSpecies species) { + setData((byte) ((getData() & 0xC) | species.getData())); + } + + /** + * Test if step is inverted + * @return true if inverted (top half), false if normal (bottom half) + */ + public boolean isInverted() { + return ((getData() & 0x8) != 0); + } + + /** + * Set step inverted state + * @param inv - true if step is inverted (top half), false if step is normal (bottom half) + */ + public void setInverted(boolean inv) { + int dat = getData() & 0x7; + if (inv) { + dat |= 0x8; + } + setData((byte) dat); + } + + @Override + public WoodenStep clone() { + return (WoodenStep) super.clone(); + } + + @Override + public String toString() { + return super.toString() + " " + getSpecies() + (isInverted()?" inverted":""); + } +} |