Added setters to applicable MaterialData classes.

By: sunkid <sunkid@iminurnetz.com>
This commit is contained in:
Bukkit/Spigot 2011-06-16 15:45:50 -07:00
parent 93406ae5d2
commit 615b1a9f3f
17 changed files with 139 additions and 20 deletions

View file

@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace;
/**
* Represents a bed.
*
* @author sunkid
*/
public class Bed extends MaterialData implements Directional {
@ -51,6 +49,14 @@ public class Bed extends MaterialData implements Directional {
return (getData() & 0x8) == 0x8;
}
/**
* Configure this to be either the head or the foot of the bed
* @param isHeadOfBed
*/
public void setHeadOfBed(boolean isHeadOfBed) {
setData((byte) (isHeadOfBed ? (getData() | 0x8) : (getData() & ~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.

View file

@ -5,7 +5,6 @@ import org.bukkit.Material;
/**
* Represents the different types of coals.
* @author sunkid
*/
public class Coal extends MaterialData {
public Coal() {

View file

@ -5,7 +5,6 @@ import org.bukkit.Material;
/**
* Represents the different types of crops.
* @author sunkid
*/
public class Crops extends MaterialData {
public Crops() {

View file

@ -29,4 +29,8 @@ public class DetectorRail extends ExtendedRails implements PressureSensor {
public boolean isPressed() {
return (getData() & 0x8) == 0x8;
}
public void setPressed(boolean isPressed) {
setData((byte) (isPressed ? (getData() | 0x8) : (getData() & ~0x8)));
}
}

View file

@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace;
/**
* Represents a dispenser.
*
* @author sunkid
*/
public class Dispenser extends FurnaceAndDispenser {

View file

@ -5,9 +5,8 @@ import org.bukkit.block.BlockFace;
/**
* Represents a door.
* @author sunkid
*/
public class Door extends MaterialData {
public class Door extends MaterialData implements Directional {
public Door() {
super(Material.WOODEN_DOOR);
}
@ -36,6 +35,14 @@ public class Door extends MaterialData {
return ((getData() & 0x4) == 0x4);
}
/**
* Configure this door to be either open or closed;
* @param isOpen
*/
public void setOpen(boolean isOpen) {
setData((byte) (isOpen ? (getData() | 0x4) : (getData() & ~0x4)));
}
/**
* @return whether this is the top half of the door
*/
@ -43,6 +50,14 @@ public class Door extends MaterialData {
return ((getData() & 0x8) == 0x8);
}
/**
* Configure this part of the door to be either the top or the bottom half;
* @param isTopHalf
*/
public void setTopHalf(boolean isTopHalf) {
setData((byte) (isTopHalf ? (getData() | 0x8) : (getData() & ~0x8)));
}
/**
* @return the location of the hinges
*/
@ -64,4 +79,48 @@ public class Door extends MaterialData {
public String toString() {
return (isTopHalf() ? "TOP" : "BOTTOM") + " half of " + (isOpen() ? "an OPEN " : "a CLOSED ") + super.toString() + " with hinges " + getHingeCorner();
}
/**
* Set the direction that this door should is facing.
* @param face the direction
*/
public void setFacingDirection(BlockFace face) {
byte data = (byte) (getData() & 0x12);
switch (face) {
case EAST:
data |= 0x1;
break;
case SOUTH:
data |= 0x2;
break;
case WEST:
data |= 0x3;
break;
}
setData(data);
}
/**
* Get the direction that this door is facing.
* @return the direction
*/
public BlockFace getFacing() {
byte data = (byte) (getData() & 0x3);
switch (data) {
case 0:
return BlockFace.NORTH;
case 1:
return BlockFace.EAST;
case 2:
return BlockFace.SOUTH;
case 3:
return BlockFace.WEST;
}
return null; // shouldn't happen
}
}

View file

@ -1,6 +1,7 @@
package org.bukkit.material;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
/**
* This is the superclass for the {@link DetectorRail} and {@link PoweredRail} classes
@ -31,4 +32,16 @@ public class ExtendedRails extends Rails {
protected byte getConvertedData() {
return (byte) (getData() & 0x7);
}
@Override
public void setDirection(BlockFace face, boolean isOnSlope) {
boolean extraBitSet = (getData() & 0x8) == 0x8;
if (face != BlockFace.NORTH && face != BlockFace.SOUTH && face != BlockFace.EAST && face != BlockFace.WEST) {
throw new IllegalArgumentException("Detector rails and powered rails cannot be set on a curve!");
}
super.setDirection(face, isOnSlope);
setData((byte) (extraBitSet ? (getData() | 0x8) : (getData() & ~0x8)));
}
}

View file

@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace;
/**
* Represents a furnace.
*
* @author sunkid
*/
public class Furnace extends FurnaceAndDispenser {

View file

@ -5,7 +5,6 @@ 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) {

View file

@ -5,7 +5,6 @@ import org.bukkit.TreeSpecies;
/**
* Represents the different types of leaves.
* @author sunkid
*/
public class Leaves extends MaterialData {
public Leaves() {

View file

@ -37,6 +37,14 @@ public class Lever extends SimpleAttachableMaterialData implements Redstone {
return (getData() & 0x8) == 0x8;
}
/**
* Set this lever to be powered or not.
* @param isPowered whether the lever should be powered or not
*/
public void setPowered(boolean isPowered) {
setData((byte) (isPowered ? (getData() | 0x8) : (getData() & ~0x8)));
}
/**
* Gets the face that this block is attached on
*

View file

@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace;
/**
* Represents a pumpkin.
*
* @author sunkid
*/
public class Pumpkin extends MaterialData implements Directional {

View file

@ -102,4 +102,49 @@ public class Rails extends MaterialData {
protected byte getConvertedData() {
return getData();
}
/**
* Set the direction of these tracks<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 should
* be supplied.
* @param face the direction the track should be facing
* @param isOnSlope whether or not the track should be on a slope
*/
public void setDirection(BlockFace face, boolean isOnSlope) {
switch (face) {
case SOUTH:
setData((byte) (isOnSlope ? 0x2 : 0x1));
break;
case NORTH:
setData((byte) (isOnSlope ? 0x3 : 0x1));
break;
case EAST:
setData((byte) (isOnSlope ? 0x4 : 0x0));
break;
case WEST:
setData((byte) (isOnSlope ? 0x5 : 0x0));
break;
case NORTH_EAST:
setData((byte) 0x6);
break;
case SOUTH_EAST:
setData((byte) 0x7);
break;
case SOUTH_WEST:
setData((byte) 0x8);
break;
case NORTH_WEST:
setData((byte) 0x9);
break;
}
}
}

View file

@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace;
/**
* Simple utility class for attachable MaterialData subclasses
* @author sunkid
*
*/
public abstract class SimpleAttachableMaterialData extends MaterialData implements Attachable {

View file

@ -5,8 +5,6 @@ import org.bukkit.block.BlockFace;
/**
* Represents stairs.
*
* @author sunkid
*/
public class Stairs extends MaterialData implements Directional {

View file

@ -6,7 +6,6 @@ import org.bukkit.Material;
/**
* Represents the different types of steps.
* @author sunkid
*/
public class Step extends MaterialData {
private static HashSet<Material> stepTypes = new HashSet<Material>();

View file

@ -5,7 +5,6 @@ import org.bukkit.TreeSpecies;
/**
* Represents the different types of Trees.
* @author sunkid
*/
public class Tree extends MaterialData {
public Tree() {