mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Added support for new tree types to TreeGenerator and make adding more tree types later easier
This commit is contained in:
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user