From d4b57972ef7203ed898d1b0b947edc6149ed8602 Mon Sep 17 00:00:00 2001 From: ryanbennitt Date: Sun, 7 Feb 2016 22:41:50 +0000 Subject: [PATCH] Merged sapling onto tree species fix --- src/main/java/org/bukkit/Material.java | 3 +- src/main/java/org/bukkit/material/Leaves.java | 69 +++--- src/main/java/org/bukkit/material/Sapling.java | 121 +++++++++++ src/main/java/org/bukkit/material/Tree.java | 52 ++--- src/main/java/org/bukkit/material/Wood.java | 176 +++++++-------- src/main/java/org/bukkit/material/WoodenStep.java | 32 ++- .../org/bukkit/materials/MaterialDataTest.java | 238 +++++++++++---------- 7 files changed, 392 insertions(+), 299 deletions(-) create mode 100644 src/main/java/org/bukkit/material/Sapling.java diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 1d399a2..d83c038 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -40,6 +40,7 @@ import org.bukkit.material.Rails; import org.bukkit.material.RedstoneTorch; import org.bukkit.material.RedstoneWire; import org.bukkit.material.Sandstone; +import org.bukkit.material.Sapling; import org.bukkit.material.Sign; import org.bukkit.material.Skull; import org.bukkit.material.SmoothBrick; @@ -72,7 +73,7 @@ public enum Material { DIRT(3), COBBLESTONE(4), WOOD(5, Wood.class), - SAPLING(6, Wood.class), + SAPLING(6, Sapling.class), BEDROCK(7), WATER(8, MaterialData.class), STATIONARY_WATER(9, MaterialData.class), diff --git a/src/main/java/org/bukkit/material/Leaves.java b/src/main/java/org/bukkit/material/Leaves.java index 9903229..1be1409 100644 --- a/src/main/java/org/bukkit/material/Leaves.java +++ b/src/main/java/org/bukkit/material/Leaves.java @@ -4,8 +4,9 @@ import org.bukkit.Material; import org.bukkit.TreeSpecies; /** - * Represents the different types of leaf block that may be permanent or can decay when too far from a log. - * + * 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 */ @@ -22,22 +23,19 @@ public class Leaves extends Wood { /** * Constructs a leaf block of the given tree species. - * - * @param species - * the species of the wood block + * + * @param species the species of the wood block */ public Leaves(TreeSpecies 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 + * 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); @@ -54,9 +52,8 @@ public class Leaves extends Wood { /** * Constructs a leaf block of the given type. - * - * @param type - * the type of leaf block + * + * @param type the type of leaf block */ public Leaves(final Material type) { this(type, DEFAULT_SPECIES, DEFAULT_DECAYABLE); @@ -64,11 +61,9 @@ public class Leaves extends Wood { /** * 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 + * + * @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); @@ -77,13 +72,10 @@ public class Leaves extends Wood { /** * 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 + * + * @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); @@ -115,7 +107,6 @@ public class Leaves extends Wood { * * @return true if the leaf block is in the process of decaying */ - @SuppressWarnings("deprecation") public boolean isDecaying() { return (getData() & 0x8) != 0; } @@ -125,32 +116,32 @@ public class Leaves extends Wood { * * @param isDecaying whether the block is decaying or not */ - @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 + 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 + * 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 + * @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 isDecayable whether the block is permanent or can disappear */ - @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))); + setData((byte) ((getData() & 0x3) | (isDecayable + ? (getData() & 0x8) // Only persist the decaying flag if this is a decayable block + : 0x4))); } @Override diff --git a/src/main/java/org/bukkit/material/Sapling.java b/src/main/java/org/bukkit/material/Sapling.java new file mode 100644 index 0000000..52dbaee --- /dev/null +++ b/src/main/java/org/bukkit/material/Sapling.java @@ -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(); + } +} diff --git a/src/main/java/org/bukkit/material/Tree.java b/src/main/java/org/bukkit/material/Tree.java index 7ee9aa5..8bc79af 100644 --- a/src/main/java/org/bukkit/material/Tree.java +++ b/src/main/java/org/bukkit/material/Tree.java @@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace; /** * Represents the different types of Tree block that face a direction. - * + * * @see Material.LOG * @see Material.LOG_2 */ @@ -23,9 +23,8 @@ public class Tree extends Wood { /** * Constructs a tree block of the given tree species. - * - * @param species - * the species of the tree block + * + * @param species the species of the tree block */ public Tree(TreeSpecies species) { this(DEFAULT_TYPE, species, DEFAULT_DIRECTION); @@ -34,11 +33,9 @@ public class Tree extends Wood { /** * 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 + * + * @param species the species of the tree block + * @param dir the direction the tree block is facing */ public Tree(TreeSpecies species, BlockFace dir) { this(DEFAULT_TYPE, species, dir); @@ -55,9 +52,8 @@ public class Tree extends Wood { /** * Constructs a tree block of the given type. - * - * @param type - * the type of tree block + * + * @param type the type of tree block */ public Tree(final Material type) { this(type, DEFAULT_SPECIES, DEFAULT_DIRECTION); @@ -65,11 +61,9 @@ public class Tree extends Wood { /** * 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 + * + * @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); @@ -78,13 +72,10 @@ public class Tree extends Wood { /** * 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 + * + * @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); @@ -115,12 +106,12 @@ public class Tree extends Wood { * Get direction of the log * * @return one of: - * + * */ @SuppressWarnings("deprecation") public BlockFace getDirection() { @@ -136,6 +127,7 @@ public class Tree extends Wood { return BlockFace.SELF; } } + /** * Set direction of the log * diff --git a/src/main/java/org/bukkit/material/Wood.java b/src/main/java/org/bukkit/material/Wood.java index bb8af15..1c40162 100644 --- a/src/main/java/org/bukkit/material/Wood.java +++ b/src/main/java/org/bukkit/material/Wood.java @@ -5,7 +5,7 @@ import org.bukkit.TreeSpecies; /** * Represents wood blocks of different species. - * + * * @see Material.WOOD * @see Material.SAPLING * @see Material.WOOD_DOUBLE_STEP @@ -24,8 +24,7 @@ public class Wood extends MaterialData { /** * Constructs a wood block of the given tree species. * - * @param species - * the species of the wood block + * @param species the species of the wood block */ public Wood(TreeSpecies species) { this(DEFAULT_TYPE, species); @@ -42,9 +41,8 @@ public class Wood extends MaterialData { /** * Constructs a wood block of the given type. - * - * @param type - * the type of wood block + * + * @param type the type of wood block */ public Wood(final Material type) { this(type, DEFAULT_SPECIES); @@ -52,15 +50,13 @@ public class Wood extends MaterialData { /** * 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 + * + * @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)); + super(getSpeciesType(type, species)); setSpecies(species); } @@ -89,62 +85,56 @@ public class Wood extends MaterialData { * * @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"); + 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 + * @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; + 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; } @@ -154,49 +144,43 @@ public class Wood extends MaterialData { * * @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; + 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"); + 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 ACACIA: - case DARK_OAK: - if(firstType) - { - throw new IllegalArgumentException("Invalid tree species for block type 2, use block type instead"); - } + case SAPLING: + case WOOD_STEP: + setData((byte) ((getData() & 0x8) | species.getData())); 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"); + default: + throw new IllegalArgumentException("Invalid block type for tree species"); } } diff --git a/src/main/java/org/bukkit/material/WoodenStep.java b/src/main/java/org/bukkit/material/WoodenStep.java index 454bc16..293c95b 100644 --- a/src/main/java/org/bukkit/material/WoodenStep.java +++ b/src/main/java/org/bukkit/material/WoodenStep.java @@ -5,7 +5,7 @@ import org.bukkit.TreeSpecies; /** * Represents the different types of wooden steps. - * + * * @see Material.WOOD_STEP */ public class WoodenStep extends Wood { @@ -16,28 +16,24 @@ public class WoodenStep extends Wood { * Constructs a wooden step. */ public WoodenStep() { - this(DEFAULT_SPECIES,DEFAULT_INVERTED); + this(DEFAULT_SPECIES, DEFAULT_INVERTED); } /** * Constructs a wooden step of the given tree species. - * - * @param species - * the species of the wooden step + * + * @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 + * 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); @@ -82,12 +78,12 @@ public class WoodenStep extends Wood { 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) { @@ -97,7 +93,7 @@ public class WoodenStep extends Wood { } setData((byte) dat); } - + @Override public WoodenStep clone() { return (WoodenStep) super.clone(); @@ -105,6 +101,6 @@ public class WoodenStep extends Wood { @Override public String toString() { - return super.toString() + " " + getSpecies() + (isInverted()?" inverted":""); + return super.toString() + " " + getSpecies() + (isInverted() ? " inverted" : ""); } } diff --git a/src/test/java/org/bukkit/materials/MaterialDataTest.java b/src/test/java/org/bukkit/materials/MaterialDataTest.java index 399a909..41dff99 100644 --- a/src/test/java/org/bukkit/materials/MaterialDataTest.java +++ b/src/test/java/org/bukkit/materials/MaterialDataTest.java @@ -8,6 +8,7 @@ import org.bukkit.TreeSpecies; import org.bukkit.block.BlockFace; import org.bukkit.material.Door; import org.bukkit.material.Leaves; +import org.bukkit.material.Sapling; import org.bukkit.material.Tree; import org.bukkit.material.Wood; import org.bukkit.material.WoodenStep; @@ -65,161 +66,168 @@ public class MaterialDataTest { } @Test - public void testWood() - { + 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)); - + 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) - { + 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)); + 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)); + + Material[] types = new Material[]{Material.WOOD, Material.WOOD_DOUBLE_STEP}; + for (Material type : types) { + wood = new Wood(type); + assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); + assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); + + for (TreeSpecies species : allSpecies) { + wood = new Wood(type, species); + assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); + assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); } } } - + @Test - public void testTree() - { + 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)); + 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)); + 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[][] { + 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)); + 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)); + 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() - { + 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)); - + 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)); + 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[][] { + 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)); + 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 = 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)); + 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() - { + 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)); - + 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) - { + 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)); + 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)); + } + } + } + + @Test + public void testSapling() { + Sapling sapling = new Sapling(); + assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.SAPLING)); + assertThat("Constructed with default tree species", sapling.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + + TreeSpecies[] allSpecies = TreeSpecies.values(); + boolean[] growable = new boolean[]{true, false}; + for (TreeSpecies species : allSpecies) { + sapling = new Sapling(species); + assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.SAPLING)); + assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); + assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + for (boolean isInstantGrowable : growable) { + sapling = new Sapling(species, isInstantGrowable); + assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.SAPLING)); + assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); + assertThat("Constructed with correct growable", sapling.isInstantGrowable(), equalTo(isInstantGrowable)); } } } -- 2.7.0.windows.1