mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-14 03:35:51 -07:00
SPIGOT-1389: Fixed issues with setting tree species by expanding API
By: ryanbennitt <ryanbennitt@googlemail.com>
This commit is contained in:
@@ -4,16 +4,41 @@ import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
|
||||
/**
|
||||
* Represents the different types of leaves.
|
||||
* Represents the different types of leaf block that may be permanent or can
|
||||
* decay when too far from a log.
|
||||
*
|
||||
* @see Material.LEAVES
|
||||
* @see Material.LEAVES_2
|
||||
*/
|
||||
public class Leaves extends MaterialData {
|
||||
public class Leaves extends Wood {
|
||||
protected static final Material DEFAULT_TYPE = Material.LEAVES;
|
||||
protected static final boolean DEFAULT_DECAYABLE = true;
|
||||
|
||||
/**
|
||||
* Constructs a leaf block.
|
||||
*/
|
||||
public Leaves() {
|
||||
super(Material.LEAVES);
|
||||
this(DEFAULT_TYPE, DEFAULT_SPECIES, DEFAULT_DECAYABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a leaf block of the given tree species.
|
||||
*
|
||||
* @param species the species of the wood block
|
||||
*/
|
||||
public Leaves(TreeSpecies species) {
|
||||
this();
|
||||
setSpecies(species);
|
||||
this(DEFAULT_TYPE, species, DEFAULT_DECAYABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a leaf block of the given tree species and flag for whether
|
||||
* this leaf block will disappear when too far from a log.
|
||||
*
|
||||
* @param species the species of the wood block
|
||||
* @param isDecayable whether the block is permanent or can disappear
|
||||
*/
|
||||
public Leaves(TreeSpecies species, boolean isDecayable) {
|
||||
this(DEFAULT_TYPE, species, isDecayable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,8 +50,36 @@ public class Leaves extends MaterialData {
|
||||
super(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a leaf block of the given type.
|
||||
*
|
||||
* @param type the type of leaf block
|
||||
*/
|
||||
public Leaves(final Material type) {
|
||||
super(type);
|
||||
this(type, DEFAULT_SPECIES, DEFAULT_DECAYABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a leaf block of the given type and tree species.
|
||||
*
|
||||
* @param type the type of leaf block
|
||||
* @param species the species of the wood block
|
||||
*/
|
||||
public Leaves(final Material type, TreeSpecies species) {
|
||||
this(type, species, DEFAULT_DECAYABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a leaf block of the given type and tree species and flag for
|
||||
* whether this leaf block will disappear when too far from a log.
|
||||
*
|
||||
* @param type the type of leaf block
|
||||
* @param species the species of the wood block
|
||||
* @param isDecayable whether the block is permanent or can disappear
|
||||
*/
|
||||
public Leaves(final Material type, TreeSpecies species, boolean isDecayable) {
|
||||
super(type, species);
|
||||
setDecayable(isDecayable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,26 +103,50 @@ public class Leaves extends MaterialData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current species of this leave
|
||||
* Checks if this leaf block is in the process of decaying
|
||||
*
|
||||
* @return TreeSpecies of this leave
|
||||
* @return true if the leaf block is in the process of decaying
|
||||
*/
|
||||
public TreeSpecies getSpecies() {
|
||||
return TreeSpecies.getByData((byte) (getData() & 3));
|
||||
public boolean isDecaying() {
|
||||
return (getData() & 0x8) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the species of this leave
|
||||
* Set whether this leaf block is in the process of decaying
|
||||
*
|
||||
* @param species New species of this leave
|
||||
* @param isDecaying whether the block is decaying or not
|
||||
*/
|
||||
public void setSpecies(TreeSpecies species) {
|
||||
setData(species.getData());
|
||||
public void setDecaying(boolean isDecaying) {
|
||||
setData((byte) ((getData() & 0x3) | (isDecaying
|
||||
? 0x8 // Clear the permanent flag to make this a decayable flag and set the decaying flag
|
||||
: (getData() & 0x4)))); // Only persist the decayable flag if this is not a decaying block
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this leaf block is permanent or can decay when too far from a
|
||||
* log
|
||||
*
|
||||
* @return true if the leaf block is permanent or can decay when too far
|
||||
* from a log
|
||||
*/
|
||||
public boolean isDecayable() {
|
||||
return (getData() & 0x4) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this leaf block will disappear when too far from a log
|
||||
*
|
||||
* @param isDecayable whether the block is permanent or can disappear
|
||||
*/
|
||||
public void setDecayable(boolean isDecayable) {
|
||||
setData((byte) ((getData() & 0x3) | (isDecayable
|
||||
? (getData() & 0x8) // Only persist the decaying flag if this is a decayable block
|
||||
: 0x4)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSpecies() + " " + super.toString();
|
||||
return getSpecies() + (isDecayable() ? " DECAYABLE " : " PERMANENT ") + (isDecaying() ? " DECAYING " : " ") + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
121
paper-api/src/main/java/org/bukkit/material/Sapling.java
Normal file
121
paper-api/src/main/java/org/bukkit/material/Sapling.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package org.bukkit.material;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
|
||||
/**
|
||||
* Represents the different types of Tree block that face a direction.
|
||||
*
|
||||
* @see Material.SAPLING
|
||||
*/
|
||||
public class Sapling extends Wood {
|
||||
|
||||
/**
|
||||
* Constructs a sapling.
|
||||
*/
|
||||
public Sapling() {
|
||||
this(DEFAULT_SPECIES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sapling of the given tree species.
|
||||
*
|
||||
* @param species the species of the sapling
|
||||
*/
|
||||
public Sapling(TreeSpecies species) {
|
||||
this(species, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sapling of the given tree species and if is it instant
|
||||
* growable
|
||||
*
|
||||
* @param species the species of the tree block
|
||||
* @param isInstantGrowable true if the Sapling should grow when next ticked with bonemeal
|
||||
*/
|
||||
public Sapling(TreeSpecies species, boolean isInstantGrowable) {
|
||||
this(Material.SAPLING, species, isInstantGrowable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sapling of the given type.
|
||||
*
|
||||
* @param type the type of tree block
|
||||
*/
|
||||
public Sapling(final Material type) {
|
||||
this(type, DEFAULT_SPECIES, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sapling of the given type and tree species.
|
||||
*
|
||||
* @param type the type of sapling
|
||||
* @param species the species of the sapling
|
||||
*/
|
||||
public Sapling(final Material type, TreeSpecies species) {
|
||||
this(type, species, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sapling of the given type and tree species and if is it
|
||||
* instant growable
|
||||
*
|
||||
* @param type the type of sapling
|
||||
* @param species the species of the sapling
|
||||
* @param isInstantGrowable true if the Sapling should grow when next ticked
|
||||
* with bonemeal
|
||||
*/
|
||||
public Sapling(final Material type, TreeSpecies species, boolean isInstantGrowable) {
|
||||
super(type, species);
|
||||
setIsInstantGrowable(isInstantGrowable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the raw type id
|
||||
* @param data the raw data value
|
||||
* @deprecated Magic value
|
||||
*/
|
||||
@Deprecated
|
||||
public Sapling(final int type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type
|
||||
* @param data the raw data value
|
||||
* @deprecated Magic value
|
||||
*/
|
||||
@Deprecated
|
||||
public Sapling(final Material type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Sapling would grow when next ticked with bonemeal
|
||||
*
|
||||
* @return true if the Sapling would grow when next ticked with bonemeal
|
||||
*/
|
||||
public boolean isInstantGrowable() {
|
||||
return (getData() & 0x8) == 0x8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this sapling will grow when next ticked with bonemeal
|
||||
*
|
||||
* @param isInstantGrowable true if the Sapling should grow when next ticked
|
||||
* with bonemeal
|
||||
*/
|
||||
public void setIsInstantGrowable(boolean isInstantGrowable) {
|
||||
setData(isInstantGrowable ? (byte) ((getData() & 0x7) | 0x8) : (byte) (getData() & 0x7));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSpecies() + " " + (isInstantGrowable() ? " IS_INSTANT_GROWABLE " : "") + " " + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sapling clone() {
|
||||
return (Sapling) super.clone();
|
||||
}
|
||||
}
|
@@ -5,22 +5,40 @@ import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
/**
|
||||
* Represents the different types of Trees.
|
||||
* Represents the different types of Tree block that face a direction.
|
||||
*
|
||||
* @see Material.LOG
|
||||
* @see Material.LOG_2
|
||||
*/
|
||||
public class Tree extends MaterialData {
|
||||
public class Tree extends Wood {
|
||||
protected static final Material DEFAULT_TYPE = Material.LOG;
|
||||
protected static final BlockFace DEFAULT_DIRECTION = BlockFace.UP;
|
||||
|
||||
/**
|
||||
* Constructs a tree block.
|
||||
*/
|
||||
public Tree() {
|
||||
super(Material.LOG);
|
||||
this(DEFAULT_TYPE, DEFAULT_SPECIES, DEFAULT_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a tree block of the given tree species.
|
||||
*
|
||||
* @param species the species of the tree block
|
||||
*/
|
||||
public Tree(TreeSpecies species) {
|
||||
this();
|
||||
setSpecies(species);
|
||||
this(DEFAULT_TYPE, species, DEFAULT_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a tree block of the given tree species, and facing the given
|
||||
* direction.
|
||||
*
|
||||
* @param species the species of the tree block
|
||||
* @param dir the direction the tree block is facing
|
||||
*/
|
||||
public Tree(TreeSpecies species, BlockFace dir) {
|
||||
this();
|
||||
setSpecies(species);
|
||||
setDirection(dir);
|
||||
this(DEFAULT_TYPE, species, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,8 +50,36 @@ public class Tree extends MaterialData {
|
||||
super(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a tree block of the given type.
|
||||
*
|
||||
* @param type the type of tree block
|
||||
*/
|
||||
public Tree(final Material type) {
|
||||
super(type);
|
||||
this(type, DEFAULT_SPECIES, DEFAULT_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a tree block of the given type and tree species.
|
||||
*
|
||||
* @param type the type of tree block
|
||||
* @param species the species of the tree block
|
||||
*/
|
||||
public Tree(final Material type, TreeSpecies species) {
|
||||
this(type, species, DEFAULT_DIRECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a tree block of the given type and tree species, and facing
|
||||
* the given direction.
|
||||
*
|
||||
* @param type the type of tree block
|
||||
* @param species the species of the tree block
|
||||
* @param dir the direction the tree block is facing
|
||||
*/
|
||||
public Tree(final Material type, TreeSpecies species, BlockFace dir) {
|
||||
super(type, species);
|
||||
setDirection(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,35 +102,18 @@ public class Tree extends MaterialData {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current species of this tree
|
||||
*
|
||||
* @return TreeSpecies of this tree
|
||||
*/
|
||||
public TreeSpecies getSpecies() {
|
||||
return TreeSpecies.getByData((byte) (getData() & 0x3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the species of this tree
|
||||
*
|
||||
* @param species New species of this tree
|
||||
*/
|
||||
public void setSpecies(TreeSpecies species) {
|
||||
setData((byte) ((getData() & 0xC) | species.getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get direction of the log
|
||||
*
|
||||
* @return one of:
|
||||
* <ul>
|
||||
* <li>BlockFace.TOP for upright (default)
|
||||
* <li>BlockFace.NORTH (east-west)
|
||||
* <li>BlockFace.WEST (north-south)
|
||||
* <li>BlockFace.SELF (directionless)
|
||||
* </ul>
|
||||
* <ul>
|
||||
* <li>BlockFace.TOP for upright (default)
|
||||
* <li>BlockFace.NORTH (east-west)
|
||||
* <li>BlockFace.WEST (north-south)
|
||||
* <li>BlockFace.SELF (directionless)
|
||||
* </ul>
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public BlockFace getDirection() {
|
||||
switch ((getData() >> 2) & 0x3) {
|
||||
case 0: // Up-down
|
||||
@@ -98,11 +127,13 @@ public class Tree extends MaterialData {
|
||||
return BlockFace.SELF;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set direction of the log
|
||||
*
|
||||
* @param dir - direction of end of log (BlockFace.SELF for no direction)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setDirection(BlockFace dir) {
|
||||
int dat;
|
||||
switch (dir) {
|
||||
@@ -113,17 +144,17 @@ public class Tree extends MaterialData {
|
||||
break;
|
||||
case WEST:
|
||||
case EAST:
|
||||
dat = 1;
|
||||
dat = 4; // 1<<2
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
dat = 2;
|
||||
dat = 8; // 2<<2
|
||||
break;
|
||||
case SELF:
|
||||
dat = 3;
|
||||
dat = 12; // 3<<2
|
||||
break;
|
||||
}
|
||||
setData((byte) ((getData() & 0x3) | (dat << 2)));
|
||||
setData((byte) ((getData() & 0x3) | dat));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
196
paper-api/src/main/java/org/bukkit/material/Wood.java
Normal file
196
paper-api/src/main/java/org/bukkit/material/Wood.java
Normal file
@@ -0,0 +1,196 @@
|
||||
package org.bukkit.material;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
|
||||
/**
|
||||
* Represents wood blocks of different species.
|
||||
*
|
||||
* @see Material.WOOD
|
||||
* @see Material.SAPLING
|
||||
* @see Material.WOOD_DOUBLE_STEP
|
||||
*/
|
||||
public class Wood extends MaterialData {
|
||||
protected static final Material DEFAULT_TYPE = Material.WOOD;
|
||||
protected static final TreeSpecies DEFAULT_SPECIES = TreeSpecies.GENERIC;
|
||||
|
||||
/**
|
||||
* Constructs a wood block.
|
||||
*/
|
||||
public Wood() {
|
||||
this(DEFAULT_TYPE, DEFAULT_SPECIES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a wood block of the given tree species.
|
||||
*
|
||||
* @param species the species of the wood block
|
||||
*/
|
||||
public Wood(TreeSpecies species) {
|
||||
this(DEFAULT_TYPE, species);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the raw type id
|
||||
* @deprecated Magic value
|
||||
*/
|
||||
@Deprecated
|
||||
public Wood(final int type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a wood block of the given type.
|
||||
*
|
||||
* @param type the type of wood block
|
||||
*/
|
||||
public Wood(final Material type) {
|
||||
this(type, DEFAULT_SPECIES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a wood block of the given type and tree species.
|
||||
*
|
||||
* @param type the type of wood block
|
||||
* @param species the species of the wood block
|
||||
*/
|
||||
public Wood(final Material type, final TreeSpecies species) {
|
||||
// Ensure only valid species-type combinations
|
||||
super(getSpeciesType(type, species));
|
||||
setSpecies(species);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the raw type id
|
||||
* @param data the raw data value
|
||||
* @deprecated Magic value
|
||||
*/
|
||||
@Deprecated
|
||||
public Wood(final int type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type
|
||||
* @param data the raw data value
|
||||
* @deprecated Magic value
|
||||
*/
|
||||
@Deprecated
|
||||
public Wood(final Material type, final byte data) {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current species of this wood block
|
||||
*
|
||||
* @return TreeSpecies of this wood block
|
||||
*/
|
||||
public TreeSpecies getSpecies() {
|
||||
switch (getItemType()) {
|
||||
case WOOD:
|
||||
case WOOD_DOUBLE_STEP:
|
||||
return TreeSpecies.getByData((byte) getData());
|
||||
case LOG:
|
||||
case LEAVES:
|
||||
return TreeSpecies.getByData((byte) (getData() & 0x3));
|
||||
case LOG_2:
|
||||
case LEAVES_2:
|
||||
return TreeSpecies.getByData((byte) ((getData() & 0x3) | 0x4));
|
||||
case SAPLING:
|
||||
case WOOD_STEP:
|
||||
return TreeSpecies.getByData((byte) (getData() & 0x7));
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid block type for tree species");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct the block type for certain species-type combinations.
|
||||
*
|
||||
* @param type The desired type
|
||||
* @param species The required species
|
||||
* @return The actual type for this species given the desired type
|
||||
*/
|
||||
private static Material getSpeciesType(Material type, TreeSpecies species) {
|
||||
switch (species) {
|
||||
case GENERIC:
|
||||
case REDWOOD:
|
||||
case BIRCH:
|
||||
case JUNGLE:
|
||||
switch (type) {
|
||||
case LOG_2:
|
||||
return Material.LOG;
|
||||
case LEAVES_2:
|
||||
return Material.LEAVES;
|
||||
default:
|
||||
}
|
||||
break;
|
||||
case ACACIA:
|
||||
case DARK_OAK:
|
||||
switch (type) {
|
||||
case LOG:
|
||||
return Material.LOG_2;
|
||||
case LEAVES:
|
||||
return Material.LEAVES_2;
|
||||
default:
|
||||
}
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the species of this wood block
|
||||
*
|
||||
* @param species New species of this wood block
|
||||
*/
|
||||
public void setSpecies(final TreeSpecies species) {
|
||||
boolean firstType = false;
|
||||
switch (getItemType()) {
|
||||
case WOOD:
|
||||
case WOOD_DOUBLE_STEP:
|
||||
setData(species.getData());
|
||||
break;
|
||||
case LOG:
|
||||
case LEAVES:
|
||||
firstType = true;
|
||||
// fall through to next switch statement below
|
||||
case LOG_2:
|
||||
case LEAVES_2:
|
||||
switch (species) {
|
||||
case GENERIC:
|
||||
case REDWOOD:
|
||||
case BIRCH:
|
||||
case JUNGLE:
|
||||
if (!firstType) {
|
||||
throw new IllegalArgumentException("Invalid tree species for block type, use block type 2 instead");
|
||||
}
|
||||
break;
|
||||
case ACACIA:
|
||||
case DARK_OAK:
|
||||
if (firstType) {
|
||||
throw new IllegalArgumentException("Invalid tree species for block type 2, use block type instead");
|
||||
}
|
||||
break;
|
||||
}
|
||||
setData((byte) ((getData() & 0xC) | (species.getData() & 0x3)));
|
||||
break;
|
||||
case SAPLING:
|
||||
case WOOD_STEP:
|
||||
setData((byte) ((getData() & 0x8) | species.getData()));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid block type for tree species");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSpecies() + " " + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Wood clone() {
|
||||
return (Wood) super.clone();
|
||||
}
|
||||
}
|
@@ -5,11 +5,39 @@ import org.bukkit.TreeSpecies;
|
||||
|
||||
/**
|
||||
* Represents the different types of wooden steps.
|
||||
*
|
||||
* @see Material.WOOD_STEP
|
||||
*/
|
||||
public class WoodenStep extends MaterialData {
|
||||
public class WoodenStep extends Wood {
|
||||
protected static final Material DEFAULT_TYPE = Material.WOOD_STEP;
|
||||
protected static final boolean DEFAULT_INVERTED = false;
|
||||
|
||||
/**
|
||||
* Constructs a wooden step.
|
||||
*/
|
||||
public WoodenStep() {
|
||||
super(Material.WOOD_STEP);
|
||||
this(DEFAULT_SPECIES, DEFAULT_INVERTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a wooden step of the given tree species.
|
||||
*
|
||||
* @param species the species of the wooden step
|
||||
*/
|
||||
public WoodenStep(TreeSpecies species) {
|
||||
this(species, DEFAULT_INVERTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a wooden step of the given type and tree species, either
|
||||
* inverted or not.
|
||||
*
|
||||
* @param species the species of the wooden step
|
||||
* @param inv true the step is at the top of the block
|
||||
*/
|
||||
public WoodenStep(final TreeSpecies species, boolean inv) {
|
||||
super(DEFAULT_TYPE, species);
|
||||
setInverted(inv);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,17 +49,6 @@ public class WoodenStep extends MaterialData {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public WoodenStep(TreeSpecies species) {
|
||||
this();
|
||||
setSpecies(species);
|
||||
}
|
||||
|
||||
public WoodenStep(TreeSpecies species, boolean inv) {
|
||||
this();
|
||||
setSpecies(species);
|
||||
setInverted(inv);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the raw type id
|
||||
* @param data the raw data value
|
||||
@@ -52,39 +69,23 @@ public class WoodenStep extends MaterialData {
|
||||
super(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current species of this tree
|
||||
*
|
||||
* @return TreeSpecies of this tree
|
||||
*/
|
||||
public TreeSpecies getSpecies() {
|
||||
return TreeSpecies.getByData((byte) (getData() & 0x3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the species of this tree
|
||||
*
|
||||
* @param species New species of this tree
|
||||
*/
|
||||
public void setSpecies(TreeSpecies species) {
|
||||
setData((byte) ((getData() & 0xC) | species.getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if step is inverted
|
||||
*
|
||||
* @return true if inverted (top half), false if normal (bottom half)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isInverted() {
|
||||
return ((getData() & 0x8) != 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set step inverted state
|
||||
*
|
||||
* @param inv - true if step is inverted (top half), false if step is
|
||||
* normal (bottom half)
|
||||
* @param inv - true if step is inverted (top half), false if step is normal
|
||||
* (bottom half)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setInverted(boolean inv) {
|
||||
int dat = getData() & 0x7;
|
||||
if (inv) {
|
||||
@@ -92,7 +93,7 @@ public class WoodenStep extends MaterialData {
|
||||
}
|
||||
setData((byte) dat);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public WoodenStep clone() {
|
||||
return (WoodenStep) super.clone();
|
||||
@@ -100,6 +101,6 @@ public class WoodenStep extends MaterialData {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " " + getSpecies() + (isInverted()?" inverted":"");
|
||||
return super.toString() + " " + getSpecies() + (isInverted() ? " inverted" : "");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user