13
0
geforkt von Mirrors/Paper

Fixed TrapDoor and added MaterialData for LONG_GRASS. Thanks sunkid!

By: EvilSeph <evilseph@unaligned.org>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2011-06-07 02:15:19 -04:00
Ursprung e12c49e9d1
Commit 3996bf8026
4 geänderte Dateien mit 162 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,57 @@
package org.bukkit;
import java.util.HashMap;
import java.util.Map;
/**
* Represents the different types of grass.
*/
public enum GrassSpecies {
/**
* Represents the dead looking grass.
*/
DEAD((byte) 0x0),
/**
* Represents the normal grass species.
*/
NORMAL((byte) 0x1),
/**
* Represents the fern-looking grass species.
*/
FERN_LIKE((byte) 0x2);
private final byte data;
private final static Map<Byte, GrassSpecies> species = new HashMap<Byte, GrassSpecies>();
private GrassSpecies(final byte data) {
this.data = data;
}
/**
* Gets the associated data value representing this species
*
* @return A byte containing the data value of this grass species
*/
public byte getData() {
return data;
}
/**
* Gets the GrassSpecies with the given data value
*
* @param data
* Data value to fetch
* @return The {@link GrassSpecies} representing the given value, or null if
* it doesn't exist
*/
public static GrassSpecies getByData(final byte data) {
return species.get(data);
}
static {
for (GrassSpecies s : GrassSpecies.values()) {
species.put(s.getData(), s);
}
}
}

Datei anzeigen

@ -42,7 +42,7 @@ public enum Material {
POWERED_RAIL(27, PoweredRail.class), POWERED_RAIL(27, PoweredRail.class),
DETECTOR_RAIL(28, DetectorRail.class), DETECTOR_RAIL(28, DetectorRail.class),
WEB(30), WEB(30),
LONG_GRASS(31), LONG_GRASS(31, LongGrass.class),
DEAD_BUSH(32), DEAD_BUSH(32),
WOOL(35, Wool.class), WOOL(35, Wool.class),
YELLOW_FLOWER(37), YELLOW_FLOWER(37),

Datei anzeigen

@ -0,0 +1,57 @@
package org.bukkit.material;
import org.bukkit.GrassSpecies;
import org.bukkit.Material;
/**
* Represents the different types of long grasses.
*/
public class LongGrass extends MaterialData {
public LongGrass() {
super(Material.LOG);
}
public LongGrass(GrassSpecies species) {
this();
setSpecies(species);
}
public LongGrass(final int type) {
super(type);
}
public LongGrass(final Material type) {
super(type);
}
public LongGrass(final int type, final byte data) {
super(type, data);
}
public LongGrass(final Material type, final byte data) {
super(type, data);
}
/**
* Gets the current species of this grass
*
* @return GrassSpecies of this grass
*/
public GrassSpecies getSpecies() {
return GrassSpecies.getByData(getData());
}
/**
* Sets the species of this grass
*
* @param species New species of this grass
*/
public void setSpecies(GrassSpecies species) {
setData(species.getData());
}
@Override
public String toString() {
return getSpecies() + " " + super.toString();
}
}

Datei anzeigen

@ -1,12 +1,12 @@
package org.bukkit.material; package org.bukkit.material;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace;
/** /**
* Represents a trap door * Represents a trap door
*/ */
public class TrapDoor extends MaterialData implements Redstone { public class TrapDoor extends SimpleAttachableMaterialData {
public TrapDoor() { public TrapDoor() {
super(Material.TRAP_DOOR); super(Material.TRAP_DOOR);
} }
@ -28,17 +28,56 @@ public class TrapDoor extends MaterialData implements Redstone {
} }
/** /**
* Gets the current state of this Material, indicating if it's powered or * Check to see if the trap door is open.
* unpowered
* *
* @return true if powered, otherwise false * @return true if the trap door is open.
*/ */
public boolean isPowered() { public boolean isOpen() {
return (getData() & 0x8) == 0x8; return ((getData() & 0x4) == 0x4);
}
public BlockFace getAttachedFace() {
byte data = (byte) (getData() & 0x3);
switch (data) {
case 0x0:
return BlockFace.WEST;
case 0x1:
return BlockFace.EAST;
case 0x2:
return BlockFace.SOUTH;
case 0x3:
return BlockFace.NORTH;
}
return null;
}
public void setFacingDirection(BlockFace face) {
byte data = (byte) (getData() & 0x4);
switch (face) {
case WEST:
data |= 0x1;
break;
case NORTH:
data |= 0x2;
break;
case SOUTH:
data |= 0x3;
break;
}
setData(data);
} }
@Override @Override
public String toString() { public String toString() {
return super.toString() + "[powered=" + isPowered() + "]"; return (isOpen() ? "OPEN " : "CLOSED ") + super.toString() + " with hinges set " + getAttachedFace();
} }
} }