Removed more deprecated code

This commit is contained in:
Matthew Miller
2018-06-19 17:03:09 +10:00
parent 416480c16d
commit 66d70f00e7
19 changed files with 107 additions and 296 deletions

View File

@ -197,7 +197,7 @@ public class GenerationCommands {
@Logging(POSITION)
public void forestGen(Player player, LocalSession session, EditSession editSession, @Optional("10") int size, @Optional("tree") TreeType type, @Optional("5") double density) throws WorldEditException {
density = density / 100;
int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, new TreeGenerator(type));
int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, type);
player.print(affected + " trees created.");
}

View File

@ -437,7 +437,7 @@ public class RegionCommands {
public void forest(Player player, EditSession editSession, @Selection Region region, @Optional("tree") TreeType type,
@Optional("5") @Range(min = 0, max = 100) double density) throws WorldEditException {
density = density / 100;
ForestGenerator generator = new ForestGenerator(editSession, new TreeGenerator(type));
ForestGenerator generator = new ForestGenerator(editSession, type);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));

View File

@ -89,7 +89,7 @@ public class ToolCommands {
}
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), new TreePlanter(new TreeGenerator(type)));
session.setTool(itemStack.getType(), new TreePlanter(type));
player.print("Tree tool bound to " + itemStack.getType().getName() + ".");
}

View File

@ -94,7 +94,7 @@ public class TreeGeneratorParser implements CommandExecutor<Contextual<ForestGen
@Override
public ForestGenerator createFromContext(EditContext input) {
return new ForestGenerator((EditSession) input.getDestination(), new TreeGenerator(type));
return new ForestGenerator((EditSession) input.getDestination(), type);
}
@Override

View File

@ -24,8 +24,9 @@ import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockCategories;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
@ -55,6 +56,15 @@ public class FloatingTreeRemover implements BlockTool {
return player.hasPermission("worldedit.tool.deltree");
}
private boolean isTreeBlock(BlockType type) {
return BlockCategories.LEAVES.contains(type)
|| BlockCategories.LOGS.contains(type)
|| type == BlockTypes.RED_MUSHROOM_BLOCK
|| type == BlockTypes.BROWN_MUSHROOM_BLOCK
|| type == BlockTypes.MUSHROOM_STEM
|| type == BlockTypes.VINE;
}
@Override
public boolean actPrimary(Platform server, LocalConfiguration config,
Player player, LocalSession session, Location clicked) {
@ -62,17 +72,7 @@ public class FloatingTreeRemover implements BlockTool {
final World world = (World) clicked.getExtent();
final BlockState state = world.getBlock(clicked.toVector());
switch (world.getLazyBlock(clicked.toVector()).getId()) {
case BlockID.LOG:
case BlockID.LOG2:
case BlockID.LEAVES:
case BlockID.LEAVES2:
case BlockID.BROWN_MUSHROOM_CAP:
case BlockID.RED_MUSHROOM_CAP:
case BlockID.VINE:
break;
default:
if (!isTreeBlock(state.getBlockType())) {
player.printError("That's not a tree.");
return true;
}
@ -87,15 +87,8 @@ public class FloatingTreeRemover implements BlockTool {
}
for (Vector blockVector : blockSet) {
final int typeId = editSession.getBlock(blockVector).getBlockType().getLegacyId();
switch (typeId) {
case BlockID.LOG:
case BlockID.LOG2:
case BlockID.LEAVES:
case BlockID.LEAVES2:
case BlockID.BROWN_MUSHROOM_CAP:
case BlockID.RED_MUSHROOM_CAP:
case BlockID.VINE:
final BlockState otherState = editSession.getBlock(blockVector);
if (isTreeBlock(otherState.getBlockType())) {
editSession.setBlock(blockVector, AIR);
}
}
@ -141,39 +134,24 @@ public class FloatingTreeRemover implements BlockTool {
}
if (visited.add(next)) {
switch (world.getLazyBlock(next).getId()) {
case BlockID.AIR:
case BlockID.SNOW:
// we hit air or snow => stop walking this route
BlockState state = world.getBlock(next);
if (state.getBlockType() == BlockTypes.AIR || state.getBlockType() == BlockTypes.SNOW) {
continue;
case BlockID.LOG:
case BlockID.LOG2:
case BlockID.LEAVES:
case BlockID.LEAVES2:
case BlockID.BROWN_MUSHROOM_CAP:
case BlockID.RED_MUSHROOM_CAP:
case BlockID.VINE:
// queue next point
}
if (isTreeBlock(state.getBlockType())) {
queue.addLast(next);
break;
default:
} else {
// we hit something solid - evaluate where we came from
final int curId = world.getLazyBlock(current).getId();
if (curId == BlockID.LEAVES || curId == BlockID.LEAVES2
|| curId == BlockID.VINE) {
// leaves touching a wall/the ground => stop walking this route
continue;
} else {
final BlockType currentType = world.getBlock(current).getBlockType();
if (!BlockCategories.LEAVES.contains(currentType) && currentType != BlockTypes.VINE) {
// log/shroom touching a wall/the ground => this is not a floating tree, bail out
return null;
}
} // switch
} // if
} // for
} // while
}
}
}
}
return visited;
} // bfs
}
}

View File

@ -22,9 +22,7 @@ package com.sk89q.worldedit.command.tool;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
import com.sk89q.worldedit.blocks.NoteBlock;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
@ -57,9 +55,6 @@ public class QueryTool implements BlockTool {
if (block instanceof MobSpawnerBlock) {
player.printRaw("\u00A7e" + "Mob Type: "
+ ((MobSpawnerBlock) block).getMobType());
} else if (block instanceof NoteBlock) {
player.printRaw("\u00A7e" + "Note block: "
+ ((NoteBlock) block).getNote());
}
return true;

View File

@ -30,10 +30,10 @@ import com.sk89q.worldedit.util.*;
*/
public class TreePlanter implements BlockTool {
private TreeGenerator gen;
private TreeGenerator.TreeType treeType;
public TreePlanter(TreeGenerator gen) {
this.gen = gen;
public TreePlanter(TreeGenerator.TreeType treeType) {
this.treeType = treeType;
}
@Override
@ -50,7 +50,7 @@ public class TreePlanter implements BlockTool {
boolean successful = false;
for (int i = 0; i < 10; i++) {
if (gen.generate(editSession, clicked.toVector().add(0, 1, 0))) {
if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0))) {
successful = true;
break;
}