geforkt von Mirrors/FastAsyncWorldEdit
Added range command for brushes. Thanks Nichts
Dieser Commit ist enthalten in:
Ursprung
45302859ef
Commit
021e99c252
@ -275,6 +275,10 @@ commands:
|
|||||||
description: Set the brush size
|
description: Set the brush size
|
||||||
usage: /<command> [pattern]
|
usage: /<command> [pattern]
|
||||||
permissions: 'worldedit.brush.options.size'
|
permissions: 'worldedit.brush.options.size'
|
||||||
|
range:
|
||||||
|
description: Set the brush range
|
||||||
|
usage: /<command> [range]
|
||||||
|
permissions: 'worldedit.brush.options.range'
|
||||||
mask:
|
mask:
|
||||||
description: Set the brush mask
|
description: Set the brush mask
|
||||||
usage: /<command> [mask]
|
usage: /<command> [mask]
|
||||||
|
@ -302,6 +302,19 @@ public abstract class LocalPlayer {
|
|||||||
pos.getY() - 1, pos.getZ());
|
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.
|
* Get the point of the block being looked at. May return null.
|
||||||
*
|
*
|
||||||
@ -309,8 +322,7 @@ public abstract class LocalPlayer {
|
|||||||
* @return point
|
* @return point
|
||||||
*/
|
*/
|
||||||
public WorldVector getBlockTrace(int range) {
|
public WorldVector getBlockTrace(int range) {
|
||||||
TargetBlock tb = new TargetBlock(this, range, 0.2);
|
return getBlockTrace(range, false);
|
||||||
return tb.getTargetBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,6 +109,22 @@ public class ToolUtilCommands {
|
|||||||
player.print("Brush material set.");
|
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(
|
@Command(
|
||||||
aliases = {"size"},
|
aliases = {"size"},
|
||||||
usage = "[pattern]",
|
usage = "[pattern]",
|
||||||
|
@ -36,6 +36,8 @@ import com.sk89q.worldedit.tools.brushes.SphereBrush;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class BrushTool implements TraceTool {
|
public class BrushTool implements TraceTool {
|
||||||
|
private static int MAX_RANGE = 500;
|
||||||
|
private int range = -1;
|
||||||
private Mask mask = null;
|
private Mask mask = null;
|
||||||
private Brush brush = new SphereBrush();
|
private Brush brush = new SphereBrush();
|
||||||
private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE));
|
private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE));
|
||||||
@ -136,6 +138,24 @@ public class BrushTool implements TraceTool {
|
|||||||
this.size = size;
|
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
|
* Perform the action. Should return true to deny the default
|
||||||
* action.
|
* action.
|
||||||
@ -146,7 +166,12 @@ public class BrushTool implements TraceTool {
|
|||||||
*/
|
*/
|
||||||
public boolean act(ServerInterface server, LocalConfiguration config,
|
public boolean act(ServerInterface server, LocalConfiguration config,
|
||||||
LocalPlayer player, LocalSession session) {
|
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) {
|
if (target == null) {
|
||||||
player.printError("No block in sight!");
|
player.printError("No block in sight!");
|
||||||
|
@ -100,6 +100,31 @@ public class TargetBlock {
|
|||||||
prevPos = targetPos;
|
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
|
* Returns the block at the sight. Returns null if out of range or if no
|
||||||
* viable target was found
|
* viable target was found
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren