13
0
geforkt von Mirrors/Paper

added support for SmoothBrick and changed steps to a TexturedMaterial

By: sunkid <sunkid@iminurnetz.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2011-09-15 16:33:53 -07:00
Ursprung fd48f02fc3
Commit 1968b78a12
4 geänderte Dateien mit 131 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -110,7 +110,7 @@ public enum Material {
LOCKED_CHEST(95),
TRAP_DOOR(96, TrapDoor.class),
MONSTER_EGGS(97),
SMOOTH_BRICK(98),
SMOOTH_BRICK(98, SmoothBrick.class),
HUGE_MUSHROOM_1(99),
HUGE_MUSHROOM_2(100),
IRON_FENCE(101),

Datei anzeigen

@ -0,0 +1,48 @@
package org.bukkit.material;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
/**
* Represents the different types of smooth bricks.
*/
public class SmoothBrick extends TexturedMaterial {
private static final List<Material> textures = new ArrayList<Material>();
static {
textures.add(Material.STONE);
textures.add(Material.MOSSY_COBBLESTONE);
textures.add(Material.COBBLESTONE);
}
public SmoothBrick() {
super(Material.SMOOTH_BRICK);
}
public SmoothBrick(final int type) {
super(type);
}
public SmoothBrick(final Material type) {
super((textures.contains(type)) ? Material.SMOOTH_BRICK : type);
if (textures.contains(type)) {
setMaterial(type);
}
}
public SmoothBrick(final int type, final byte data) {
super(type, data);
}
public SmoothBrick(final Material type, final byte data) {
super(type, data);
}
@Override
public List<Material> getTextures() {
return textures;
}
}

Datei anzeigen

@ -1,19 +1,22 @@
package org.bukkit.material;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
/**
* Represents the different types of steps.
*/
public class Step extends MaterialData {
private static HashSet<Material> stepTypes = new HashSet<Material>();
public class Step extends TexturedMaterial {
private static final List<Material> textures = new ArrayList<Material>();
static {
stepTypes.add(Material.SANDSTONE);
stepTypes.add(Material.WOOD);
stepTypes.add(Material.COBBLESTONE);
stepTypes.add(Material.STONE);
textures.add(Material.STONE);
textures.add(Material.SANDSTONE);
textures.add(Material.WOOD);
textures.add(Material.COBBLESTONE);
textures.add(Material.BRICK);
textures.add(Material.SMOOTH_BRICK);
}
public Step() {
@ -25,8 +28,8 @@ public class Step extends MaterialData {
}
public Step(final Material type) {
super((stepTypes.contains(type)) ? Material.STEP : type);
if (stepTypes.contains(type)) {
super((textures.contains(type)) ? Material.STEP : type);
if (textures.contains(type)) {
setMaterial(type);
}
}
@ -39,55 +42,8 @@ public class Step extends MaterialData {
super(type, data);
}
/**
* Gets the current Material this step is made of
*
* @return Material of this step
*/
public Material getMaterial() {
switch ((int) getData()) {
case 1:
return Material.SANDSTONE;
case 2:
return Material.WOOD;
case 3:
return Material.COBBLESTONE;
case 0:
default:
return Material.STONE;
}
}
/**
* Sets the material this step is made of
*
* @param material New material of this step
*/
public void setMaterial(Material material) {
switch (material) {
case SANDSTONE:
setData((byte) 0x1);
break;
case WOOD:
setData((byte) 0x2);
break;
case COBBLESTONE:
setData((byte) 0x3);
break;
case STONE:
default:
setData((byte) 0x0);
}
}
@Override
public String toString() {
return getMaterial() + " " + super.toString();
public List<Material> getTextures() {
return textures;
}
}

Datei anzeigen

@ -0,0 +1,68 @@
package org.bukkit.material;
import java.util.List;
import org.bukkit.Material;
/**
* Represents textured materials like steps and smooth bricks
*/
public abstract class TexturedMaterial extends MaterialData {
public TexturedMaterial(Material m) {
super(m);
}
public TexturedMaterial(int type) {
super(type);
}
public TexturedMaterial(final int type, final byte data) {
super(type, data);
}
public TexturedMaterial(final Material type, final byte data) {
super(type, data);
}
/**
* Retrieve a list of possible textures. The first element of the list will be used as a default.
*
* @return a list of possible textures for this block
*/
public abstract List<Material> getTextures();
/**
* Gets the current Material this block is made of
*
* @return Material of this block
*/
public Material getMaterial() {
int n = (int) getData();
if (n > getTextures().size() - 1) {
n = 0;
}
return getTextures().get(n);
}
/**
* Sets the material this block is made of
*
* @param material
* New material of this block
*/
public void setMaterial(Material material) {
if (getTextures().contains(material)) {
setData((byte) getTextures().indexOf(material));
} else {
setData((byte) 0x0);
}
}
@Override
public String toString() {
return getMaterial() + " " + super.toString();
}
}