Added support for new tree types to TreeGenerator and make adding more tree types later easier

This commit is contained in:
zml2008 2012-03-17 15:24:30 -07:00
parent 7f7178957a
commit b6d1146427
8 changed files with 253 additions and 177 deletions

12
pom.xml
View File

@ -1,6 +1,6 @@
<!--
Maven build file for WorldEdit
Copyright (c) 2011 sk89q <http://www.sk89q.com>
Copyright (c) 2011 sk89q <http://www.sk89q.com>
WorldEdit is available under the GNU General Public License v3
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@ -37,7 +37,7 @@
</repositories>
<dependencies>
<!-- Used for Permissions support (this version has both the legacy API
<!-- Used for Permissions support (this version has both the legacy API
and the new Permissions API to compile against -->
<dependency>
<groupId>com.sk89q</groupId>
@ -49,7 +49,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.1-R6</version>
<version>1.2.3-R0.3-SNAPSHOT</version>
</dependency>
<!-- Archive reading library for snapshots -->
@ -66,8 +66,8 @@
<version>1.7R2</version>
</dependency>
<!-- Time related functions, used for snapshots. This is NOT the original
jchronic as it has been modified to have some extra timezone related methods
<!-- Time related functions, used for snapshots. This is NOT the original
jchronic as it has been modified to have some extra timezone related methods
(which were hacked in) -->
<dependency>
<groupId>com.sk89q</groupId>
@ -143,7 +143,7 @@
</manifest>
<manifestEntries>
<Class-Path>truezip.jar WorldEdit/truezip.jar js.jar WorldEdit/js.jar</Class-Path>
<!-- This is a legacy manifest entry for older versions of
<!-- This is a legacy manifest entry for older versions of
WorldEdit (like really old) -->
<WorldEdit-Version>${project.version}</WorldEdit-Version>
</manifestEntries>

View File

@ -789,7 +789,7 @@ public class EditSession {
final PlayerDirection attachment = BlockType.getAttachment(type, data);
if (attachment == null) {
// Block is not attached to anything => we can place it
// Block is not attached to anything => we can place it
break;
}
@ -2787,8 +2787,8 @@ public class EditSession {
*
* @param region the region to hollow out.
* @param thickness the thickness of the shell to leave (manhattan distance)
* @param patternThe block pattern to use
*
* @param pattern The block pattern to use
*
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/

View File

@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
/**
* Represents a world.
@ -33,7 +34,7 @@ import com.sk89q.worldedit.regions.Region;
*/
public abstract class LocalWorld {
/**
* Named flags to use as parameters to {@link LocalWorld#killMobs(Vector, int, int)}
* Named flags to use as parameters to {@link LocalWorld#killMobs(Vector, double, int)}
*/
public class KillFlags {
public static final int PETS = 1 << 0;
@ -185,9 +186,13 @@ public abstract class LocalWorld {
* @param pt
* @return
* @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/
public abstract boolean generateTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException;
@Deprecated
public boolean generateTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/**
* Generate a big tree at a location.
@ -196,9 +201,13 @@ public abstract class LocalWorld {
* @param pt
* @return
* @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/
public abstract boolean generateBigTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException;
@Deprecated
public boolean generateBigTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/**
* Generate a birch tree at a location.
@ -207,9 +216,13 @@ public abstract class LocalWorld {
* @param pt
* @return
* @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/
public abstract boolean generateBirchTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException;
@Deprecated
public boolean generateBirchTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/**
* Generate a redwood tree at a location.
@ -218,9 +231,13 @@ public abstract class LocalWorld {
* @param pt
* @return
* @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/
public abstract boolean generateRedwoodTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException;
@Deprecated
public boolean generateRedwoodTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/**
* Generate a tall redwood tree at a location.
@ -229,9 +246,38 @@ public abstract class LocalWorld {
* @param pt
* @return
* @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/
public abstract boolean generateTallRedwoodTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException;
@Deprecated
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/**
* Generates a tree
* @param type The type of tree to generate
* @param editSession The EditSession to pass block changes through
* @param pt The point where the base of the tree should be located
* @return Whether the tree generation was successful
* @throws MaxChangedBlocksException if too many blocks were changed by the EditSession
*/
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
switch (type) {
case BIG_TREE:
return generateBigTree(editSession, pt);
case BIRCH:
return generateBirchTree(editSession, pt);
case REDWOOD:
return generateRedwoodTree(editSession, pt);
case TALL_REDWOOD:
return generateTallRedwoodTree(editSession, pt);
default:
case TREE:
return generateTree(editSession, pt);
}
}
/**
* Drop an item.
@ -276,8 +322,7 @@ public abstract class LocalWorld {
/**
* Kill mobs in an area, excluding pet wolves.
*
* @param origin
* @param radius
* @param origin -1 for the whole world
* @return
*/
@Deprecated
@ -288,9 +333,9 @@ public abstract class LocalWorld {
/**
* Kill mobs in an area.
*
* @param origin
* @param origin The center of the area to kill mobs in
* @param radius -1 for all mobs
* @param flags various flags that determine what to kill
* @param killPets whether to kill pets
* @return
*/
@Deprecated
@ -303,7 +348,7 @@ public abstract class LocalWorld {
*
* @param origin
* @param radius
* @param killflags
* @param flags
* @return
*/
public int killMobs(Vector origin, double radius, int flags) {

View File

@ -19,9 +19,12 @@
package com.sk89q.worldedit.bukkit;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.TreeGenerator;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace;
@ -395,9 +398,9 @@ public class BukkitWorld extends LocalWorld {
* @return
*/
@Override
@Deprecated
public boolean generateTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.TREE,
new EditSessionBlockChangeDelegate(editSession));
return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
}
/**
@ -407,9 +410,9 @@ public class BukkitWorld extends LocalWorld {
* @return
*/
@Override
@Deprecated
public boolean generateBigTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.BIG_TREE,
new EditSessionBlockChangeDelegate(editSession));
return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
}
/**
@ -419,9 +422,9 @@ public class BukkitWorld extends LocalWorld {
* @return
*/
@Override
@Deprecated
public boolean generateBirchTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.BIRCH,
new EditSessionBlockChangeDelegate(editSession));
return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
}
/**
@ -431,9 +434,9 @@ public class BukkitWorld extends LocalWorld {
* @return
*/
@Override
@Deprecated
public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.REDWOOD,
new EditSessionBlockChangeDelegate(editSession));
return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
}
/**
@ -443,8 +446,53 @@ public class BukkitWorld extends LocalWorld {
* @return
*/
@Override
@Deprecated
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.TALL_REDWOOD,
return generateTree(TreeGenerator.TreeType.TALL_REDWOOD, editSession, pt);
}
/**
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
*/
private static final EnumMap<TreeGenerator.TreeType, TreeType> treeTypeMapping =
new EnumMap<TreeGenerator.TreeType, TreeType>(TreeGenerator.TreeType.class);
static {
// Mappings for new TreeType values not yet in Bukkit
treeTypeMapping.put(TreeGenerator.TreeType.SWAMP, TreeType.TREE);
treeTypeMapping.put(TreeGenerator.TreeType.JUNGLE_BUSH, TreeType.TREE);
try {
treeTypeMapping.put(TreeGenerator.TreeType.SHORT_JUNGLE, TreeType.valueOf("SMALL_JUNGLE"));
} catch (IllegalArgumentException e) {
treeTypeMapping.put(TreeGenerator.TreeType.SHORT_JUNGLE, TreeType.TREE);
}
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
try {
TreeType bukkitType = TreeType.valueOf(type.name());
treeTypeMapping.put(type, bukkitType);
} catch (IllegalArgumentException e) {
// Unhandled TreeType
}
}
// Other mappings for WE-specific values
treeTypeMapping.put(TreeGenerator.TreeType.RANDOM, TreeType.BROWN_MUSHROOM);
treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_REDWOOD, TreeType.REDWOOD);
treeTypeMapping.put(TreeGenerator.TreeType.PINE, TreeType.REDWOOD);
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
if (treeTypeMapping.get(type) == null) {
WorldEdit.logger.severe("No TreeType mapping for TreeGenerator.TreeType." + type);
}
}
}
public static TreeType toBukkitTreeType(TreeGenerator.TreeType type) {
return treeTypeMapping.get(type);
}
@Override
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) {
TreeType bukkitType = toBukkitTreeType(type);
return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
new EditSessionBlockChangeDelegate(editSession));
}

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BlockID;
import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
@ -53,6 +54,14 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
}
}
public boolean setTypeId(int x, int y, int z, int typeId) {
return setRawTypeId(x, y, z, typeId);
}
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
return setRawTypeIdAndData(x, y, z, typeId, data);
}
public int getTypeId(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z));
}
@ -60,4 +69,8 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
public int getHeight() {
return editSession.getWorld().getMaxY() + 1;
}
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
}
}

View File

@ -23,11 +23,13 @@ import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EntityType;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import org.spout.api.geo.World;
import org.spout.api.material.MaterialData;
@ -44,7 +46,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Get the world handle.
*
*
* @return
*/
public World getWorld() {
@ -53,7 +55,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Get the name of the world
*
*
* @return
*/
@Override
@ -63,7 +65,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Set block type.
*
*
* @param pt
* @param type
* @return
@ -75,7 +77,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Set block type.
*
*
* @param pt
* @param type
* @return
@ -90,7 +92,7 @@ public class SpoutWorld extends LocalWorld {
* @param pt
* @param type
* @param data
* @return
* @return
*/
@Override
public boolean setTypeIdAndData(Vector pt, int type, int data) {
@ -103,7 +105,7 @@ public class SpoutWorld extends LocalWorld {
* @param pt
* @param type
* @param data
* @return
* @return
*/
@Override
public boolean setTypeIdAndDataFast(Vector pt, int type, int data) {
@ -112,7 +114,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Get block type.
*
*
* @param pt
* @return
*/
@ -123,7 +125,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Set block data.
*
*
* @param pt
* @param data
*/
@ -134,7 +136,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Set block data.
*
*
* @param pt
* @param data
*/
@ -145,7 +147,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Get block data.
*
*
* @param pt
* @return
*/
@ -156,7 +158,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Get block light level.
*
*
* @param pt
* @return
*/
@ -167,7 +169,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Regenerate an area.
*
*
* @param region
* @param editSession
* @return
@ -196,7 +198,7 @@ public class SpoutWorld extends LocalWorld {
t.printStackTrace();
}
// Then restore
// Then restore
for (int x = 0; x < 16; ++x) {
for (int y = 0; y < (getMaxY() + 1); ++y) {
for (int z = 0; z < 16; ++z) {
@ -221,7 +223,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Attempts to accurately copy a BaseBlock's extra data to the world.
*
*
* @param pt
* @param block
* @return
@ -282,7 +284,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Attempts to read a BaseBlock's extra data from the world.
*
*
* @param pt
* @param block
* @return
@ -344,7 +346,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Clear a chest's contents.
*
*
* @param pt
*/
@Override
@ -365,69 +367,10 @@ public class SpoutWorld extends LocalWorld {
return false;
}
/**
* Generate a tree at a location.
*
* @param pt
* @return
*/
@Override
public boolean generateTree(EditSession editSession, Vector pt) {
/*return world.generateTree(SpoutUtil.toLocation(world, pt), TreeType.TREE,
new EditSessionBlockChangeDelegate(editSession));*/
return false;
}
/**
* Generate a big tree at a location.
*
* @param pt
* @return
*/
@Override
public boolean generateBigTree(EditSession editSession, Vector pt) {
/*return world.generateTree(SpoutUtil.toLocation(world, pt), TreeType.BIG_TREE,
new EditSessionBlockChangeDelegate(editSession));*/
return false;
}
/**
* Generate a birch tree at a location.
*
* @param pt
* @return
*/
@Override
public boolean generateBirchTree(EditSession editSession, Vector pt) {
/*return world.generateTree(SpoutUtil.toLocation(world, pt), TreeType.BIRCH,
new EditSessionBlockChangeDelegate(editSession));*/
return false;
}
/**
* Generate a redwood tree at a location.
*
* @param pt
* @return
*/
@Override
public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
/*return world.generateTree(SpoutUtil.toLocation(world, pt), TreeType.REDWOOD,
new EditSessionBlockChangeDelegate(editSession));*/
return false;
}
/**
* Generate a redwood tree at a location.
*
* @param pt
* @return
*/
@Override
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) {
/*return world.generateTree(SpoutUtil.toLocation(world, pt), TreeType.TALL_REDWOOD,
new EditSessionBlockChangeDelegate(editSession));*/
return false;
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
throw new UnsupportedOperationException("Not supported yet.");
}
/**
@ -463,7 +406,7 @@ public class SpoutWorld extends LocalWorld {
Point bukkitOrigin = SpoutUtil.toPoint(world, origin);
for (LivingEntity ent : world.getLivingEntities()) {
if (ent instanceof HumanEntity) {
continue;
@ -510,7 +453,7 @@ public class SpoutWorld extends LocalWorld {
&& origin.distanceSq(SpoutUtil.toVector(ent.getTransform().getPosition())) > radiusSq) {
continue;
}
if (type == EntityType.ARROWS) {
if (ent instanceof Arrow) {
ent.remove();
@ -554,7 +497,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Set a sign's text.
*
*
* @param pt
* @param text
* @return
@ -575,7 +518,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Get a sign's text.
*
*
* @param pt
* @return
*/
@ -599,7 +542,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Get a container block's contents.
*
*
* @param pt
* @return
*/
@ -638,7 +581,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Set a container block's contents.
*
*
* @param pt
* @param contents
* @return
@ -682,7 +625,7 @@ public class SpoutWorld extends LocalWorld {
/**
* Returns whether a block has a valid ID.
*
*
* @param type
* @return
*/

View File

@ -37,14 +37,40 @@ import com.sk89q.worldedit.blocks.BlockID;
*/
public class TreeGenerator {
public enum TreeType {
TREE("Regular tree", new String[] { "tree", "regular" }),
BIG_TREE("Big tree", new String[] { "big", "bigtree" }),
REDWOOD("Redwood", new String[] { "redwood", "sequoia", "sequoioideae" }),
TALL_REDWOOD("Tall redwood", new String[] { "tallredwood", "tallsequoia", "tallsequoioideae" }),
BIRCH("Birch", new String[] { "birch", "white", "whitebark" }),
PINE("Pine", new String[] { "pine" }),
RANDOM_REDWOOD("Random redwood", new String[] { "randredwood", "randomredwood", "anyredwood" }),
RANDOM("Random", new String[] { "rand", "random" });
TREE("Regular tree", "tree", "regular"),
BIG_TREE("Big tree", "big", "bigtree"),
REDWOOD("Redwood", "redwood", "sequoia", "sequoioideae"),
TALL_REDWOOD("Tall redwood", "tallredwood", "tallsequoia", "tallsequoioideae"),
BIRCH("Birch", "birch", "white", "whitebark"),
PINE("Pine", "pine") {
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
makePineTree(editSession, pos);
return true;
}
},
RANDOM_REDWOOD("Random redwood", "randredwood", "randomredwood", "anyredwood" ) {
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
TreeType[] choices = new TreeType[] {
TreeType.REDWOOD, TreeType.TALL_REDWOOD
};
return choices[rand.nextInt(choices.length)].generate(editSession, pos);
}
},
JUNGLE("Jungle", "jungle"),
SHORT_JUNGLE("Short jungle", "shortjungle", "smalljungle"),
JUNGLE_BUSH("Jungle bush", "junglebush", "jungleshrub"),
RED_MUSHROOM("Red Mushroom", "redmushroom", "redgiantmushroom"),
BROWN_MUSHROOM("Brown Mushroom", "brownmushroom", "browngiantmushroom"),
SWAMP("Swamp", "swamp", "swamptree"),
RANDOM("Random", "rand", "random" ) {
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
TreeType[] choices = new TreeType[] {
TreeType.TREE, TreeType.BIG_TREE, TreeType.BIRCH,
TreeType.REDWOOD, TreeType.TALL_REDWOOD, TreeType.PINE
};
return choices[rand.nextInt(choices.length)].generate(editSession, pos);
}
};
/**
* Stores a map of the names for fast access.
@ -62,16 +88,15 @@ public class TreeGenerator {
}
}
TreeType(String name, String lookupKey) {
this.name = name;
this.lookupKeys = new String[] { lookupKey };
}
TreeType(String name, String[] lookupKeys) {
TreeType(String name, String... lookupKeys) {
this.name = name;
this.lookupKeys = lookupKeys;
}
public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
return editSession.getWorld().generateTree(this, editSession, pos);
}
/**
* Get user-friendly tree type name.
*
@ -98,16 +123,17 @@ public class TreeGenerator {
/**
* Construct the tree generator with a tree type.
*
*
* @param type
*/
@Deprecated
public TreeGenerator(TreeType type) {
this.type = type;
}
/**
* Generate a tree.
*
*
* @param editSession
* @param pos
* @return
@ -115,62 +141,28 @@ public class TreeGenerator {
*/
public boolean generate(EditSession editSession, Vector pos)
throws MaxChangedBlocksException {
return generate(type, editSession, pos);
return type.generate(editSession, pos);
}
/**
* Generate a tree.
*
* @param world
*
* @param type
* @param editSession
* @param pos
* @return
* @throws MaxChangedBlocksException
* @deprecated use {@link TreeType#generate(com.sk89q.worldedit.EditSession, com.sk89q.worldedit.Vector)} instead
*/
@Deprecated
private boolean generate(TreeType type, EditSession editSession, Vector pos)
throws MaxChangedBlocksException {
LocalWorld world = editSession.getWorld();
TreeType[] choices;
TreeType realType;
switch (type) {
case TREE:
return world.generateTree(editSession, pos);
case BIG_TREE:
return world.generateBigTree(editSession, pos);
case BIRCH:
return world.generateBirchTree(editSession, pos);
case REDWOOD:
return world.generateRedwoodTree(editSession, pos);
case TALL_REDWOOD:
return world.generateTallRedwoodTree(editSession, pos);
case PINE:
makePineTree(editSession, pos);
return true;
case RANDOM_REDWOOD:
choices =
new TreeType[] {
TreeType.REDWOOD, TreeType.TALL_REDWOOD
};
realType = choices[rand.nextInt(choices.length)];
return generate(realType, editSession, pos);
case RANDOM:
choices =
new TreeType[] {
TreeType.TREE, TreeType.BIG_TREE, TreeType.BIRCH,
TreeType.REDWOOD, TreeType.TALL_REDWOOD, TreeType.PINE
};
realType = choices[rand.nextInt(choices.length)];
return generate(realType, editSession, pos);
}
return false;
return type.generate(editSession, pos);
}
/**
* Makes a terrible looking pine tree.
*
*
* @param basePos
*/
private static void makePineTree(EditSession editSession, Vector basePos)
@ -230,7 +222,7 @@ public class TreeGenerator {
/**
* Looks up a tree type. May return null if a tree type by that
* name is not found.
*
*
* @param type
* @return
*/

View File

@ -0,0 +1,35 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.util.TreeGenerator;
import org.junit.Assert;
import org.junit.Test;
/**
* @author zml2008
*/
public class BukkitWorldTest {
@Test
public void testTreeTypeMapping() {
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
Assert.assertFalse("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type) == null);
}
}
}