Added range command for brushes. Thanks Nichts

This commit is contained in:
Wizjany 2011-06-22 18:28:56 -04:00
parent 45302859ef
commit 021e99c252
6 changed files with 86 additions and 4 deletions

View File

@ -275,6 +275,10 @@ commands:
description: Set the brush size
usage: /<command> [pattern]
permissions: 'worldedit.brush.options.size'
range:
description: Set the brush range
usage: /<command> [range]
permissions: 'worldedit.brush.options.range'
mask:
description: Set the brush mask
usage: /<command> [mask]

View File

@ -12,7 +12,7 @@
<description>WorldEdit allows for editing the Minecraft SMP world
en-masse, de-griefing, and fixing issues.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<scm>

View File

@ -302,6 +302,19 @@ public abstract class LocalPlayer {
pos.getY() - 1, pos.getZ());
}
/**
* Get the point of the block being looked at. May return null.
* Will return the farthest away air block if useLastBlock is true and no other block is found.
*
* @param range
* @param useLastBlock
* @return point
*/
public WorldVector getBlockTrace(int range, boolean useLastBlock) {
TargetBlock tb = new TargetBlock(this, range, 0.2);
return (useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock());
}
/**
* Get the point of the block being looked at. May return null.
*
@ -309,8 +322,7 @@ public abstract class LocalPlayer {
* @return point
*/
public WorldVector getBlockTrace(int range) {
TargetBlock tb = new TargetBlock(this, range, 0.2);
return tb.getTargetBlock();
return getBlockTrace(range, false);
}
/**

View File

@ -109,6 +109,22 @@ public class ToolUtilCommands {
player.print("Brush material set.");
}
@Command(
aliases = {"range"},
usage = "[pattern]",
desc = "Set the brush range",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.brush.options.range"})
public static void range(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int range = args.getInteger(0);
session.getBrushTool(player.getItemInHand()).setRange(range);
player.print("Brush range set.");
}
@Command(
aliases = {"size"},
usage = "[pattern]",

View File

@ -36,6 +36,8 @@ import com.sk89q.worldedit.tools.brushes.SphereBrush;
* @author sk89q
*/
public class BrushTool implements TraceTool {
private static int MAX_RANGE = 500;
private int range = -1;
private Mask mask = null;
private Brush brush = new SphereBrush();
private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE));
@ -136,6 +138,24 @@ public class BrushTool implements TraceTool {
this.size = size;
}
/**
* Get the set brush range.
*
* @return
*/
public int getRange() {
return (range < 0) ? MAX_RANGE : Math.min(range, MAX_RANGE);
}
/**
* Set the set brush range.
*
* @param size
*/
public void setRange(int range) {
this.range = range;
}
/**
* Perform the action. Should return true to deny the default
* action.
@ -146,7 +166,12 @@ public class BrushTool implements TraceTool {
*/
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session) {
WorldVector target = player.getBlockTrace(500);
WorldVector target = null;
if (this.range > -1) {
target = player.getBlockTrace(getRange(), true);
} else {
target = player.getBlockTrace(MAX_RANGE);
}
if (target == null) {
player.printError("No block in sight!");

View File

@ -100,6 +100,31 @@ public class TargetBlock {
prevPos = targetPos;
}
/**
* Returns any block at the sight. Returns null if out of range or if no
* viable target was found. Will try to return the last valid air block it finds.
*
* @return Block
*/
public BlockWorldVector getAnyTargetBlock() {
boolean searchForLastBlock = true;
BlockWorldVector lastBlock = null;
while (getNextBlock() != null) {
if (world.getBlockType(getCurrentBlock()) == 0) {
if(searchForLastBlock) {
lastBlock = getCurrentBlock();
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= 127) {
searchForLastBlock = false;
}
}
} else {
break;
}
}
BlockWorldVector currentBlock = getCurrentBlock();
return (currentBlock != null ? currentBlock : lastBlock);
}
/**
* Returns the block at the sight. Returns null if out of range or if no
* viable target was found