SPIGOT-2013 Added Comparator/Hopper material, enhanced Diode
By: ryanbennitt <ryanbennitt@googlemail.com>
This commit is contained in:
@@ -3,9 +3,71 @@ package org.bukkit.material;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
public class Diode extends MaterialData implements Directional {
|
||||
/**
|
||||
* Represents a diode/repeater in the on or off state, with a delay and facing
|
||||
* in a specific direction.
|
||||
*
|
||||
* @see Material#DIODE_BLOCK_OFF
|
||||
* @see Material#DIODE_BLOCK_ON
|
||||
*/
|
||||
public class Diode extends MaterialData implements Directional, Redstone {
|
||||
|
||||
protected static final BlockFace DEFAULT_DIRECTION = BlockFace.NORTH;
|
||||
protected static final int DEFAULT_DELAY = 1;
|
||||
protected static final boolean DEFAULT_STATE = false;
|
||||
|
||||
/**
|
||||
* Constructs a diode switched on, with a delay of 1 and facing the default
|
||||
* direction (north).
|
||||
*
|
||||
* By default this constructor creates a diode that is switched on for
|
||||
* backwards compatibility with past implementations.
|
||||
*/
|
||||
public Diode() {
|
||||
super(Material.DIODE_BLOCK_ON);
|
||||
this(DEFAULT_DIRECTION, DEFAULT_DELAY, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a diode switched off, with a delay of 1 and facing the
|
||||
* specified direction.
|
||||
*
|
||||
* @param facingDirection the direction the diode is facing
|
||||
*
|
||||
* @see BlockFace
|
||||
*/
|
||||
public Diode(BlockFace facingDirection) {
|
||||
this(facingDirection, DEFAULT_DELAY, DEFAULT_STATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a diode switched off, with the specified delay and facing the
|
||||
* specified direction.
|
||||
*
|
||||
* @param facingDirection the direction the diode is facing
|
||||
* @param delay The number of ticks (1-4) before the diode turns on after
|
||||
* being powered
|
||||
*
|
||||
* @see BlockFace
|
||||
*/
|
||||
public Diode(BlockFace facingDirection, int delay) {
|
||||
this(facingDirection, delay, DEFAULT_STATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a diode switched on or off, with the specified delay and
|
||||
* facing the specified direction.
|
||||
*
|
||||
* @param facingDirection the direction the diode is facing
|
||||
* @param delay The number of ticks (1-4) before the diode turns on after
|
||||
* being powered
|
||||
* @param state True if the diode is in the on state
|
||||
*
|
||||
* @see BlockFace
|
||||
*/
|
||||
public Diode(BlockFace facingDirection, int delay, boolean state) {
|
||||
super(state ? Material.DIODE_BLOCK_ON : Material.DIODE_BLOCK_OFF);
|
||||
setFacingDirection(facingDirection);
|
||||
setDelay(delay);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,10 +104,9 @@ public class Diode extends MaterialData implements Directional {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (delay > 4) {
|
||||
@@ -60,7 +121,7 @@ public class Diode extends MaterialData implements Directional {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the delay of the repeater in ticks
|
||||
* Gets the delay of the repeater in ticks.
|
||||
*
|
||||
* @return The delay (1-4)
|
||||
*/
|
||||
@@ -68,48 +129,61 @@ public class Diode extends MaterialData implements Directional {
|
||||
return (getData() >> 2) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the direction this diode is facing.
|
||||
*
|
||||
* @param face The direction to set this diode to
|
||||
*
|
||||
* @see BlockFace
|
||||
*/
|
||||
@Override
|
||||
public void setFacingDirection(BlockFace face) {
|
||||
int delay = getDelay();
|
||||
byte data;
|
||||
|
||||
switch (face) {
|
||||
case EAST:
|
||||
data = 0x1;
|
||||
break;
|
||||
|
||||
case SOUTH:
|
||||
data = 0x2;
|
||||
break;
|
||||
|
||||
case WEST:
|
||||
data = 0x3;
|
||||
break;
|
||||
|
||||
case NORTH:
|
||||
default:
|
||||
data = 0x0;
|
||||
case EAST:
|
||||
data = 0x1;
|
||||
break;
|
||||
case SOUTH:
|
||||
data = 0x2;
|
||||
break;
|
||||
case WEST:
|
||||
data = 0x3;
|
||||
break;
|
||||
case NORTH:
|
||||
default:
|
||||
data = 0x0;
|
||||
}
|
||||
|
||||
setData(data);
|
||||
setDelay(delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the direction this diode is facing
|
||||
*
|
||||
* @return The direction this diode is facing
|
||||
*
|
||||
* @see BlockFace
|
||||
*/
|
||||
@Override
|
||||
public BlockFace getFacing() {
|
||||
byte data = (byte) (getData() & 0x3);
|
||||
|
||||
switch (data) {
|
||||
case 0x0:
|
||||
default:
|
||||
return BlockFace.NORTH;
|
||||
case 0x0:
|
||||
default:
|
||||
return BlockFace.NORTH;
|
||||
|
||||
case 0x1:
|
||||
return BlockFace.EAST;
|
||||
case 0x1:
|
||||
return BlockFace.EAST;
|
||||
|
||||
case 0x2:
|
||||
return BlockFace.SOUTH;
|
||||
case 0x2:
|
||||
return BlockFace.SOUTH;
|
||||
|
||||
case 0x3:
|
||||
return BlockFace.WEST;
|
||||
case 0x3:
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,4 +196,14 @@ public class Diode extends MaterialData implements Directional {
|
||||
public Diode clone() {
|
||||
return (Diode) super.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the diode is powered.
|
||||
*
|
||||
* @return true if the diode is powered
|
||||
*/
|
||||
@Override
|
||||
public boolean isPowered() {
|
||||
return getItemType() == Material.DIODE_BLOCK_ON;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user