summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorryanbennitt <ryanbennitt@googlemail.com>2016-03-20 14:20:46 +0000
committermd_5 <git@md-5.net>2016-03-26 09:39:19 +1100
commitccc245a7e6fd9406220d69d583b5e8eeeb0bfe3e (patch)
tree18967239e742c826806d5fa9442cb7d8faf7d3e6 /src/main/java/org
parentdb1761e3c9dd2a74cda188145a5d3dc9da57f712 (diff)
downloadbukkit-ccc245a7e6fd9406220d69d583b5e8eeeb0bfe3e.tar
bukkit-ccc245a7e6fd9406220d69d583b5e8eeeb0bfe3e.tar.gz
bukkit-ccc245a7e6fd9406220d69d583b5e8eeeb0bfe3e.tar.lz
bukkit-ccc245a7e6fd9406220d69d583b5e8eeeb0bfe3e.tar.xz
bukkit-ccc245a7e6fd9406220d69d583b5e8eeeb0bfe3e.zip
SPIGOT-1464: Fixed setting Mushroom faces
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/bukkit/material/Mushroom.java120
-rw-r--r--src/main/java/org/bukkit/material/types/MushroomBlockTexture.java130
2 files changed, 238 insertions, 12 deletions
diff --git a/src/main/java/org/bukkit/material/Mushroom.java b/src/main/java/org/bukkit/material/Mushroom.java
index 40077a6a..3b372ec3 100644
--- a/src/main/java/org/bukkit/material/Mushroom.java
+++ b/src/main/java/org/bukkit/material/Mushroom.java
@@ -6,13 +6,16 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
+import org.bukkit.material.types.MushroomBlockTexture;
/**
- * Represents a huge mushroom block
+ * Represents a huge mushroom block with certain combinations of faces set to
+ * cap, pores or stem.
+ *
+ * @see Material#HUGE_MUSHROOM_1
+ * @see Material#HUGE_MUSHROOM_2
*/
public class Mushroom extends MaterialData {
- private static final byte SHROOM_NONE = 0;
- private static final byte SHROOM_STEM = 10;
private static final byte NORTH_LIMIT = 4;
private static final byte SOUTH_LIMIT = 6;
private static final byte EAST_WEST_LIMIT = 3;
@@ -21,12 +24,54 @@ public class Mushroom extends MaterialData {
private static final byte NORTH_SOUTH_MOD = 3;
private static final byte EAST_WEST_MOD = 1;
+ /**
+ * Constructs a brown/red mushroom block with all sides set to pores.
+ *
+ * @param shroom A brown or red mushroom material type.
+ *
+ * @see Material#HUGE_MUSHROOM_1
+ * @see Material#HUGE_MUSHROOM_2
+ */
public Mushroom(Material shroom) {
super(shroom);
Validate.isTrue(shroom == Material.HUGE_MUSHROOM_1 || shroom == Material.HUGE_MUSHROOM_2, "Not a mushroom!");
}
/**
+ * Constructs a brown/red mushroom cap block with the specified face or
+ * faces set to cap texture.
+ *
+ * Setting any of the four sides will also set the top to cap.
+ *
+ * To set two side faces at once use e.g. north-west.
+ *
+ * Specify self to set all six faces at once.
+ *
+ * @param shroom A brown or red mushroom material type.
+ * @param capFace The face or faces to set to mushroom cap texture.
+ *
+ * @see Material#HUGE_MUSHROOM_1
+ * @see Material#HUGE_MUSHROOM_2
+ * @see BlockFace
+ */
+ public Mushroom(Material shroom, BlockFace capFace) {
+ this(shroom, MushroomBlockTexture.getCapByFace(capFace));
+ }
+
+ /**
+ * Constructs a brown/red mushroom block with the specified textures.
+ *
+ * @param shroom A brown or red mushroom material type.
+ * @param texture The textured mushroom faces.
+ *
+ * @see Material#HUGE_MUSHROOM_1
+ * @see Material#HUGE_MUSHROOM_2
+ */
+ public Mushroom(Material shroom, MushroomBlockTexture texture) {
+ this(shroom, texture.getData());
+ }
+
+ /**
* @param shroom the type
* @param data the raw data value
* @deprecated Magic value
@@ -52,18 +97,45 @@ public class Mushroom extends MaterialData {
* @return Whether this is a mushroom stem.
*/
public boolean isStem() {
- return getData() == SHROOM_STEM;
+ return getData() == MushroomBlockTexture.STEM_SIDES.getData() || getData() == MushroomBlockTexture.ALL_STEM.getData();
}
/**
* Sets this to be a mushroom stem.
+ *
+ * @see MushroomBlockTexture#STEM_SIDES
+ * @see MushroomBlockTexture#ALL_STEM
+ *
+ * @deprecated Use
+ * {@link #setBlockTexture(org.bukkit.material.types.MushroomBlockTexture)}
+ * with {@link MushroomBlockTexture#STEM_SIDES } or
+ * {@link MushroomBlockTexture#ALL_STEM}
*/
+ @Deprecated
public void setStem() {
- setData((byte) 10);
+ setData((byte) MushroomBlockTexture.STEM_SIDES.getData());
+ }
+
+ /**
+ * Gets the mushroom texture of this block.
+ *
+ * @return The mushroom texture of this block
+ */
+ public MushroomBlockTexture getBlockTexture() {
+ return MushroomBlockTexture.getByData(getData());
+ }
+
+ /**
+ * Sets the mushroom texture of this block.
+ *
+ * @param texture The mushroom texture to set
+ */
+ public void setBlockTexture(MushroomBlockTexture texture) {
+ setData(texture.getData());
}
/**
- * Checks whether a face of the block is painted.
+ * Checks whether a face of the block is painted with cap texture.
*
* @param face The face to check.
* @return True if it is painted.
@@ -71,7 +143,8 @@ public class Mushroom extends MaterialData {
public boolean isFacePainted(BlockFace face) {
byte data = getData();
- if (data == SHROOM_NONE || data == SHROOM_STEM) {
+ if (data == MushroomBlockTexture.ALL_PORES.getData() || data == MushroomBlockTexture.STEM_SIDES.getData()
+ || data == MushroomBlockTexture.ALL_STEM.getData()) {
return false;
}
@@ -86,6 +159,9 @@ public class Mushroom extends MaterialData {
return data % EAST_WEST_LIMIT == WEST_REMAINDER;
case UP:
return true;
+ case DOWN:
+ case SELF:
+ return data == MushroomBlockTexture.ALL_CAP.getData();
default:
return false;
}
@@ -99,7 +175,10 @@ public class Mushroom extends MaterialData {
* @param face The face to paint or unpaint.
* @param painted True if you want to paint it, false if you want the
* pores to show.
+ *
+ * @deprecated Use MushroomBlockType cap options
*/
+ @Deprecated
public void setFacePainted(BlockFace face, boolean painted) {
if (painted == isFacePainted(face)) {
return;
@@ -107,8 +186,13 @@ public class Mushroom extends MaterialData {
byte data = getData();
- if (data == SHROOM_STEM) {
- data = 5;
+ if (data == MushroomBlockTexture.ALL_PORES.getData() || isStem()) {
+ data = MushroomBlockTexture.CAP_TOP.getData();
+ }
+ if (data == MushroomBlockTexture.ALL_CAP.getData() && !painted) {
+ data = MushroomBlockTexture.CAP_TOP.getData();
+ face = face.getOppositeFace();
+ painted = true;
}
switch (face) {
@@ -146,9 +230,17 @@ public class Mushroom extends MaterialData {
break;
case UP:
if (!painted) {
- data = 0;
+ data = MushroomBlockTexture.ALL_PORES.getData();
+ }
+ break;
+ case SELF:
+ case DOWN:
+ if (painted) {
+ data = MushroomBlockTexture.ALL_CAP.getData();
+ }
+ else {
+ data = MushroomBlockTexture.ALL_PORES.getData();
}
-
break;
default:
throw new IllegalArgumentException("Can't paint that face of a mushroom!");
@@ -184,12 +276,16 @@ public class Mushroom extends MaterialData {
faces.add(BlockFace.UP);
}
+ if (isFacePainted(BlockFace.DOWN)) {
+ faces.add(BlockFace.DOWN);
+ }
+
return faces;
}
@Override
public String toString() {
- return Material.getMaterial(getItemTypeId()).toString() + (isStem() ? "{STEM}" : getPaintedFaces());
+ return Material.getMaterial(getItemTypeId()).toString() + (isStem() ? " STEM " : " CAP ") + getPaintedFaces();
}
@Override
diff --git a/src/main/java/org/bukkit/material/types/MushroomBlockTexture.java b/src/main/java/org/bukkit/material/types/MushroomBlockTexture.java
new file mode 100644
index 00000000..6525ab45
--- /dev/null
+++ b/src/main/java/org/bukkit/material/types/MushroomBlockTexture.java
@@ -0,0 +1,130 @@
+package org.bukkit.material.types;
+
+import java.util.Map;
+
+import org.bukkit.block.BlockFace;
+
+import com.google.common.collect.Maps;
+
+/**
+ * Represents the different textured blocks of mushroom.
+ */
+public enum MushroomBlockTexture {
+
+ /**
+ * Pores on all faces.
+ */
+ ALL_PORES(0, null),
+ /**
+ * Cap texture on the top, north and west faces, pores on remaining sides.
+ */
+ CAP_NORTH_WEST(1, BlockFace.NORTH_WEST),
+ /**
+ * Cap texture on the top and north faces, pores on remaining sides.
+ */
+ CAP_NORTH(2, BlockFace.NORTH),
+ /**
+ * Cap texture on the top, north and east faces, pores on remaining sides.
+ */
+ CAP_NORTH_EAST(3, BlockFace.NORTH_EAST),
+ /**
+ * Cap texture on the top and west faces, pores on remaining sides.
+ */
+ CAP_WEST(4, BlockFace.WEST),
+ /**
+ * Cap texture on the top face, pores on remaining sides.
+ */
+ CAP_TOP(5, BlockFace.UP),
+ /**
+ * Cap texture on the top and east faces, pores on remaining sides.
+ */
+ CAP_EAST(6, BlockFace.EAST),
+ /**
+ * Cap texture on the top, south and west faces, pores on remaining sides.
+ */
+ CAP_SOUTH_WEST(7, BlockFace.SOUTH_WEST),
+ /**
+ * Cap texture on the top and south faces, pores on remaining sides.
+ */
+ CAP_SOUTH(8, BlockFace.SOUTH),
+ /**
+ * Cap texture on the top, south and east faces, pores on remaining sides.
+ */
+ CAP_SOUTH_EAST(9, BlockFace.SOUTH_EAST),
+ /**
+ * Stem texture on the north, east, south and west faces, pores on top and
+ * bottom.
+ */
+ STEM_SIDES(10, null),
+ /**
+ * Cap texture on all faces.
+ */
+ ALL_CAP(14, BlockFace.SELF),
+ /**
+ * Stem texture on all faces.
+ */
+ ALL_STEM(15, null);
+ private final static Map<Byte, MushroomBlockTexture> BY_DATA = Maps.newHashMap();
+ private final static Map<BlockFace, MushroomBlockTexture> BY_BLOCKFACE = Maps.newHashMap();
+
+ private final Byte data;
+ private final BlockFace capFace;
+
+ private MushroomBlockTexture(final int data, final BlockFace capFace) {
+ this.data = (byte) data;
+ this.capFace = capFace;
+ }
+
+ /**
+ * Gets the associated data value representing this mushroom block face.
+ *
+ * @return A byte containing the data value of this mushroom block face
+ * @deprecated Magic value
+ */
+ @Deprecated
+ public byte getData() {
+ return data;
+ }
+
+ /**
+ * Gets the face that has cap texture.
+ *
+ * @return The cap face
+ */
+ public BlockFace getCapFace() {
+ return capFace;
+ }
+
+ /**
+ * Gets the MushroomBlockType with the given data value.
+ *
+ * @param data Data value to fetch
+ * @return The {@link MushroomBlockTexture} representing the given value, or
+ * null if it doesn't exist
+ * @deprecated Magic value
+ */
+ @Deprecated
+ public static MushroomBlockTexture getByData(final byte data) {
+ return BY_DATA.get(data);
+ }
+
+ /**
+ * Gets the MushroomBlockType with cap texture on the given block face.
+ *
+ * @param face the required block face with cap texture
+ * @return The {@link MushroomBlockTexture} representing the given block
+ * face, or null if it doesn't exist
+ *
+ * @see BlockFace
+ */
+ public static MushroomBlockTexture getCapByFace(final BlockFace face) {
+ return BY_BLOCKFACE.get(face);
+ }
+
+ static {
+ for (MushroomBlockTexture type : values()) {
+ BY_DATA.put(type.data, type);
+ BY_BLOCKFACE.put(type.capFace, type);
+ }
+ }
+}