Ton of Material extensions handling the meta-data of blocks.
This commit is contained in:
parent
6fa9eef18d
commit
3d0781c8bf
@ -18,12 +18,12 @@ public enum Material {
|
|||||||
DIRT(3),
|
DIRT(3),
|
||||||
COBBLESTONE(4),
|
COBBLESTONE(4),
|
||||||
WOOD(5),
|
WOOD(5),
|
||||||
SAPLING(6),
|
SAPLING(6, MaterialData.class),
|
||||||
BEDROCK(7),
|
BEDROCK(7),
|
||||||
WATER(8),
|
WATER(8, MaterialData.class),
|
||||||
STATIONARY_WATER(9),
|
STATIONARY_WATER(9, MaterialData.class),
|
||||||
LAVA(10),
|
LAVA(10, MaterialData.class),
|
||||||
STATIONARY_LAVA(11),
|
STATIONARY_LAVA(11, MaterialData.class),
|
||||||
SAND(12),
|
SAND(12),
|
||||||
GRAVEL(13),
|
GRAVEL(13),
|
||||||
GOLD_ORE(14),
|
GOLD_ORE(14),
|
||||||
@ -35,10 +35,10 @@ public enum Material {
|
|||||||
GLASS(20),
|
GLASS(20),
|
||||||
LAPIS_ORE(21),
|
LAPIS_ORE(21),
|
||||||
LAPIS_BLOCK(22),
|
LAPIS_BLOCK(22),
|
||||||
DISPENSER(23),
|
DISPENSER(23, Dispenser.class),
|
||||||
SANDSTONE(24),
|
SANDSTONE(24),
|
||||||
NOTE_BLOCK(25),
|
NOTE_BLOCK(25),
|
||||||
BED_BLOCK(26),
|
BED_BLOCK(26, Bed.class),
|
||||||
WOOL(35, Wool.class),
|
WOOL(35, Wool.class),
|
||||||
YELLOW_FLOWER(37),
|
YELLOW_FLOWER(37),
|
||||||
RED_ROSE(38),
|
RED_ROSE(38),
|
||||||
@ -56,26 +56,26 @@ public enum Material {
|
|||||||
TORCH(50, Torch.class),
|
TORCH(50, Torch.class),
|
||||||
FIRE(51),
|
FIRE(51),
|
||||||
MOB_SPAWNER(52),
|
MOB_SPAWNER(52),
|
||||||
WOOD_STAIRS(53),
|
WOOD_STAIRS(53, Stairs.class),
|
||||||
CHEST(54),
|
CHEST(54),
|
||||||
REDSTONE_WIRE(55, RedstoneWire.class),
|
REDSTONE_WIRE(55, RedstoneWire.class),
|
||||||
DIAMOND_ORE(56),
|
DIAMOND_ORE(56),
|
||||||
DIAMOND_BLOCK(57),
|
DIAMOND_BLOCK(57),
|
||||||
WORKBENCH(58),
|
WORKBENCH(58),
|
||||||
CROPS(59, Crops.class),
|
CROPS(59, Crops.class),
|
||||||
SOIL(60),
|
SOIL(60, MaterialData.class),
|
||||||
FURNACE(61),
|
FURNACE(61, Furnace.class),
|
||||||
BURNING_FURNACE(62),
|
BURNING_FURNACE(62, Furnace.class),
|
||||||
SIGN_POST(63, 1, Sign.class),
|
SIGN_POST(63, 1, Sign.class),
|
||||||
WOODEN_DOOR(64, Door.class),
|
WOODEN_DOOR(64, Door.class),
|
||||||
LADDER(65, Ladder.class),
|
LADDER(65, Ladder.class),
|
||||||
RAILS(66),
|
RAILS(66, Rails.class),
|
||||||
COBBLESTONE_STAIRS(67),
|
COBBLESTONE_STAIRS(67, Stairs.class),
|
||||||
WALL_SIGN(68, 1, Sign.class),
|
WALL_SIGN(68, 1, Sign.class),
|
||||||
LEVER(69, Lever.class),
|
LEVER(69, Lever.class),
|
||||||
STONE_PLATE(70),
|
STONE_PLATE(70, PressurePlate.class),
|
||||||
IRON_DOOR_BLOCK(71, Door.class),
|
IRON_DOOR_BLOCK(71, Door.class),
|
||||||
WOOD_PLATE(72),
|
WOOD_PLATE(72, PressurePlate.class),
|
||||||
REDSTONE_ORE(73),
|
REDSTONE_ORE(73),
|
||||||
GLOWING_REDSTONE_ORE(74),
|
GLOWING_REDSTONE_ORE(74),
|
||||||
REDSTONE_TORCH_OFF(75, RedstoneTorch.class),
|
REDSTONE_TORCH_OFF(75, RedstoneTorch.class),
|
||||||
@ -84,17 +84,17 @@ public enum Material {
|
|||||||
SNOW(78),
|
SNOW(78),
|
||||||
ICE(79),
|
ICE(79),
|
||||||
SNOW_BLOCK(80),
|
SNOW_BLOCK(80),
|
||||||
CACTUS(81),
|
CACTUS(81, MaterialData.class),
|
||||||
CLAY(82),
|
CLAY(82),
|
||||||
SUGAR_CANE_BLOCK(83),
|
SUGAR_CANE_BLOCK(83, MaterialData.class),
|
||||||
JUKEBOX(84, Jukebox.class),
|
JUKEBOX(84, Jukebox.class),
|
||||||
FENCE(85),
|
FENCE(85),
|
||||||
PUMPKIN(86),
|
PUMPKIN(86, Pumpkin.class),
|
||||||
NETHERRACK(87),
|
NETHERRACK(87),
|
||||||
SOUL_SAND(88),
|
SOUL_SAND(88),
|
||||||
GLOWSTONE(89),
|
GLOWSTONE(89),
|
||||||
PORTAL(90),
|
PORTAL(90),
|
||||||
JACK_O_LANTERN(91),
|
JACK_O_LANTERN(91, Pumpkin.class),
|
||||||
CAKE_BLOCK(92, 1, Cake.class),
|
CAKE_BLOCK(92, 1, Cake.class),
|
||||||
DIODE_BLOCK_OFF(93, Diode.class),
|
DIODE_BLOCK_OFF(93, Diode.class),
|
||||||
DIODE_BLOCK_ON(94, Diode.class),
|
DIODE_BLOCK_ON(94, Diode.class),
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package org.bukkit.material;
|
package org.bukkit.material;
|
||||||
|
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -6,7 +5,7 @@ import org.bukkit.block.BlockFace;
|
|||||||
/**
|
/**
|
||||||
* Indicates that a block can be attached to another block
|
* Indicates that a block can be attached to another block
|
||||||
*/
|
*/
|
||||||
public interface Attachable {
|
public interface Attachable extends Directional {
|
||||||
/**
|
/**
|
||||||
* Gets the face that this block is attached on
|
* Gets the face that this block is attached on
|
||||||
*
|
*
|
||||||
|
106
src/main/java/org/bukkit/material/Bed.java
Normal file
106
src/main/java/org/bukkit/material/Bed.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a bed.
|
||||||
|
*
|
||||||
|
* @author sunkid
|
||||||
|
*/
|
||||||
|
public class Bed extends MaterialData implements Directional {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for a bed.
|
||||||
|
*/
|
||||||
|
public Bed() {
|
||||||
|
super(Material.BED_BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a bed facing in a particular direction.
|
||||||
|
* @param direction the direction the bed's head is facing
|
||||||
|
*/
|
||||||
|
public Bed(BlockFace direction) {
|
||||||
|
this();
|
||||||
|
setFacingDirection(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bed(final int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bed(final Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bed(final int type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bed(final Material type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if this block represents the head of the bed
|
||||||
|
*
|
||||||
|
* @return true if this is the head of the bed, false if it is the foot
|
||||||
|
*/
|
||||||
|
public boolean isHeadOfBed() {
|
||||||
|
return (getData() & 0x8) == 0x8;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set which direction the head of the bed is facing. Note that this will
|
||||||
|
* only affect one of the two blocks the bed is made of.
|
||||||
|
*/
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data;
|
||||||
|
switch (face) {
|
||||||
|
case WEST:
|
||||||
|
data = 0x0;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 0x1;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
default:
|
||||||
|
data = 0x3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isHeadOfBed()) {
|
||||||
|
data |= 0x8;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the direction that this bed's head is facing toward
|
||||||
|
*
|
||||||
|
* @return the direction the head of the bed is facing
|
||||||
|
*/
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
byte data = (byte) (getData() & 0x7);
|
||||||
|
switch (data) {
|
||||||
|
case 0x0:
|
||||||
|
return BlockFace.WEST;
|
||||||
|
case 0x1:
|
||||||
|
return BlockFace.NORTH;
|
||||||
|
case 0x2:
|
||||||
|
return BlockFace.EAST;
|
||||||
|
case 0x3:
|
||||||
|
default:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return (isHeadOfBed() ? "HEAD" : "FOOT") + " of " + super.toString() + " facing " + getFacing();
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,11 @@ import org.bukkit.Material;
|
|||||||
/**
|
/**
|
||||||
* Represents a button
|
* Represents a button
|
||||||
*/
|
*/
|
||||||
public class Button extends MaterialData implements Redstone, Attachable {
|
public class Button extends SimpleAttachableMaterialData implements Redstone {
|
||||||
|
public Button() {
|
||||||
|
super(Material.STONE_BUTTON);
|
||||||
|
}
|
||||||
|
|
||||||
public Button(final int type) {
|
public Button(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -33,6 +37,16 @@ public class Button extends MaterialData implements Redstone, Attachable {
|
|||||||
return (getData() & 0x8) == 0x8;
|
return (getData() & 0x8) == 0x8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current state of this button
|
||||||
|
*
|
||||||
|
* @param bool
|
||||||
|
* whether or not the button is powered
|
||||||
|
*/
|
||||||
|
public void setPowered(boolean bool) {
|
||||||
|
setData((byte) (bool ? (getData() | 0x8) : (getData() & ~0x8)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the face that this block is attached on
|
* Gets the face that this block is attached on
|
||||||
*
|
*
|
||||||
@ -54,4 +68,34 @@ public class Button extends MaterialData implements Redstone, Attachable {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the direction this button is pointing toward
|
||||||
|
*/
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data = (byte) (getData() & 0x8);
|
||||||
|
|
||||||
|
switch (face) {
|
||||||
|
case SOUTH:
|
||||||
|
data |= 0x1;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data |= 0x2;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data |= 0x3;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data |= 0x4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " " + (isPowered() ? "" : "NOT ") + "POWERED";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ package org.bukkit.material;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
public class Cake extends MaterialData {
|
public class Cake extends MaterialData {
|
||||||
|
public Cake() {
|
||||||
|
super(Material.CAKE_BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
public Cake(int type) {
|
public Cake(int type) {
|
||||||
super(type);
|
super(type);
|
||||||
@ -58,4 +61,10 @@ public class Cake extends MaterialData {
|
|||||||
if (n > 6) n = 6;
|
if (n > 6) n = 6;
|
||||||
setData((byte) (6 - n));
|
setData((byte) (6 - n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " " + getSlicesEaten() + "/" + getSlicesRemaining() + " slices eaten/remaining";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,15 @@ import org.bukkit.Material;
|
|||||||
* @author sunkid
|
* @author sunkid
|
||||||
*/
|
*/
|
||||||
public class Coal extends MaterialData {
|
public class Coal extends MaterialData {
|
||||||
|
public Coal() {
|
||||||
|
super(Material.COAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coal(CoalType type) {
|
||||||
|
this();
|
||||||
|
setType(type);
|
||||||
|
}
|
||||||
|
|
||||||
public Coal(final int type) {
|
public Coal(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -37,8 +46,25 @@ public class Coal extends MaterialData {
|
|||||||
* Sets the type of this coal
|
* Sets the type of this coal
|
||||||
*
|
*
|
||||||
* @param type New type of this coal
|
* @param type New type of this coal
|
||||||
|
* @deprecated use {@link #setType(CoalType)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setSpecies(CoalType type) {
|
public void setSpecies(CoalType type) {
|
||||||
|
setType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the type of this coal
|
||||||
|
*
|
||||||
|
* @param type New type of this coal
|
||||||
|
*/
|
||||||
|
public void setType(CoalType type) {
|
||||||
setData(type.getData());
|
setData(type.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getType() + " " + super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,15 @@ import org.bukkit.Material;
|
|||||||
* @author sunkid
|
* @author sunkid
|
||||||
*/
|
*/
|
||||||
public class Crops extends MaterialData {
|
public class Crops extends MaterialData {
|
||||||
|
public Crops() {
|
||||||
|
super(Material.CROPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Crops(CropState state) {
|
||||||
|
this();
|
||||||
|
setState(state);
|
||||||
|
}
|
||||||
|
|
||||||
public Crops(final int type) {
|
public Crops(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -28,8 +37,19 @@ public class Crops extends MaterialData {
|
|||||||
* Gets the current growth state of this crop
|
* Gets the current growth state of this crop
|
||||||
*
|
*
|
||||||
* @return CropState of this leave
|
* @return CropState of this leave
|
||||||
|
* @deprecated use {@link #getState()} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public CropState getSpecies() {
|
public CropState getSpecies() {
|
||||||
|
return getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current growth state of this crop
|
||||||
|
*
|
||||||
|
* @return CropState of this leave
|
||||||
|
*/
|
||||||
|
public CropState getState() {
|
||||||
return CropState.getByData(getData());
|
return CropState.getByData(getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,8 +57,25 @@ public class Crops extends MaterialData {
|
|||||||
* Sets the growth state of this crop
|
* Sets the growth state of this crop
|
||||||
*
|
*
|
||||||
* @param state New growth state of this crop
|
* @param state New growth state of this crop
|
||||||
|
* @deprecated use {@link #setState(CropState)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setSpecies(CropState state) {
|
public void setSpecies(CropState state) {
|
||||||
|
setState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the growth state of this crop
|
||||||
|
*
|
||||||
|
* @param state New growth state of this crop
|
||||||
|
*/
|
||||||
|
public void setState(CropState state) {
|
||||||
setData(state.getData());
|
setData(state.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getState() + " " + super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package org.bukkit.material;
|
package org.bukkit.material;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
public class Diode extends MaterialData {
|
public class Diode extends MaterialData implements Directional {
|
||||||
|
public Diode() {
|
||||||
|
super(Material.DIODE_BLOCK_ON);
|
||||||
|
}
|
||||||
|
|
||||||
public Diode(int type) {
|
public Diode(int type) {
|
||||||
super(type);
|
super(type);
|
||||||
@ -23,21 +27,64 @@ public class Diode extends MaterialData {
|
|||||||
/**
|
/**
|
||||||
* Sets the delay of the repeater
|
* Sets the delay of the repeater
|
||||||
*
|
*
|
||||||
* @param delay The new delay (1-4)
|
* @param delay
|
||||||
|
* The new delay (1-4)
|
||||||
*/
|
*/
|
||||||
public void setDelay(int delay) {
|
public void setDelay(int delay) {
|
||||||
if (delay > 4) delay = 4;
|
if (delay > 4) delay = 4;
|
||||||
if (delay < 1) delay = 1;
|
if (delay < 1) delay = 1;
|
||||||
byte newData = (byte) (getData() & 0x3);
|
byte newData = (byte) (getData() & 0x3);
|
||||||
setData((byte) (newData | (delay - 1)));
|
setData((byte) (newData | ((delay - 1) << 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the delay of the repeater
|
* Gets the delay of the repeater in ticks
|
||||||
*
|
*
|
||||||
* @return The delay (1-4)
|
* @return The delay (1-4)
|
||||||
*/
|
*/
|
||||||
public int getDelay() {
|
public int getDelay() {
|
||||||
return (getData() & 0xC) + 1;
|
return (getData() >> 2) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
int delay = getDelay();
|
||||||
|
byte data;
|
||||||
|
switch (face) {
|
||||||
|
case SOUTH:
|
||||||
|
data = 0x1;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 0x3;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
default:
|
||||||
|
data = 0x0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
setDelay(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
byte data = (byte) (getData() & 0x3);
|
||||||
|
switch (data) {
|
||||||
|
case 0x0:
|
||||||
|
default:
|
||||||
|
return BlockFace.EAST;
|
||||||
|
case 0x1:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
case 0x2:
|
||||||
|
return BlockFace.WEST;
|
||||||
|
case 0x3:
|
||||||
|
return BlockFace.NORTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getFacing() + " with " + getDelay() + " ticks delay";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
src/main/java/org/bukkit/material/Directional.java
Normal file
18
src/main/java/org/bukkit/material/Directional.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
public interface Directional {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the direction that this block is facing in
|
||||||
|
*/
|
||||||
|
public void setFacingDirection(BlockFace face);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the direction this block is facing
|
||||||
|
*
|
||||||
|
* @return the direction this block is facing
|
||||||
|
*/
|
||||||
|
public BlockFace getFacing();
|
||||||
|
}
|
37
src/main/java/org/bukkit/material/Dispenser.java
Normal file
37
src/main/java/org/bukkit/material/Dispenser.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a dispenser.
|
||||||
|
*
|
||||||
|
* @author sunkid
|
||||||
|
*/
|
||||||
|
public class Dispenser extends FurnaceAndDispenser {
|
||||||
|
|
||||||
|
public Dispenser() {
|
||||||
|
super(Material.DISPENSER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dispenser(BlockFace direction) {
|
||||||
|
this();
|
||||||
|
setFacingDirection(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dispenser(final int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dispenser(final Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dispenser(final int type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dispenser(final Material type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
}
|
@ -4,10 +4,14 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the different types of coals.
|
* Represents a door.
|
||||||
* @author sunkid
|
* @author sunkid
|
||||||
*/
|
*/
|
||||||
public class Door extends MaterialData {
|
public class Door extends MaterialData {
|
||||||
|
public Door() {
|
||||||
|
super(Material.WOODEN_DOOR);
|
||||||
|
}
|
||||||
|
|
||||||
public Door(final int type) {
|
public Door(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -54,4 +58,10 @@ public class Door extends MaterialData {
|
|||||||
|
|
||||||
return BlockFace.NORTH_EAST;
|
return BlockFace.NORTH_EAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return (isTopHalf() ? "TOP" : "BOTTOM") + " half of " + (isOpen() ? "an OPEN " : "a CLOSED ") + super.toString() + " with hinges " + getHingeCorner();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ import org.bukkit.Material;
|
|||||||
* Represents dye
|
* Represents dye
|
||||||
*/
|
*/
|
||||||
public class Dye extends MaterialData implements Colorable {
|
public class Dye extends MaterialData implements Colorable {
|
||||||
|
public Dye() {
|
||||||
|
super(Material.INK_SACK);
|
||||||
|
}
|
||||||
|
|
||||||
public Dye(final int type) {
|
public Dye(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -30,7 +34,7 @@ public class Dye extends MaterialData implements Colorable {
|
|||||||
* @return DyeColor of this dye
|
* @return DyeColor of this dye
|
||||||
*/
|
*/
|
||||||
public DyeColor getColor() {
|
public DyeColor getColor() {
|
||||||
return DyeColor.getByData(getData());
|
return DyeColor.getByData((byte) (15 - getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,6 +43,11 @@ public class Dye extends MaterialData implements Colorable {
|
|||||||
* @param color New color of this dye
|
* @param color New color of this dye
|
||||||
*/
|
*/
|
||||||
public void setColor(DyeColor color) {
|
public void setColor(DyeColor color) {
|
||||||
setData(color.getData());
|
setData((byte) (15 - color.getData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getColor() + " DYE(" + getData() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
src/main/java/org/bukkit/material/Furnace.java
Normal file
41
src/main/java/org/bukkit/material/Furnace.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a furnace.
|
||||||
|
*
|
||||||
|
* @author sunkid
|
||||||
|
*/
|
||||||
|
public class Furnace extends FurnaceAndDispenser {
|
||||||
|
|
||||||
|
public Furnace() {
|
||||||
|
super(Material.FURNACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a furnace facing in a particular direction.
|
||||||
|
* @param direction the direction the furnace's "opening" is facing
|
||||||
|
*/
|
||||||
|
public Furnace(BlockFace direction) {
|
||||||
|
this();
|
||||||
|
setFacingDirection(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Furnace(final int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Furnace(final Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Furnace(final int type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Furnace(final Material type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
}
|
66
src/main/java/org/bukkit/material/FurnaceAndDispenser.java
Normal file
66
src/main/java/org/bukkit/material/FurnaceAndDispenser.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a furnace or a dispenser.
|
||||||
|
* @author sunkid
|
||||||
|
*/
|
||||||
|
public class FurnaceAndDispenser extends MaterialData implements Directional {
|
||||||
|
public FurnaceAndDispenser(final int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnaceAndDispenser(final Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnaceAndDispenser(final int type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FurnaceAndDispenser(final Material type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data;
|
||||||
|
switch (face) {
|
||||||
|
case EAST:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data = 0x3;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 0x4;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
default:
|
||||||
|
data = 0x5;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
byte data = getData();
|
||||||
|
switch (data) {
|
||||||
|
case 0x2:
|
||||||
|
return BlockFace.EAST;
|
||||||
|
case 0x3:
|
||||||
|
return BlockFace.WEST;
|
||||||
|
case 0x4:
|
||||||
|
return BlockFace.NORTH;
|
||||||
|
case 0x5:
|
||||||
|
default:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getFacing();
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,28 @@
|
|||||||
package org.bukkit.material;
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
public class Jukebox extends MaterialData {
|
public class Jukebox extends MaterialData {
|
||||||
|
private static HashSet<Material> recordTypes = new HashSet<Material>();
|
||||||
|
static {
|
||||||
|
recordTypes.add(Material.GOLD_RECORD);
|
||||||
|
recordTypes.add(Material.GREEN_RECORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Jukebox() {
|
||||||
|
super(Material.JUKEBOX);
|
||||||
|
}
|
||||||
|
|
||||||
public Jukebox(int type) {
|
public Jukebox(int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jukebox(Material type) {
|
public Jukebox(Material type) {
|
||||||
super(type);
|
super((recordTypes.contains(type)) ? Material.JUKEBOX : type);
|
||||||
|
if(recordTypes.contains(type))
|
||||||
|
setPlaying(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jukebox(int type, byte data) {
|
public Jukebox(int type, byte data) {
|
||||||
@ -55,4 +68,10 @@ public class Jukebox extends MaterialData {
|
|||||||
setData((byte) 0x0);
|
setData((byte) 0x0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " playing " + getPlaying();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package org.bukkit.material;
|
package org.bukkit.material;
|
||||||
|
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -7,7 +6,11 @@ import org.bukkit.Material;
|
|||||||
/**
|
/**
|
||||||
* Represents Ladder data
|
* Represents Ladder data
|
||||||
*/
|
*/
|
||||||
public class Ladder extends MaterialData implements Attachable {
|
public class Ladder extends SimpleAttachableMaterialData {
|
||||||
|
public Ladder() {
|
||||||
|
super(Material.LADDER);
|
||||||
|
}
|
||||||
|
|
||||||
public Ladder(final int type) {
|
public Ladder(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -45,4 +48,29 @@ public class Ladder extends MaterialData implements Attachable {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the direction this ladder is facing
|
||||||
|
*/
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data = (byte) 0x0;
|
||||||
|
|
||||||
|
switch (face) {
|
||||||
|
case WEST:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data = 0x3;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
data = 0x4;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 0x5;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,6 +8,15 @@ import org.bukkit.TreeSpecies;
|
|||||||
* @author sunkid
|
* @author sunkid
|
||||||
*/
|
*/
|
||||||
public class Leaves extends MaterialData {
|
public class Leaves extends MaterialData {
|
||||||
|
public Leaves() {
|
||||||
|
super(Material.LEAVES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Leaves(TreeSpecies species) {
|
||||||
|
this();
|
||||||
|
setSpecies(species);
|
||||||
|
}
|
||||||
|
|
||||||
public Leaves(final int type) {
|
public Leaves(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -41,4 +50,9 @@ public class Leaves extends MaterialData {
|
|||||||
public void setSpecies(TreeSpecies species) {
|
public void setSpecies(TreeSpecies species) {
|
||||||
setData(species.getData());
|
setData(species.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getSpecies() + " " + super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,11 @@ import org.bukkit.Material;
|
|||||||
/**
|
/**
|
||||||
* Represents a lever
|
* Represents a lever
|
||||||
*/
|
*/
|
||||||
public class Lever extends MaterialData implements Redstone, Attachable {
|
public class Lever extends SimpleAttachableMaterialData implements Redstone {
|
||||||
|
public Lever() {
|
||||||
|
super(Material.LEVER);
|
||||||
|
}
|
||||||
|
|
||||||
public Lever(final int type) {
|
public Lever(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -57,4 +61,46 @@ public class Lever extends MaterialData implements Redstone, Attachable {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the direction this lever is pointing in
|
||||||
|
*/
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data = (byte) (getData() & 0x8);
|
||||||
|
|
||||||
|
if (getAttachedFace() == BlockFace.DOWN) {
|
||||||
|
switch (face) {
|
||||||
|
case WEST:
|
||||||
|
case EAST:
|
||||||
|
data |= 0x5;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
case NORTH:
|
||||||
|
data |= 0x6;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (face) {
|
||||||
|
case SOUTH:
|
||||||
|
data |= 0x1;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data |= 0x2;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data |= 0x3;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data |= 0x4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getFacing() + " " + (isPowered() ? "" : "NOT ") + "POWERED";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,20 @@ public class MaterialData {
|
|||||||
* @return New ItemStack containing a copy of this MaterialData
|
* @return New ItemStack containing a copy of this MaterialData
|
||||||
*/
|
*/
|
||||||
public ItemStack toItemStack() {
|
public ItemStack toItemStack() {
|
||||||
return new ItemStack(type);
|
return new ItemStack(type, 0, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ItemStack based on this MaterialData
|
||||||
|
*
|
||||||
|
* @return New ItemStack containing a copy of this MaterialData
|
||||||
|
*/
|
||||||
|
public ItemStack toItemStack(int amount) {
|
||||||
|
return new ItemStack(type, amount, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getItemType() + "(" + getData() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
src/main/java/org/bukkit/material/PressurePlate.java
Normal file
39
src/main/java/org/bukkit/material/PressurePlate.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a pressure plate
|
||||||
|
* @author CelticMinstrel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PressurePlate extends MaterialData {
|
||||||
|
public PressurePlate() {
|
||||||
|
super(Material.WOOD_PLATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PressurePlate(int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PressurePlate(Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PressurePlate(int type, byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PressurePlate(Material type, byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPressed() {
|
||||||
|
return getData() == 0x1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + (isPressed() ? " PRESSED" : "");
|
||||||
|
}
|
||||||
|
}
|
85
src/main/java/org/bukkit/material/Pumpkin.java
Normal file
85
src/main/java/org/bukkit/material/Pumpkin.java
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a pumpkin.
|
||||||
|
*
|
||||||
|
* @author sunkid
|
||||||
|
*/
|
||||||
|
public class Pumpkin extends MaterialData implements Directional {
|
||||||
|
|
||||||
|
public Pumpkin() {
|
||||||
|
super(Material.PUMPKIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a pumpkin facing in a particular direction.
|
||||||
|
* @param direction the direction the pumkin's face is facing
|
||||||
|
*/
|
||||||
|
public Pumpkin(BlockFace direction) {
|
||||||
|
this();
|
||||||
|
setFacingDirection(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pumpkin(final int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pumpkin(final Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pumpkin(final int type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pumpkin(final Material type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLit() {
|
||||||
|
return getItemType() == Material.JACK_O_LANTERN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data;
|
||||||
|
switch (face) {
|
||||||
|
case EAST:
|
||||||
|
data = 0x0;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
data = 0x1;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
default:
|
||||||
|
data = 0x3;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
byte data = getData();
|
||||||
|
switch (data) {
|
||||||
|
case 0x0:
|
||||||
|
return BlockFace.EAST;
|
||||||
|
case 0x1:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
case 0x2:
|
||||||
|
return BlockFace.WEST;
|
||||||
|
case 0x3:
|
||||||
|
default:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getFacing() + " " + (isLit() ? "" : "NOT ") + "LIT";
|
||||||
|
}
|
||||||
|
}
|
87
src/main/java/org/bukkit/material/Rails.java
Normal file
87
src/main/java/org/bukkit/material/Rails.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents minecart rails.
|
||||||
|
*
|
||||||
|
* @author sunkid
|
||||||
|
*/
|
||||||
|
public class Rails extends MaterialData {
|
||||||
|
|
||||||
|
public Rails() {
|
||||||
|
super(Material.RAILS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rails(final int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rails(final Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rails(final int type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rails(final Material type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the whether this track is set on a slope
|
||||||
|
*/
|
||||||
|
public boolean isOnSlope() {
|
||||||
|
byte d = getData();
|
||||||
|
return (d == 0x2 || d == 0x3 || d == 0x4 || d == 0x5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the whether this track is set as a curve
|
||||||
|
*/
|
||||||
|
public boolean isCurve() {
|
||||||
|
byte d = getData();
|
||||||
|
return (d == 0x6 || d == 0x7 || d == 0x8 || d == 0x9);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the direction these tracks are set <br>
|
||||||
|
* Note that tracks are bidirectional and that the direction
|
||||||
|
* returned is the ascending direction if the track is set on a
|
||||||
|
* slope. If it is set as a curve, the corner of the track is
|
||||||
|
* returned.
|
||||||
|
*/
|
||||||
|
public BlockFace getDirection() {
|
||||||
|
byte d = getData();
|
||||||
|
switch (d) {
|
||||||
|
case 0x0:
|
||||||
|
default:
|
||||||
|
return BlockFace.WEST;
|
||||||
|
case 0x1:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
case 0x2:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
case 0x3:
|
||||||
|
return BlockFace.NORTH;
|
||||||
|
case 0x4:
|
||||||
|
return BlockFace.EAST;
|
||||||
|
case 0x5:
|
||||||
|
return BlockFace.WEST;
|
||||||
|
case 0x6:
|
||||||
|
return BlockFace.NORTH_EAST;
|
||||||
|
case 0x7:
|
||||||
|
return BlockFace.SOUTH_EAST;
|
||||||
|
case 0x8:
|
||||||
|
return BlockFace.SOUTH_WEST;
|
||||||
|
case 0x9:
|
||||||
|
return BlockFace.NORTH_WEST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getDirection() + (isCurve() ? " on a curve" : (isOnSlope() ? " on a slope" : ""));
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,10 @@ import org.bukkit.Material;
|
|||||||
* Represents a redstone torch
|
* Represents a redstone torch
|
||||||
*/
|
*/
|
||||||
public class RedstoneTorch extends Torch implements Redstone {
|
public class RedstoneTorch extends Torch implements Redstone {
|
||||||
|
public RedstoneTorch() {
|
||||||
|
super(Material.REDSTONE_TORCH_ON);
|
||||||
|
}
|
||||||
|
|
||||||
public RedstoneTorch(final int type) {
|
public RedstoneTorch(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -32,4 +36,9 @@ public class RedstoneTorch extends Torch implements Redstone {
|
|||||||
public boolean isPowered() {
|
public boolean isPowered() {
|
||||||
return getItemType() == Material.REDSTONE_TORCH_ON;
|
return getItemType() == Material.REDSTONE_TORCH_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " " + (isPowered() ? "" : "NOT ") + "POWERED";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,10 @@ import org.bukkit.Material;
|
|||||||
* Represents redstone wire
|
* Represents redstone wire
|
||||||
*/
|
*/
|
||||||
public class RedstoneWire extends MaterialData implements Redstone {
|
public class RedstoneWire extends MaterialData implements Redstone {
|
||||||
|
public RedstoneWire() {
|
||||||
|
super(Material.REDSTONE_WIRE);
|
||||||
|
}
|
||||||
|
|
||||||
public RedstoneWire(final int type) {
|
public RedstoneWire(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -32,4 +36,9 @@ public class RedstoneWire extends MaterialData implements Redstone {
|
|||||||
public boolean isPowered() {
|
public boolean isPowered() {
|
||||||
return getData() > 0;
|
return getData() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " " + (isPowered() ? "" : "NOT ") + "POWERED";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package org.bukkit.material;
|
package org.bukkit.material;
|
||||||
|
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -8,6 +7,10 @@ import org.bukkit.Material;
|
|||||||
* MaterialData for signs
|
* MaterialData for signs
|
||||||
*/
|
*/
|
||||||
public class Sign extends MaterialData implements Attachable {
|
public class Sign extends MaterialData implements Attachable {
|
||||||
|
public Sign() {
|
||||||
|
super(Material.SIGN_POST);
|
||||||
|
}
|
||||||
|
|
||||||
public Sign(final int type) {
|
public Sign(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -24,13 +27,23 @@ public class Sign extends MaterialData implements Attachable {
|
|||||||
super(type, data);
|
super(type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this sign is attached to a wall
|
||||||
|
*
|
||||||
|
* @return true if this sign is attached to a wall, false if set on top of a
|
||||||
|
* block
|
||||||
|
*/
|
||||||
|
public boolean isWallSign() {
|
||||||
|
return getItemType() == Material.WALL_SIGN;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the face that this block is attached on
|
* Gets the face that this block is attached on
|
||||||
*
|
*
|
||||||
* @return BlockFace attached to
|
* @return BlockFace attached to
|
||||||
*/
|
*/
|
||||||
public BlockFace getAttachedFace() {
|
public BlockFace getAttachedFace() {
|
||||||
if (getItemType() == Material.WALL_SIGN) {
|
if (isWallSign()) {
|
||||||
byte data = getData();
|
byte data = getData();
|
||||||
|
|
||||||
switch (data) {
|
switch (data) {
|
||||||
@ -58,7 +71,7 @@ public class Sign extends MaterialData implements Attachable {
|
|||||||
public BlockFace getFacing() {
|
public BlockFace getFacing() {
|
||||||
byte data = getData();
|
byte data = getData();
|
||||||
|
|
||||||
if (getAttachedFace() == BlockFace.DOWN) {
|
if (!isWallSign()) {
|
||||||
switch (data) {
|
switch (data) {
|
||||||
case 0x0:
|
case 0x0:
|
||||||
case 0x1:
|
case 0x1:
|
||||||
@ -88,18 +101,61 @@ public class Sign extends MaterialData implements Attachable {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
switch (data) {
|
return getAttachedFace().getOppositeFace();
|
||||||
case 0x2:
|
|
||||||
return BlockFace.EAST;
|
|
||||||
case 0x3:
|
|
||||||
return BlockFace.WEST;
|
|
||||||
case 0x4:
|
|
||||||
return BlockFace.NORTH;
|
|
||||||
case 0x5:
|
|
||||||
return BlockFace.SOUTH;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data;
|
||||||
|
if (isWallSign()) {
|
||||||
|
switch (face) {
|
||||||
|
case EAST:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data = 0x3;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 0x4;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
default:
|
||||||
|
data = 0x5;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (face) {
|
||||||
|
case WEST:
|
||||||
|
data = 0x1;
|
||||||
|
break;
|
||||||
|
case NORTH_WEST:
|
||||||
|
data = 0x3;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 0x5;
|
||||||
|
break;
|
||||||
|
case NORTH_EAST:
|
||||||
|
data = 0x7;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data = 0x9;
|
||||||
|
break;
|
||||||
|
case SOUTH_EAST:
|
||||||
|
data = 0xB;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
data = 0xD;
|
||||||
|
break;
|
||||||
|
case SOUTH_WEST:
|
||||||
|
default:
|
||||||
|
data = 0xF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getFacing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple utility class for attachable MaterialData subclasses
|
||||||
|
* @author sunkid
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class SimpleAttachableMaterialData extends MaterialData implements Attachable {
|
||||||
|
|
||||||
|
public SimpleAttachableMaterialData(int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAttachableMaterialData(int type, BlockFace direction) {
|
||||||
|
this(type);
|
||||||
|
setFacingDirection(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAttachableMaterialData(Material type, BlockFace direction) {
|
||||||
|
this(type);
|
||||||
|
setFacingDirection(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAttachableMaterialData(Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAttachableMaterialData(int type, byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAttachableMaterialData(Material type, byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
return getAttachedFace().getOppositeFace();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getFacing();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
90
src/main/java/org/bukkit/material/Stairs.java
Normal file
90
src/main/java/org/bukkit/material/Stairs.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents stairs.
|
||||||
|
*
|
||||||
|
* @author sunkid
|
||||||
|
*/
|
||||||
|
public class Stairs extends MaterialData implements Directional {
|
||||||
|
|
||||||
|
public Stairs(final int type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stairs(final Material type) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stairs(final int type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stairs(final Material type, final byte data) {
|
||||||
|
super(type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the direction the stairs ascend towards
|
||||||
|
*/
|
||||||
|
public BlockFace getAscendingDirection() {
|
||||||
|
byte data = getData();
|
||||||
|
switch (data) {
|
||||||
|
case 0x0:
|
||||||
|
default:
|
||||||
|
return BlockFace.SOUTH;
|
||||||
|
case 0x1:
|
||||||
|
return BlockFace.NORTH;
|
||||||
|
case 0x2:
|
||||||
|
return BlockFace.WEST;
|
||||||
|
case 0x3:
|
||||||
|
return BlockFace.EAST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the direction the stairs descend towards
|
||||||
|
*/
|
||||||
|
public BlockFace getDescendingDirection() {
|
||||||
|
return getAscendingDirection().getOppositeFace();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the direction the stair part of the block is facing
|
||||||
|
*/
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data;
|
||||||
|
switch (face) {
|
||||||
|
case NORTH:
|
||||||
|
default:
|
||||||
|
data = 0x0;
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
data = 0x1;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data = 0x3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the direction the stair part of the block is facing
|
||||||
|
*/
|
||||||
|
public BlockFace getFacing() {
|
||||||
|
return getDescendingDirection();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " facing " + getFacing();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package org.bukkit.material;
|
package org.bukkit.material;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,12 +9,26 @@ import org.bukkit.Material;
|
|||||||
* @author sunkid
|
* @author sunkid
|
||||||
*/
|
*/
|
||||||
public class Step extends MaterialData {
|
public class Step extends MaterialData {
|
||||||
|
private static HashSet<Material> stepTypes = new HashSet<Material>();
|
||||||
|
static {
|
||||||
|
stepTypes.add(Material.SANDSTONE);
|
||||||
|
stepTypes.add(Material.WOOD);
|
||||||
|
stepTypes.add(Material.COBBLESTONE);
|
||||||
|
stepTypes.add(Material.STONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Step() {
|
||||||
|
super(Material.STEP);
|
||||||
|
}
|
||||||
|
|
||||||
public Step(final int type) {
|
public Step(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Step(final Material type) {
|
public Step(final Material type) {
|
||||||
super(type);
|
super((stepTypes.contains(type)) ? Material.STEP : type);
|
||||||
|
if(stepTypes.contains(type))
|
||||||
|
setMaterial(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Step(final int type, final byte data) {
|
public Step(final int type, final byte data) {
|
||||||
@ -63,4 +79,9 @@ public class Step extends MaterialData {
|
|||||||
setData((byte) 0x0);
|
setData((byte) 0x0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getMaterial() + " " + super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package org.bukkit.material;
|
package org.bukkit.material;
|
||||||
|
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -7,7 +6,11 @@ import org.bukkit.Material;
|
|||||||
/**
|
/**
|
||||||
* MaterialData for torches
|
* MaterialData for torches
|
||||||
*/
|
*/
|
||||||
public class Torch extends MaterialData implements Attachable {
|
public class Torch extends SimpleAttachableMaterialData {
|
||||||
|
public Torch() {
|
||||||
|
super(Material.TORCH);
|
||||||
|
}
|
||||||
|
|
||||||
public Torch(final int type) {
|
public Torch(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -47,4 +50,27 @@ public class Torch extends MaterialData implements Attachable {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFacingDirection(BlockFace face) {
|
||||||
|
byte data;
|
||||||
|
switch (face) {
|
||||||
|
case SOUTH:
|
||||||
|
data = 0x1;
|
||||||
|
break;
|
||||||
|
case NORTH:
|
||||||
|
data = 0x2;
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
data = 0x3;
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
data = 0x4;
|
||||||
|
break;
|
||||||
|
case UP:
|
||||||
|
default:
|
||||||
|
data = 0x5;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,15 @@ import org.bukkit.TreeSpecies;
|
|||||||
* @author sunkid
|
* @author sunkid
|
||||||
*/
|
*/
|
||||||
public class Tree extends MaterialData {
|
public class Tree extends MaterialData {
|
||||||
|
public Tree() {
|
||||||
|
super(Material.LOG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tree(TreeSpecies species) {
|
||||||
|
this();
|
||||||
|
setSpecies(species);
|
||||||
|
}
|
||||||
|
|
||||||
public Tree(final int type) {
|
public Tree(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -41,4 +50,9 @@ public class Tree extends MaterialData {
|
|||||||
public void setSpecies(TreeSpecies species) {
|
public void setSpecies(TreeSpecies species) {
|
||||||
setData(species.getData());
|
setData(species.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getSpecies() + " " + super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,15 @@ import org.bukkit.Material;
|
|||||||
* Represents a Wool/Cloth block
|
* Represents a Wool/Cloth block
|
||||||
*/
|
*/
|
||||||
public class Wool extends MaterialData implements Colorable {
|
public class Wool extends MaterialData implements Colorable {
|
||||||
|
public Wool() {
|
||||||
|
super(Material.WOOL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Wool(DyeColor color) {
|
||||||
|
this();
|
||||||
|
setColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
public Wool(final int type) {
|
public Wool(final int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
@ -41,4 +50,9 @@ public class Wool extends MaterialData implements Colorable {
|
|||||||
public void setColor(DyeColor color) {
|
public void setColor(DyeColor color) {
|
||||||
setData(color.getData());
|
setData(color.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getColor() + " " + super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user