mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Added range command for brushes. Thanks Nichts
This commit is contained in:
parent
45302859ef
commit
021e99c252
@ -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]
|
||||
|
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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]",
|
||||
|
@ -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));
|
||||
@ -135,6 +137,24 @@ public class BrushTool implements TraceTool {
|
||||
public void setSize(int 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
|
||||
@ -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!");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user