Changed Super Pickaxe to use EditSession.

This fixes WORLDEDIT-3102 and allows the logging of Super Pickaxe
usage via the EditSession Extent pipeline.
This commit is contained in:
sk89q
2014-04-23 00:33:00 -07:00
parent bf062298f1
commit f94be80923
7 changed files with 253 additions and 40 deletions

View File

@ -57,18 +57,16 @@ public class AreaPickaxe implements BlockTool {
}
EditSession editSession = session.createEditSession(player);
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
try {
for (int x = ox - range; x <= ox + range; ++x) {
for (int y = oy - range; y <= oy + range; ++y) {
for (int z = oz - range; z <= oz + range; ++z) {
Vector pos = new Vector(x, y, z);
if (world.getBlockType(pos) != initialType) {
if (editSession.getBlockType(pos) != initialType) {
continue;
}
if (config.superPickaxeManyDrop) {
world.simulateBlockMine(pos);
}
world.queueBlockBreakEffect(server, pos, initialType, clicked.distanceSq(pos));
@ -79,6 +77,7 @@ public class AreaPickaxe implements BlockTool {
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
editSession.flushQueue();
session.remember(editSession);
}

View File

@ -19,13 +19,13 @@
package com.sk89q.worldedit.command.tool;
import java.util.HashSet;
import java.util.Set;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import java.util.HashSet;
import java.util.Set;
/**
* A pickaxe mode that recursively finds adjacent blocks within range of
* an initial block and of the same type.
@ -59,14 +59,15 @@ public class RecursivePickaxe implements BlockTool {
}
EditSession editSession = session.createEditSession(player);
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
try {
recurse(server, editSession, world, clicked.toBlockVector(),
clicked, range, initialType, new HashSet<BlockVector>(),
config.superPickaxeManyDrop);
clicked, range, initialType, new HashSet<BlockVector>());
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
editSession.flushQueue();
session.remember(editSession);
}
@ -77,7 +78,6 @@ public class RecursivePickaxe implements BlockTool {
* Helper method.
*
* @param server
* @param superPickaxeManyDrop
* @param world
* @param pos
* @param origin
@ -88,7 +88,7 @@ public class RecursivePickaxe implements BlockTool {
private static void recurse(ServerInterface server, EditSession editSession,
LocalWorld world, BlockVector pos,
Vector origin, double size, int initialType,
Set<BlockVector> visited, boolean drop)
Set<BlockVector> visited)
throws MaxChangedBlocksException {
final double distanceSq = origin.distanceSq(pos);
@ -102,26 +102,22 @@ public class RecursivePickaxe implements BlockTool {
return;
}
if (drop) {
world.simulateBlockMine(pos);
}
world.queueBlockBreakEffect(server, pos, initialType, distanceSq);
editSession.setBlock(pos, air);
recurse(server, editSession, world, pos.add(1, 0, 0).toBlockVector(),
origin, size, initialType, visited, drop);
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(),
origin, size, initialType, visited, drop);
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(),
origin, size, initialType, visited, drop);
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(),
origin, size, initialType, visited, drop);
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(),
origin, size, initialType, visited, drop);
origin, size, initialType, visited);
recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(),
origin, size, initialType, visited, drop);
origin, size, initialType, visited);
}
}

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.command.tool;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
/**
@ -43,11 +44,16 @@ public class SinglePickaxe implements BlockTool {
return true;
}
if (config.superPickaxeDrop) {
world.simulateBlockMine(clicked);
}
EditSession editSession = session.createEditSession(player);
editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop);
world.setBlockType(clicked, BlockID.AIR);
try {
editSession.setBlock(clicked, new BaseBlock(BlockID.AIR));
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
editSession.flushQueue();
}
world.playEffect(clicked, 2001, blockType);