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 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 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"> <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> </repositories>
<dependencies> <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 --> and the new Permissions API to compile against -->
<dependency> <dependency>
<groupId>com.sk89q</groupId> <groupId>com.sk89q</groupId>
@ -49,7 +49,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.1-R6</version> <version>1.2.3-R0.3-SNAPSHOT</version>
</dependency> </dependency>
<!-- Archive reading library for snapshots --> <!-- Archive reading library for snapshots -->
@ -66,8 +66,8 @@
<version>1.7R2</version> <version>1.7R2</version>
</dependency> </dependency>
<!-- Time related functions, used for snapshots. This is NOT the original <!-- Time related functions, used for snapshots. This is NOT the original
jchronic as it has been modified to have some extra timezone related methods jchronic as it has been modified to have some extra timezone related methods
(which were hacked in) --> (which were hacked in) -->
<dependency> <dependency>
<groupId>com.sk89q</groupId> <groupId>com.sk89q</groupId>
@ -143,7 +143,7 @@
</manifest> </manifest>
<manifestEntries> <manifestEntries>
<Class-Path>truezip.jar WorldEdit/truezip.jar js.jar WorldEdit/js.jar</Class-Path> <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 (like really old) -->
<WorldEdit-Version>${project.version}</WorldEdit-Version> <WorldEdit-Version>${project.version}</WorldEdit-Version>
</manifestEntries> </manifestEntries>

View File

@ -789,7 +789,7 @@ public class EditSession {
final PlayerDirection attachment = BlockType.getAttachment(type, data); final PlayerDirection attachment = BlockType.getAttachment(type, data);
if (attachment == null) { if (attachment == null) {
// Block is not attached to anything => we can place it // Block is not attached to anything => we can place it
break; break;
} }
@ -2787,8 +2787,8 @@ public class EditSession {
* *
* @param region the region to hollow out. * @param region the region to hollow out.
* @param thickness the thickness of the shell to leave (manhattan distance) * @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 * @return number of blocks affected
* @throws MaxChangedBlocksException * @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.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
/** /**
* Represents a world. * Represents a world.
@ -33,7 +34,7 @@ import com.sk89q.worldedit.regions.Region;
*/ */
public abstract class LocalWorld { 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 class KillFlags {
public static final int PETS = 1 << 0; public static final int PETS = 1 << 0;
@ -185,9 +186,13 @@ public abstract class LocalWorld {
* @param pt * @param pt
* @return * @return
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/ */
public abstract boolean generateTree(EditSession editSession, Vector pt) @Deprecated
throws MaxChangedBlocksException; public boolean generateTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/** /**
* Generate a big tree at a location. * Generate a big tree at a location.
@ -196,9 +201,13 @@ public abstract class LocalWorld {
* @param pt * @param pt
* @return * @return
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/ */
public abstract boolean generateBigTree(EditSession editSession, Vector pt) @Deprecated
throws MaxChangedBlocksException; public boolean generateBigTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/** /**
* Generate a birch tree at a location. * Generate a birch tree at a location.
@ -207,9 +216,13 @@ public abstract class LocalWorld {
* @param pt * @param pt
* @return * @return
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/ */
public abstract boolean generateBirchTree(EditSession editSession, Vector pt) @Deprecated
throws MaxChangedBlocksException; public boolean generateBirchTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/** /**
* Generate a redwood tree at a location. * Generate a redwood tree at a location.
@ -218,9 +231,13 @@ public abstract class LocalWorld {
* @param pt * @param pt
* @return * @return
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/ */
public abstract boolean generateRedwoodTree(EditSession editSession, Vector pt) @Deprecated
throws MaxChangedBlocksException; public boolean generateRedwoodTree(EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
return false;
}
/** /**
* Generate a tall redwood tree at a location. * Generate a tall redwood tree at a location.
@ -229,9 +246,38 @@ public abstract class LocalWorld {
* @param pt * @param pt
* @return * @return
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
* @deprecated use {@link #generateTree(com.sk89q.worldedit.util.TreeGenerator.TreeType, EditSession, Vector)} instead
*/ */
public abstract boolean generateTallRedwoodTree(EditSession editSession, Vector pt) @Deprecated
throws MaxChangedBlocksException; 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. * Drop an item.
@ -276,8 +322,7 @@ public abstract class LocalWorld {
/** /**
* Kill mobs in an area, excluding pet wolves. * Kill mobs in an area, excluding pet wolves.
* *
* @param origin * @param origin -1 for the whole world
* @param radius
* @return * @return
*/ */
@Deprecated @Deprecated
@ -288,9 +333,9 @@ public abstract class LocalWorld {
/** /**
* Kill mobs in an area. * 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 radius -1 for all mobs
* @param flags various flags that determine what to kill * @param killPets whether to kill pets
* @return * @return
*/ */
@Deprecated @Deprecated
@ -303,7 +348,7 @@ public abstract class LocalWorld {
* *
* @param origin * @param origin
* @param radius * @param radius
* @param killflags * @param flags
* @return * @return
*/ */
public int killMobs(Vector origin, double radius, int flags) { public int killMobs(Vector origin, double radius, int flags) {

View File

@ -19,9 +19,12 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.TreeGenerator;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace; import org.bukkit.block.Furnace;
@ -395,9 +398,9 @@ public class BukkitWorld extends LocalWorld {
* @return * @return
*/ */
@Override @Override
@Deprecated
public boolean generateTree(EditSession editSession, Vector pt) { public boolean generateTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.TREE, return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
new EditSessionBlockChangeDelegate(editSession));
} }
/** /**
@ -407,9 +410,9 @@ public class BukkitWorld extends LocalWorld {
* @return * @return
*/ */
@Override @Override
@Deprecated
public boolean generateBigTree(EditSession editSession, Vector pt) { public boolean generateBigTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.BIG_TREE, return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
new EditSessionBlockChangeDelegate(editSession));
} }
/** /**
@ -419,9 +422,9 @@ public class BukkitWorld extends LocalWorld {
* @return * @return
*/ */
@Override @Override
@Deprecated
public boolean generateBirchTree(EditSession editSession, Vector pt) { public boolean generateBirchTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.BIRCH, return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
new EditSessionBlockChangeDelegate(editSession));
} }
/** /**
@ -431,9 +434,9 @@ public class BukkitWorld extends LocalWorld {
* @return * @return
*/ */
@Override @Override
@Deprecated
public boolean generateRedwoodTree(EditSession editSession, Vector pt) { public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.REDWOOD, return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
new EditSessionBlockChangeDelegate(editSession));
} }
/** /**
@ -443,8 +446,53 @@ public class BukkitWorld extends LocalWorld {
* @return * @return
*/ */
@Override @Override
@Deprecated
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) { 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)); new EditSessionBlockChangeDelegate(editSession));
} }

View File

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

View File

@ -37,14 +37,40 @@ import com.sk89q.worldedit.blocks.BlockID;
*/ */
public class TreeGenerator { public class TreeGenerator {
public enum TreeType { public enum TreeType {
TREE("Regular tree", new String[] { "tree", "regular" }), TREE("Regular tree", "tree", "regular"),
BIG_TREE("Big tree", new String[] { "big", "bigtree" }), BIG_TREE("Big tree", "big", "bigtree"),
REDWOOD("Redwood", new String[] { "redwood", "sequoia", "sequoioideae" }), REDWOOD("Redwood", "redwood", "sequoia", "sequoioideae"),
TALL_REDWOOD("Tall redwood", new String[] { "tallredwood", "tallsequoia", "tallsequoioideae" }), TALL_REDWOOD("Tall redwood", "tallredwood", "tallsequoia", "tallsequoioideae"),
BIRCH("Birch", new String[] { "birch", "white", "whitebark" }), BIRCH("Birch", "birch", "white", "whitebark"),
PINE("Pine", new String[] { "pine" }), PINE("Pine", "pine") {
RANDOM_REDWOOD("Random redwood", new String[] { "randredwood", "randomredwood", "anyredwood" }), public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException {
RANDOM("Random", new String[] { "rand", "random" }); 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. * Stores a map of the names for fast access.
@ -62,16 +88,15 @@ public class TreeGenerator {
} }
} }
TreeType(String name, String lookupKey) { TreeType(String name, String... lookupKeys) {
this.name = name;
this.lookupKeys = new String[] { lookupKey };
}
TreeType(String name, String[] lookupKeys) {
this.name = name; this.name = name;
this.lookupKeys = lookupKeys; 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. * Get user-friendly tree type name.
* *
@ -98,16 +123,17 @@ public class TreeGenerator {
/** /**
* Construct the tree generator with a tree type. * Construct the tree generator with a tree type.
* *
* @param type * @param type
*/ */
@Deprecated
public TreeGenerator(TreeType type) { public TreeGenerator(TreeType type) {
this.type = type; this.type = type;
} }
/** /**
* Generate a tree. * Generate a tree.
* *
* @param editSession * @param editSession
* @param pos * @param pos
* @return * @return
@ -115,62 +141,28 @@ public class TreeGenerator {
*/ */
public boolean generate(EditSession editSession, Vector pos) public boolean generate(EditSession editSession, Vector pos)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
return generate(type, editSession, pos); return type.generate(editSession, pos);
} }
/** /**
* Generate a tree. * Generate a tree.
* *
* @param world * @param type
* @param editSession * @param editSession
* @param pos * @param pos
* @return * @return
* @throws MaxChangedBlocksException * @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) private boolean generate(TreeType type, EditSession editSession, Vector pos)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
LocalWorld world = editSession.getWorld(); return type.generate(editSession, pos);
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;
} }
/** /**
* Makes a terrible looking pine tree. * Makes a terrible looking pine tree.
* *
* @param basePos * @param basePos
*/ */
private static void makePineTree(EditSession editSession, Vector 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 * Looks up a tree type. May return null if a tree type by that
* name is not found. * name is not found.
* *
* @param type * @param type
* @return * @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);
}
}
}