Change inheritance for new MaterialData.

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
Bukkit/Spigot 2012-08-05 22:01:54 -05:00
parent 5154864bbc
commit d63210b3ec
4 changed files with 82 additions and 53 deletions

View File

@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace;
/**
* Represents a chest
*/
public class Chest extends FurnaceAndDispenser {
public class Chest extends DirectionalContainer {
public Chest() {
super(Material.CHEST);

View File

@ -0,0 +1,78 @@
package org.bukkit.material;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
/**
* Represents a furnace or a dispenser.
*/
public class DirectionalContainer extends MaterialData implements Directional {
public DirectionalContainer(final int type) {
super(type);
}
public DirectionalContainer(final Material type) {
super(type);
}
public DirectionalContainer(final int type, final byte data) {
super(type, data);
}
public DirectionalContainer(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();
}
@Override
public DirectionalContainer clone() {
return (DirectionalContainer) super.clone();
}
}

View File

@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace;
/**
* Represents an ender chest
*/
public class EnderChest extends FurnaceAndDispenser {
public class EnderChest extends DirectionalContainer {
public EnderChest() {
super(Material.ENDER_CHEST);

View File

@ -1,12 +1,11 @@
package org.bukkit.material;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
/**
* Represents a furnace or a dispenser.
* Represents a furnace or dispenser, two types of directional containers
*/
public class FurnaceAndDispenser extends MaterialData implements Directional {
public class FurnaceAndDispenser extends DirectionalContainer {
public FurnaceAndDispenser(final int type) {
super(type);
}
@ -23,54 +22,6 @@ public class FurnaceAndDispenser extends MaterialData implements Directional {
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();
}
@Override
public FurnaceAndDispenser clone() {
return (FurnaceAndDispenser) super.clone();