geforkt von Mirrors/Paper
SPIGOT-1464: Fixed setting Mushroom faces
By: ryanbennitt <ryanbennitt@googlemail.com>
Dieser Commit ist enthalten in:
Ursprung
b93b212047
Commit
3e1845033a
@ -6,13 +6,16 @@ import java.util.Set;
|
|||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockFace;
|
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 {
|
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 NORTH_LIMIT = 4;
|
||||||
private static final byte SOUTH_LIMIT = 6;
|
private static final byte SOUTH_LIMIT = 6;
|
||||||
private static final byte EAST_WEST_LIMIT = 3;
|
private static final byte EAST_WEST_LIMIT = 3;
|
||||||
@ -21,11 +24,53 @@ public class Mushroom extends MaterialData {
|
|||||||
private static final byte NORTH_SOUTH_MOD = 3;
|
private static final byte NORTH_SOUTH_MOD = 3;
|
||||||
private static final byte EAST_WEST_MOD = 1;
|
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) {
|
public Mushroom(Material shroom) {
|
||||||
super(shroom);
|
super(shroom);
|
||||||
Validate.isTrue(shroom == Material.HUGE_MUSHROOM_1 || shroom == Material.HUGE_MUSHROOM_2, "Not a mushroom!");
|
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 shroom the type
|
||||||
* @param data the raw data value
|
* @param data the raw data value
|
||||||
@ -52,18 +97,45 @@ public class Mushroom extends MaterialData {
|
|||||||
* @return Whether this is a mushroom stem.
|
* @return Whether this is a mushroom stem.
|
||||||
*/
|
*/
|
||||||
public boolean isStem() {
|
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.
|
* 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() {
|
public void setStem() {
|
||||||
setData((byte) 10);
|
setData((byte) MushroomBlockTexture.STEM_SIDES.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a face of the block is painted.
|
* 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 with cap texture.
|
||||||
*
|
*
|
||||||
* @param face The face to check.
|
* @param face The face to check.
|
||||||
* @return True if it is painted.
|
* @return True if it is painted.
|
||||||
@ -71,7 +143,8 @@ public class Mushroom extends MaterialData {
|
|||||||
public boolean isFacePainted(BlockFace face) {
|
public boolean isFacePainted(BlockFace face) {
|
||||||
byte data = getData();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +159,9 @@ public class Mushroom extends MaterialData {
|
|||||||
return data % EAST_WEST_LIMIT == WEST_REMAINDER;
|
return data % EAST_WEST_LIMIT == WEST_REMAINDER;
|
||||||
case UP:
|
case UP:
|
||||||
return true;
|
return true;
|
||||||
|
case DOWN:
|
||||||
|
case SELF:
|
||||||
|
return data == MushroomBlockTexture.ALL_CAP.getData();
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -99,7 +175,10 @@ public class Mushroom extends MaterialData {
|
|||||||
* @param face The face to paint or unpaint.
|
* @param face The face to paint or unpaint.
|
||||||
* @param painted True if you want to paint it, false if you want the
|
* @param painted True if you want to paint it, false if you want the
|
||||||
* pores to show.
|
* pores to show.
|
||||||
|
*
|
||||||
|
* @deprecated Use MushroomBlockType cap options
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setFacePainted(BlockFace face, boolean painted) {
|
public void setFacePainted(BlockFace face, boolean painted) {
|
||||||
if (painted == isFacePainted(face)) {
|
if (painted == isFacePainted(face)) {
|
||||||
return;
|
return;
|
||||||
@ -107,8 +186,13 @@ public class Mushroom extends MaterialData {
|
|||||||
|
|
||||||
byte data = getData();
|
byte data = getData();
|
||||||
|
|
||||||
if (data == SHROOM_STEM) {
|
if (data == MushroomBlockTexture.ALL_PORES.getData() || isStem()) {
|
||||||
data = 5;
|
data = MushroomBlockTexture.CAP_TOP.getData();
|
||||||
|
}
|
||||||
|
if (data == MushroomBlockTexture.ALL_CAP.getData() && !painted) {
|
||||||
|
data = MushroomBlockTexture.CAP_TOP.getData();
|
||||||
|
face = face.getOppositeFace();
|
||||||
|
painted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (face) {
|
switch (face) {
|
||||||
@ -146,9 +230,17 @@ public class Mushroom extends MaterialData {
|
|||||||
break;
|
break;
|
||||||
case UP:
|
case UP:
|
||||||
if (!painted) {
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Can't paint that face of a mushroom!");
|
throw new IllegalArgumentException("Can't paint that face of a mushroom!");
|
||||||
@ -184,12 +276,16 @@ public class Mushroom extends MaterialData {
|
|||||||
faces.add(BlockFace.UP);
|
faces.add(BlockFace.UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isFacePainted(BlockFace.DOWN)) {
|
||||||
|
faces.add(BlockFace.DOWN);
|
||||||
|
}
|
||||||
|
|
||||||
return faces;
|
return faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Material.getMaterial(getItemTypeId()).toString() + (isStem() ? "{STEM}" : getPaintedFaces());
|
return Material.getMaterial(getItemTypeId()).toString() + (isStem() ? " STEM " : " CAP ") + getPaintedFaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,12 @@ import org.bukkit.TreeSpecies;
|
|||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.material.Door;
|
import org.bukkit.material.Door;
|
||||||
import org.bukkit.material.Leaves;
|
import org.bukkit.material.Leaves;
|
||||||
|
import org.bukkit.material.Mushroom;
|
||||||
import org.bukkit.material.Sapling;
|
import org.bukkit.material.Sapling;
|
||||||
import org.bukkit.material.Tree;
|
import org.bukkit.material.Tree;
|
||||||
import org.bukkit.material.Wood;
|
import org.bukkit.material.Wood;
|
||||||
import org.bukkit.material.WoodenStep;
|
import org.bukkit.material.WoodenStep;
|
||||||
|
import org.bukkit.material.types.MushroomBlockTexture;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class MaterialDataTest {
|
public class MaterialDataTest {
|
||||||
@ -231,4 +233,30 @@ public class MaterialDataTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMushroom() {
|
||||||
|
Material[] mushroomTypes = new Material[] { Material.HUGE_MUSHROOM_1, Material.HUGE_MUSHROOM_2 };
|
||||||
|
BlockFace[] setFaces = new BlockFace[] { BlockFace.SELF, BlockFace.UP, BlockFace.NORTH,
|
||||||
|
BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH_EAST, BlockFace.NORTH_WEST,
|
||||||
|
BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST };
|
||||||
|
MushroomBlockTexture[] textures = MushroomBlockTexture.values();
|
||||||
|
for (Material type : mushroomTypes) {
|
||||||
|
Mushroom mushroom = new Mushroom(type);
|
||||||
|
assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type));
|
||||||
|
assertThat("Constructed with default pores face", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.ALL_PORES));
|
||||||
|
|
||||||
|
for (int f = 0; f < setFaces.length; f++) {
|
||||||
|
mushroom = new Mushroom(type, setFaces[f]);
|
||||||
|
assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type));
|
||||||
|
assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(MushroomBlockTexture.getCapByFace(setFaces[f])));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (MushroomBlockTexture texture : textures) {
|
||||||
|
mushroom = new Mushroom(type, texture);
|
||||||
|
assertThat("Constructed with correct mushroom type", mushroom.getItemType(), equalTo(type));
|
||||||
|
assertThat("Constructed with correct texture", mushroom.getBlockTexture(), equalTo(texture));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren