Remove string switches for BlockType

This commit is contained in:
Jesse Boyd
2019-04-06 03:34:11 +11:00
parent d49c5ebe74
commit 0afae082c2
12 changed files with 293 additions and 244 deletions

View File

@ -24,6 +24,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -52,22 +53,26 @@ public class ForestGenerator implements RegionFunction {
public boolean apply(BlockVector3 position) throws WorldEditException {
BlockState block = editSession.getBlock(position);
BlockType t = block.getBlockType();
if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) {
treeType.generate(editSession, position.add(0, 1, 0));
return true;
} else if (t == BlockTypes.TALL_GRASS || t == BlockTypes.DEAD_BUSH || t == BlockTypes.POPPY || t == BlockTypes.DANDELION) { // TODO: This list needs to be moved
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
// and then trick the generator here by directly setting into the world
editSession.getWorld().setBlock(position, BlockTypes.AIR.getDefaultState());
// so that now the generator can generate the tree
boolean success = treeType.generate(editSession, position);
if (!success) {
editSession.setBlock(position, block); // restore on failure
}
return success;
} else { // Trees won't grow on this!
return false;
switch (t.getInternalId()) {
case BlockID.GRASS_BLOCK:
case BlockID.DIRT:
treeType.generate(editSession, position.add(0, 1, 0));
return true;
case BlockID.TALL_GRASS: // TODO: This list needs to be moved
case BlockID.DEAD_BUSH:
case BlockID.POPPY:
case BlockID.DANDELION:
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
// and then trick the generator here by directly setting into the world
editSession.getWorld().setBlock(position, BlockTypes.AIR.getDefaultState());
// so that now the generator can generate the tree
boolean success = treeType.generate(editSession, position);
if (!success) {
editSession.setBlock(position, block); // restore on failure
}
return success;
default: // Trees won't grow on this!
return false;
}
}
}