From 6bae4e1a5b89e94469e71121d65f800af0916956 Mon Sep 17 00:00:00 2001 From: ryanbennitt Date: Sun, 3 Jan 2016 10:08:10 +0000 Subject: [PATCH] Fixed issues with setting tree species diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 0fb2605..1d399a2 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -24,6 +24,7 @@ import org.bukkit.material.FlowerPot; import org.bukkit.material.Furnace; import org.bukkit.material.Gate; import org.bukkit.material.Ladder; +import org.bukkit.material.Leaves; import org.bukkit.material.Lever; import org.bukkit.material.LongGrass; import org.bukkit.material.MaterialData; @@ -51,12 +52,14 @@ import org.bukkit.material.Tree; import org.bukkit.material.Tripwire; import org.bukkit.material.TripwireHook; import org.bukkit.material.Vine; +import org.bukkit.material.Wood; import org.bukkit.material.WoodenStep; import org.bukkit.material.Wool; import org.bukkit.potion.Potion; import org.bukkit.util.Java15Compat; import com.google.common.collect.Maps; + import org.bukkit.material.Banner; /** @@ -68,8 +71,8 @@ public enum Material { GRASS(2), DIRT(3), COBBLESTONE(4), - WOOD(5, Tree.class), - SAPLING(6, Tree.class), + WOOD(5, Wood.class), + SAPLING(6, Wood.class), BEDROCK(7), WATER(8, MaterialData.class), STATIONARY_WATER(9, MaterialData.class), @@ -81,7 +84,7 @@ public enum Material { IRON_ORE(15), COAL_ORE(16), LOG(17, Tree.class), - LEAVES(18, Tree.class), + LEAVES(18, Leaves.class), SPONGE(19), GLASS(20), LAPIS_ORE(21), @@ -188,7 +191,7 @@ public enum Material { DRAGON_EGG(122), REDSTONE_LAMP_OFF(123), REDSTONE_LAMP_ON(124), - WOOD_DOUBLE_STEP(125, WoodenStep.class), + WOOD_DOUBLE_STEP(125, Wood.class), WOOD_STEP(126, WoodenStep.class), COCOA(127, CocoaPlant.class), SANDSTONE_STAIRS(128, Stairs.class), @@ -224,8 +227,8 @@ public enum Material { DROPPER(158, Dispenser.class), STAINED_CLAY(159), STAINED_GLASS_PANE(160), - LEAVES_2(161), - LOG_2(162), + LEAVES_2(161, Leaves.class), + LOG_2(162, Tree.class), ACACIA_STAIRS(163, Stairs.class), DARK_OAK_STAIRS(164, Stairs.class), SLIME_BLOCK(165), diff --git a/src/main/java/org/bukkit/material/Leaves.java b/src/main/java/org/bukkit/material/Leaves.java index 9f40a23..9903229 100644 --- a/src/main/java/org/bukkit/material/Leaves.java +++ b/src/main/java/org/bukkit/material/Leaves.java @@ -4,16 +4,43 @@ 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 +52,42 @@ 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 +111,51 @@ public class Leaves extends MaterialData { } /** - * Gets the current species of this leave + * Checks if this leaf block is in the process of decaying + * + * @return true if the leaf block is in the process of decaying + */ + @SuppressWarnings("deprecation") + public boolean isDecaying() { + return (getData() & 0x8) != 0; + } + + /** + * Set whether this leaf block is in the process of decaying * - * @return TreeSpecies of this leave + * @param isDecaying whether the block is decaying or not */ - public TreeSpecies getSpecies() { - return TreeSpecies.getByData((byte) (getData() & 3)); + @SuppressWarnings("deprecation") + 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 } /** - * Sets the species of this leave + * 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 + */ + @SuppressWarnings("deprecation") + public boolean isDecayable() { + return (getData() & 0x4) == 0; + } + /** + * Set whether this leaf block will disappear when too far from a log * - * @param species New species of this leave + * @param isDecayable whether the block is permanent or can disappear */ - public void setSpecies(TreeSpecies species) { - setData(species.getData()); + @SuppressWarnings("deprecation") + 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 diff --git a/src/main/java/org/bukkit/material/Tree.java b/src/main/java/org/bukkit/material/Tree.java index d90126c..7ee9aa5 100644 --- a/src/main/java/org/bukkit/material/Tree.java +++ b/src/main/java/org/bukkit/material/Tree.java @@ -5,22 +5,43 @@ 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 +53,42 @@ 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); } /** @@ -57,24 +112,6 @@ public class Tree extends MaterialData { } /** - * 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: @@ -85,6 +122,7 @@ public class Tree extends MaterialData { *
  • BlockFace.SELF (directionless) * */ + @SuppressWarnings("deprecation") public BlockFace getDirection() { switch ((getData() >> 2) & 0x3) { case 0: // Up-down @@ -103,6 +141,7 @@ public class Tree extends MaterialData { * * @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 +152,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 diff --git a/src/main/java/org/bukkit/material/Wood.java b/src/main/java/org/bukkit/material/Wood.java new file mode 100644 index 0000000..bb8af15 --- /dev/null +++ b/src/main/java/org/bukkit/material/Wood.java @@ -0,0 +1,212 @@ +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 + */ + @SuppressWarnings("deprecation") + public TreeSpecies getSpecies() { + switch(this.getItemType()) + { + case WOOD: + case SAPLING: + 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) (0x4|(getData() & 0x1))); + 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 + */ + @SuppressWarnings("deprecation") + public void setSpecies(final TreeSpecies species) { + final Material type = this.getItemType(); + boolean firstType = false; + switch(type) + { + case WOOD: + case SAPLING: + 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 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(); + } +} diff --git a/src/main/java/org/bukkit/material/WoodenStep.java b/src/main/java/org/bukkit/material/WoodenStep.java index b07ee89..454bc16 100644 --- a/src/main/java/org/bukkit/material/WoodenStep.java +++ b/src/main/java/org/bukkit/material/WoodenStep.java @@ -5,11 +5,43 @@ 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 type + * the type of wooden step + * @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 +53,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 @@ -53,28 +74,11 @@ public class WoodenStep extends MaterialData { } /** - * 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); } @@ -85,6 +89,7 @@ public class WoodenStep extends MaterialData { * @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) { diff --git a/src/test/java/org/bukkit/materials/MaterialDataTest.java b/src/test/java/org/bukkit/materials/MaterialDataTest.java new file mode 100644 index 0000000..00e6f63 --- /dev/null +++ b/src/test/java/org/bukkit/materials/MaterialDataTest.java @@ -0,0 +1,175 @@ +package org.bukkit.materials; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +import org.bukkit.Material; +import org.bukkit.TreeSpecies; +import org.bukkit.block.BlockFace; +import org.bukkit.material.Leaves; +import org.bukkit.material.Tree; +import org.bukkit.material.Wood; +import org.bukkit.material.WoodenStep; +import org.junit.Test; + +public class MaterialDataTest { + @Test + public void testWood() + { + Wood wood = new Wood(); + assertThat("Constructed with default wood type",wood.getItemType(),equalTo(Material.WOOD)); + assertThat("Constructed with default tree species",wood.getSpecies(),equalTo(TreeSpecies.GENERIC)); + + TreeSpecies[] allSpecies = TreeSpecies.values(); + for(TreeSpecies species : allSpecies) + { + wood = new Wood(species); + assertThat("Constructed with default wood type",wood.getItemType(),equalTo(Material.WOOD)); + assertThat("Constructed with correct tree species",wood.getSpecies(),equalTo(species)); + } + + Material[] types = new Material[] {Material.WOOD, Material.SAPLING, Material.WOOD_DOUBLE_STEP}; + for(Material type : types) + { + Wood sapling = new Wood(type); + assertThat("Constructed with correct wood type",sapling.getItemType(),equalTo(type)); + assertThat("Constructed with default tree species",sapling.getSpecies(),equalTo(TreeSpecies.GENERIC)); + + for(TreeSpecies species : allSpecies) + { + sapling = new Wood(type,species); + assertThat("Constructed with correct wood type",sapling.getItemType(),equalTo(type)); + assertThat("Constructed with correct tree species",sapling.getSpecies(),equalTo(species)); + } + } + } + + @Test + public void testTree() + { + Tree tree = new Tree(); + assertThat("Constructed with default tree type",tree.getItemType(),equalTo(Material.LOG)); + assertThat("Constructed with default tree species",tree.getSpecies(),equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default direction",tree.getDirection(),equalTo(BlockFace.UP)); + + tree = new Tree(Material.LOG); + assertThat("Constructed with correct tree type",tree.getItemType(),equalTo(Material.LOG)); + assertThat("Constructed with default tree species",tree.getSpecies(),equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default direction",tree.getDirection(),equalTo(BlockFace.UP)); + + Material[] types = new Material[] {Material.LOG,Material.LOG_2}; + TreeSpecies[][] allSpecies = new TreeSpecies[][] { + {TreeSpecies.GENERIC, TreeSpecies.REDWOOD, TreeSpecies.BIRCH, TreeSpecies.JUNGLE}, + {TreeSpecies.ACACIA, TreeSpecies.DARK_OAK} + }; + BlockFace[] allDirections = new BlockFace[] {BlockFace.UP, BlockFace.WEST, BlockFace.NORTH, BlockFace.SELF}; + for(int t = 0; t < types.length; t++) + { + for(TreeSpecies species : allSpecies[t]) + { + tree = new Tree(types[t],species); + assertThat("Constructed with correct tree type",tree.getItemType(),equalTo(types[t])); + assertThat("Constructed with correct tree species",tree.getSpecies(),equalTo(species)); + assertThat("Constructed with default direction",tree.getDirection(),equalTo(BlockFace.UP)); + + // check item type is fixed automatically for invalid type-species combo + tree = new Tree(types[types.length-1-t],species); + assertThat("Constructed with fixed tree type",tree.getItemType(),equalTo(types[t])); + assertThat("Constructed with correct tree species",tree.getSpecies(),equalTo(species)); + assertThat("Constructed with default direction",tree.getDirection(),equalTo(BlockFace.UP)); + for(BlockFace dir : allDirections) + { + tree = new Tree(types[t],species,dir); + assertThat("Constructed with correct tree type",tree.getItemType(),equalTo(types[t])); + assertThat("Constructed with correct tree species",tree.getSpecies(),equalTo(species)); + assertThat("Constructed with correct direction",tree.getDirection(),equalTo(dir)); + } + } + } + } + + @Test + public void testLeaves() + { + Leaves leaves = new Leaves(); + assertThat("Constructed with default leaf type",leaves.getItemType(),equalTo(Material.LEAVES)); + assertThat("Constructed with default tree species",leaves.getSpecies(),equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default decayable",leaves.isDecayable(),equalTo(true)); + assertThat("Constructed with default decaying",leaves.isDecaying(),equalTo(false)); + + leaves = new Leaves(Material.LEAVES); + assertThat("Constructed with correct leaf type",leaves.getItemType(),equalTo(Material.LEAVES)); + assertThat("Constructed with default tree species",leaves.getSpecies(),equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default decayable",leaves.isDecayable(),equalTo(true)); + assertThat("Constructed with default decaying",leaves.isDecaying(),equalTo(false)); + + Material[] types = new Material[] {Material.LEAVES,Material.LEAVES_2}; + TreeSpecies[][] allSpecies = new TreeSpecies[][] { + {TreeSpecies.GENERIC, TreeSpecies.REDWOOD, TreeSpecies.BIRCH, TreeSpecies.JUNGLE}, + {TreeSpecies.ACACIA, TreeSpecies.DARK_OAK} + }; + boolean[] decayable = new boolean[] {true, false}; + boolean[] decaying = new boolean[] {true, false}; + for(int t = 0; t < types.length; t++) + { + for(TreeSpecies species : allSpecies[t]) + { + leaves = new Leaves(types[t],species); + assertThat("Constructed with correct leaf type",leaves.getItemType(),equalTo(types[t])); + assertThat("Constructed with correct tree species",leaves.getSpecies(),equalTo(species)); + assertThat("Constructed with default decayable",leaves.isDecayable(),equalTo(true)); + assertThat("Constructed with default decaying",leaves.isDecaying(),equalTo(false)); + + // check item type is fixed automatically for invalid type-species combo + leaves = new Leaves(types[types.length-1-t],species); + assertThat("Constructed with fixed leaf type",leaves.getItemType(),equalTo(types[t])); + assertThat("Constructed with correct tree species",leaves.getSpecies(),equalTo(species)); + assertThat("Constructed with default decayable",leaves.isDecayable(),equalTo(true)); + assertThat("Constructed with default decaying",leaves.isDecaying(),equalTo(false)); + for(boolean isDecayable : decayable) + { + leaves = new Leaves(types[t],species,isDecayable); + assertThat("Constructed with correct wood type",leaves.getItemType(),equalTo(types[t])); + assertThat("Constructed with correct tree species",leaves.getSpecies(),equalTo(species)); + assertThat("Constructed with correct decayable",leaves.isDecayable(),equalTo(isDecayable)); + assertThat("Constructed with default decaying",leaves.isDecaying(),equalTo(false)); + for(boolean isDecaying : decaying) + { + leaves = new Leaves(types[t],species,isDecayable); + leaves.setDecaying(isDecaying); + assertThat("Constructed with correct wood type",leaves.getItemType(),equalTo(types[t])); + assertThat("Constructed with correct tree species",leaves.getSpecies(),equalTo(species)); + assertThat("Constructed with correct decayable",leaves.isDecayable(),equalTo(isDecaying||isDecayable)); + assertThat("Constructed with correct decaying",leaves.isDecaying(),equalTo(isDecaying)); + } + } + } + } + } + + @Test + public void testWoodenStep() + { + WoodenStep woodenStep = new WoodenStep(); + assertThat("Constructed with default step type",woodenStep.getItemType(),equalTo(Material.WOOD_STEP)); + assertThat("Constructed with default tree species",woodenStep.getSpecies(),equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default inversion",woodenStep.isInverted(),equalTo(false)); + + TreeSpecies[] allSpecies = TreeSpecies.values(); + boolean[] inversion = new boolean[] {true, false}; + for(TreeSpecies species : allSpecies) + { + woodenStep = new WoodenStep(species); + assertThat("Constructed with default step type",woodenStep.getItemType(),equalTo(Material.WOOD_STEP)); + assertThat("Constructed with correct tree species",woodenStep.getSpecies(),equalTo(species)); + assertThat("Constructed with default inversion",woodenStep.isInverted(),equalTo(false)); + for(boolean isInverted : inversion) + { + woodenStep = new WoodenStep(species,isInverted); + assertThat("Constructed with default step type",woodenStep.getItemType(),equalTo(Material.WOOD_STEP)); + assertThat("Constructed with correct tree species",woodenStep.getSpecies(),equalTo(species)); + assertThat("Constructed with correct inversion",woodenStep.isInverted(),equalTo(isInverted)); + } + } + } +} -- 1.9.5.msysgit.1