This commit is contained in:
Jesse Boyd
2019-07-18 02:31:13 +10:00
parent 68ea3d6e99
commit 905fbf5a0b
34 changed files with 402 additions and 489 deletions

View File

@ -93,10 +93,11 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
}
protected static int MAX_RANGE = 500;
protected static int DEFAULT_RANGE = 240;
protected int range = -1;
private VisualMode visualMode = VisualMode.NONE;
private TargetMode targetMode = TargetMode.TARGET_BLOCK_RANGE;
private Mask targetMask = null;
private Mask traceMask;
private int targetOffset;
private transient BrushSettings primary = new BrushSettings();
@ -179,7 +180,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
if (targetMode != TargetMode.TARGET_BLOCK_RANGE) {
map.put("target", targetMode);
}
if (range != -1 && range != 240) {
if (range != -1 && range != DEFAULT_RANGE) {
map.put("range", range);
}
if (targetOffset != 0) {
@ -307,6 +308,25 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
update();
}
/**
* Get the mask used for identifying where to stop traces.
*
* @return the mask used to stop block traces
*/
public @Nullable Mask getTraceMask() {
return traceMask;
}
/**
* Set the block mask used for identifying where to stop traces.
*
* @param traceMask the mask used to stop block traces
*/
public void setTraceMask(@Nullable Mask traceMask) {
this.traceMask = traceMask;
update();
}
/**
* Set the block filter used for identifying blocks to replace.
*
@ -329,7 +349,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
current.setBrush(brush);
current.addPermission(permission);
update();
update();
}
/**
@ -392,7 +411,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
* @return the range of the brush in blocks
*/
public int getRange() {
return (range < 0) ? MAX_RANGE : Math.min(range, MAX_RANGE);
return (range < 0) ? DEFAULT_RANGE : Math.min(range, MAX_RANGE);
}
/**
@ -401,7 +420,11 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
* @param range the range of the brush in blocks
*/
public void setRange(int range) {
this.range = range;
if (range == DEFAULT_RANGE) {
range = -1;
} else {
this.range = range;
}
}
@Override
@ -449,7 +472,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
}
private Vector3 trace(EditSession editSession, Player player, int range, boolean useLastBlock) {
Mask mask = targetMask == null ? new SolidBlockMask(editSession) : targetMask;
Mask mask = traceMask == null ? new SolidBlockMask(editSession) : traceMask;
new MaskTraverser(mask).reset(editSession);
MaskedTargetBlock tb = new MaskedTargetBlock(mask, player, range, 0.2);
return TaskManager.IMP.sync(new RunnableVal<Vector3>() {
@ -461,23 +484,23 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
}
public boolean act(BrushAction action, Platform server, LocalConfiguration config, Player player, LocalSession session) {
if (action == BrushAction.PRIMARY) {
setContext(primary);
} else if (action == BrushAction.SECONDARY) {
setContext(secondary);
switch (action) {
case PRIMARY:
setContext(primary);
break;
case SECONDARY:
setContext(secondary);
break;
}
BrushSettings current = getContext();
Brush brush = current.getBrush();
if (brush == null) return false;
BlockBag bag = session.getBlockBag(player);
if (current.setWorld(player.getWorld().getName()) && !current.canUse(player)) {
BBC.NO_PERM.send(player, StringMan.join(current.getPermissions(), ","));
return false;
}
try (EditSession editSession = session.createEditSession(player)) {
if (current.setWorld(editSession.getWorld().getName()) && !current.canUse(player)) {
BBC.NO_PERM.send(player, StringMan.join(current.getPermissions(), ","));
return false;
}
BlockVector3 target = getPosition(editSession, player);
if (target == null) {
@ -485,6 +508,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
BBC.NO_BLOCK.send(player);
return true;
}
BlockBag bag = editSession.getBlockBag();
Request.request().setEditSession(editSession);
Mask mask = current.getMask();
@ -519,11 +543,11 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
if (bag != null) {
bag.flushChanges();
}
}
} finally {
if (bag != null) {
bag.flushChanges();
}
Request.reset();
}
@ -552,11 +576,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
update();
}
public void setTargetMask(Mask mask) {
this.targetMask = mask;
update();
}
public void setVisualMode(Player player, VisualMode visualMode) {
if (visualMode == null) visualMode = VisualMode.NONE;
if (this.visualMode != visualMode) {
@ -583,10 +602,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
return targetOffset;
}
public Mask getTargetMask() {
return targetMask;
}
public VisualMode getVisualMode() {
return visualMode;
}

View File

@ -75,7 +75,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
if (this.range > -1) {
target = player.getBlockTrace(getRange(), true);
} else {
target = player.getBlockTrace(MAX_RANGE);
target = player.getBlockTrace(DEFAULT_RANGE);
}
if (target == null) {

View File

@ -92,12 +92,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
private Location getTargetFace(Player player) {
Location target = player.getBlockTraceFace(getRange(), true);
if (this.range > -1) {
target = player.getBlockTrace(getRange(), true);
} else {
target = player.getBlockTrace(MAX_RANGE, false);
}
target = player.getBlockTrace(getRange(), true);
if (target == null) {
BBC.NO_BLOCK.send(player);
return null;

View File

@ -88,37 +88,4 @@ public class RecursivePickaxe implements BlockTool {
return true;
}
private static void recurse(Platform server, EditSession editSession, World world, BlockVector3 pos,
BlockVector3 origin, double size, BlockType initialType, Set<BlockVector3> visited) throws MaxChangedBlocksException {
final double distanceSq = origin.distanceSq(pos);
if (distanceSq > size*size || visited.contains(pos)) {
return;
}
visited.add(pos);
if (editSession.getBlock(pos).getBlockType() != initialType) {
return;
}
editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
world.queueBlockBreakEffect(server, pos, initialType, distanceSq);
recurse(server, editSession, world, pos.add(1, 0, 0),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(-1, 0, 0),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, 1),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, -1),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 1, 0),
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, -1, 0),
origin, size, initialType, visited);
}
}

View File

@ -44,7 +44,7 @@ public class ClipboardBrush implements Brush {
this.ignoreAirBlocks = ignoreAirBlocks;
this.usingOrigin = usingOrigin;
this.pasteBiomes = false;
this.pasteEntities = false;
this.pasteEntities = true;
this.sourceMask = null;
}