Overhauled the tool system. All tools can now be bound to any held item so you can have multiple tools out a time. New masks framework allows making a filter of blocks to change. Brushes are now powerful as well.

This commit is contained in:
sk89q 2011-02-18 15:14:43 -08:00
parent dfc7d074bd
commit b311b0b88a
40 changed files with 1024 additions and 636 deletions

View File

@ -2,18 +2,18 @@ name: WorldEdit
main: com.sk89q.worldedit.bukkit.WorldEditPlugin main: com.sk89q.worldedit.bukkit.WorldEditPlugin
version: "WEVERSIONMACRO" version: "WEVERSIONMACRO"
commands: commands:
/sb: sphere:
description: Choose the sphere brush description: Choose the sphere brush
usage: /<command> [-h] <block> [radius] usage: /<command> [-h] <block> [radius]
aliases: ['/sphereb'] aliases: ['s']
/cb: cylinder:
description: Choose the cylinder brush description: Choose the cylinder brush
usage: /<command> [-h] <block> [radius] [height] usage: /<command> [-h] <block> [radius] [height]
aliases: ['/cylb'] aliases: ['cyl', 'c']
/cbb: clipboard:
description: Choose the clipboard brush description: Choose the clipboard brush
usage: /<command> [-a] usage: /<command> [-a]
aliases: ['/copyb'] aliases: ['copy']
chunkinfo: chunkinfo:
description: Get information about the chunk that you are inside description: Get information about the chunk that you are inside
usage: /<command> usage: /<command>
@ -57,18 +57,18 @@ commands:
/limit: /limit:
description: Modify block change limit description: Modify block change limit
usage: /<command> <limit> usage: /<command> <limit>
/hcyl: /sphere:
description: Generate a hollow cylinder description: Generate a filled sphere
usage: /<command> <block> <radius> [height] usage: /<command> <block> <radius> [raised?]
/cyl: /cyl:
description: Generate a cylinder description: Generate a cylinder
usage: /<command> <block> <radius> [height] usage: /<command> <block> <radius> [height]
/hcyl:
description: Generate a hollow cylinder
usage: /<command> <block> <radius> [height]
/hsphere: /hsphere:
description: Generate a hollow sphere description: Generate a hollow sphere
usage: /<command> <block> <radius> [raised?] usage: /<command> <block> <radius> [raised?]
/sphere:
description: Generate a filled sphere
usage: /<command> <block> <radius> [raised?]
forestgen: forestgen:
description: Generate a forest description: Generate a forest
usage: /<command> [size] [type] [density] usage: /<command> [size] [type] [density]
@ -184,13 +184,16 @@ commands:
/restore: /restore:
description: Restore the selection from a snapshot description: Restore the selection from a snapshot
usage: /<command> [snapshot] usage: /<command> [snapshot]
/:
description: Toggle the super pickaxe pickaxe function
usage: /<command>
aliases: [',']
area: area:
description: Enable the area super pickaxe pickaxe mode description: Enable the area super pickaxe pickaxe mode
usage: /<command> <radius> usage: /<command> <radius>
recur:
description: Enable the recursive super pickaxe pickaxe mode
usage: /<command> <radius>
aliases: ['recursive']
single:
description: Enable the single block super pickaxe mode
usage: /<command>
none: none:
description: Turn off all superpickaxe alternate modes description: Turn off all superpickaxe alternate modes
usage: /<command> usage: /<command>
@ -200,24 +203,31 @@ commands:
cycler: cycler:
description: Block data cycler tool description: Block data cycler tool
usage: /<command> usage: /<command>
/brush: brush:
description: Build from far away description: Brush tool
usage: /<command> [-r]
/rbrush:
description: Brush tool that will only replace blocks
usage: /<command> usage: /<command>
recur: aliases: ['b']
description: Enable the recursive super pickaxe pickaxe mode
usage: /<command> <radius>
info: info:
description: Block information tool description: Block information tool
usage: /<command> usage: /<command>
single:
description: Enable the single block super pickaxe mode
usage: /<command>
tree: tree:
description: Tree generator tool description: Tree generator tool
usage: /<command> [type] usage: /<command> [type]
tool:
description: Select a tool to bind
usage: /<command>
aliases: ['t']
/:
description: Toggle the super pickaxe pickaxe function
usage: /<command>
aliases: [',']
pickaxe:
description: Select super pickaxe mode
usage: /<command>
aliases: ['pa', 'spa']
mask:
description: Set the brush mask
usage: /<command> [mask]
/fillr: /fillr:
description: Fill a hole recursively description: Fill a hole recursively
usage: /<command> <block> <radius> [depth] usage: /<command> <block> <radius> [depth]

View File

@ -104,11 +104,10 @@ public class EditSession {
/** /**
* Construct the object with a maximum number of blocks. * Construct the object with a maximum number of blocks.
* *
* @param server
* @param world * @param world
* @param maxBlocks * @param maxBlocks
*/ */
public EditSession(ServerInterface server, LocalWorld world, int maxBlocks) { public EditSession(LocalWorld world, int maxBlocks) {
if (maxBlocks < -1) { if (maxBlocks < -1) {
throw new IllegalArgumentException("Max blocks must be >= -1"); throw new IllegalArgumentException("Max blocks must be >= -1");
} }
@ -120,12 +119,12 @@ public class EditSession {
/** /**
* Construct the object with a maximum number of blocks and a block bag. * Construct the object with a maximum number of blocks and a block bag.
* *
* @param server * @param world
* @param maxBlocks * @param maxBlocks
* @param blockBag
* @blockBag * @blockBag
*/ */
public EditSession(ServerInterface server, LocalWorld world, int maxBlocks, public EditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) {
BlockBag blockBag) {
if (maxBlocks < -1) { if (maxBlocks < -1) {
throw new IllegalArgumentException("Max blocks must be >= -1"); throw new IllegalArgumentException("Max blocks must be >= -1");
} }
@ -231,6 +230,7 @@ public class EditSession {
* @param pt * @param pt
* @param block * @param block
* @return Whether the block changed -- not entirely dependable * @return Whether the block changed -- not entirely dependable
* @throws MaxChangedBlocksException
*/ */
public boolean setBlock(Vector pt, BaseBlock block) public boolean setBlock(Vector pt, BaseBlock block)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
@ -249,6 +249,19 @@ public class EditSession {
return smartSetBlock(pt, block); return smartSetBlock(pt, block);
} }
/**
* Set a block with a pattern.
*
* @param pt
* @param pat
* @return Whether the block changed -- not entirely dependable
* @throws MaxChangedBlocksException
*/
public boolean setBlock(Vector pt, Pattern pat)
throws MaxChangedBlocksException {
return setBlock(pt, pat.next(pt));
}
/** /**
* Set a block only if there's no block already there. * Set a block only if there's no block already there.
* *
@ -381,23 +394,23 @@ public class EditSession {
/** /**
* Restores all blocks to their initial state. * Restores all blocks to their initial state.
*/ */
public void undo() { public void undo(EditSession sess) {
for (Map.Entry<BlockVector, BaseBlock> entry : original) { for (Map.Entry<BlockVector, BaseBlock> entry : original) {
BlockVector pt = (BlockVector) entry.getKey(); BlockVector pt = (BlockVector) entry.getKey();
smartSetBlock(pt, (BaseBlock) entry.getValue()); sess.smartSetBlock(pt, (BaseBlock) entry.getValue());
} }
flushQueue(); sess.flushQueue();
} }
/** /**
* Sets to new state. * Sets to new state.
*/ */
public void redo() { public void redo(EditSession sess) {
for (Map.Entry<BlockVector, BaseBlock> entry : current) { for (Map.Entry<BlockVector, BaseBlock> entry : current) {
BlockVector pt = (BlockVector) entry.getKey(); BlockVector pt = (BlockVector) entry.getKey();
smartSetBlock(pt, (BaseBlock) entry.getValue()); sess.smartSetBlock(pt, (BaseBlock) entry.getValue());
} }
flushQueue(); sess.flushQueue();
} }
/** /**
@ -1453,7 +1466,7 @@ public class EditSession {
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
private int makeHCylinderPoints(Vector center, int x, int z, int height, private int makeHCylinderPoints(Vector center, int x, int z, int height,
BaseBlock block) throws MaxChangedBlocksException { Pattern block) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
if (x == 0) { if (x == 0) {
@ -1499,7 +1512,7 @@ public class EditSession {
* @return number of blocks set * @return number of blocks set
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int makeHollowCylinder(Vector pos, BaseBlock block, int radius, public int makeHollowCylinder(Vector pos, Pattern block, int radius,
int height) throws MaxChangedBlocksException { int height) throws MaxChangedBlocksException {
int x = 0; int x = 0;
int z = radius; int z = radius;
@ -1548,7 +1561,7 @@ public class EditSession {
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
private int makeCylinderPoints(Vector center, int x, int z, int height, private int makeCylinderPoints(Vector center, int x, int z, int height,
BaseBlock block) throws MaxChangedBlocksException { Pattern block) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
if (x == z) { if (x == z) {
@ -1586,7 +1599,7 @@ public class EditSession {
* @return number of blocks set * @return number of blocks set
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int makeCylinder(Vector pos, BaseBlock block, int radius, int height) public int makeCylinder(Vector pos, Pattern block, int radius, int height)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int x = 0; int x = 0;
int z = radius; int z = radius;
@ -1634,7 +1647,7 @@ public class EditSession {
* @return number of blocks changed * @return number of blocks changed
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int makeSphere(Vector pos, BaseBlock block, int radius, public int makeSphere(Vector pos, Pattern block, int radius,
boolean filled) throws MaxChangedBlocksException { boolean filled) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;

View File

@ -19,7 +19,7 @@ package com.sk89q.worldedit;
*/ */
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.filters.HeightMapFilter; import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
/** /**

View File

@ -19,20 +19,29 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map;
import com.sk89q.worldedit.snapshots.Snapshot; import com.sk89q.worldedit.snapshots.Snapshot;
import com.sk89q.worldedit.superpickaxe.SinglePickaxe; import com.sk89q.worldedit.tools.Brush;
import com.sk89q.worldedit.superpickaxe.SuperPickaxeMode; import com.sk89q.worldedit.tools.SinglePickaxe;
import com.sk89q.worldedit.superpickaxe.brushes.BrushShape; import com.sk89q.worldedit.tools.BlockTool;
import com.sk89q.worldedit.tools.Tool;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
/** /**
* An instance of this represents the WorldEdit session of a user. A session
* stores history and settings. Sessions are not tied particularly to any
* player and can be shuffled between players, saved, and loaded.
* *
* @author sk89q * @author sk89q
*/ */
public class LocalSession { public class LocalSession {
/**
* List of compass modes.
*/
public enum CompassMode { public enum CompassMode {
JUMPTO, JUMPTO,
THRU THRU
@ -50,15 +59,14 @@ public class LocalSession {
private CuboidClipboard clipboard; private CuboidClipboard clipboard;
private boolean toolControl = true; private boolean toolControl = true;
private boolean superPickaxe = false; private boolean superPickaxe = false;
private SuperPickaxeMode leftClickMode = new SinglePickaxe(); private BlockTool pickaxeMode = new SinglePickaxe();
private SuperPickaxeMode armSwingMode; private Map<Integer, Tool> tools
private SuperPickaxeMode rightClickMode; = new HashMap<Integer, Tool>();
private int maxBlocksChanged = -1; private int maxBlocksChanged = -1;
private boolean useInventory; private boolean useInventory;
private Snapshot snapshot; private Snapshot snapshot;
private String lastScript; private String lastScript;
private CompassMode compassMode = CompassMode.JUMPTO; private CompassMode compassMode = CompassMode.JUMPTO;
private BrushShape brushShape = null;
private boolean beenToldVersion = false; private boolean beenToldVersion = false;
/** /**
@ -79,7 +87,10 @@ public class LocalSession {
} }
/** /**
* Get the edit session. * Remember an edit session for the undo history. If the history maximum
* size is reached, old edit sessions will be discarded.
*
* @param editSession
*/ */
public void remember(EditSession editSession) { public void remember(EditSession editSession) {
// Don't store anything if no changes were made // Don't store anything if no changes were made
@ -97,16 +108,18 @@ public class LocalSession {
} }
/** /**
* Undo. * Performs an undo.
* *
* @param newBlockBag
* @return whether anything was undone * @return whether anything was undone
*/ */
public EditSession undo(BlockBag newBlockBag) { public EditSession undo(BlockBag newBlockBag) {
historyPointer--; historyPointer--;
if (historyPointer >= 0) { if (historyPointer >= 0) {
EditSession editSession = history.get(historyPointer); EditSession editSession = history.get(historyPointer);
editSession.setBlockBag(newBlockBag); EditSession newEditSession =
editSession.undo(); new EditSession(editSession.getWorld(), -1, newBlockBag);
editSession.undo(newEditSession);
return editSession; return editSession;
} else { } else {
historyPointer = 0; historyPointer = 0;
@ -115,15 +128,17 @@ public class LocalSession {
} }
/** /**
* Redo. * Performs a redo
* *
* @param newBlockBag
* @return whether anything was redone * @return whether anything was redone
*/ */
public EditSession redo(BlockBag newBlockBag) { public EditSession redo(BlockBag newBlockBag) {
if (historyPointer < history.size()) { if (historyPointer < history.size()) {
EditSession editSession = history.get(historyPointer); EditSession editSession = history.get(historyPointer);
editSession.setBlockBag(newBlockBag); EditSession newEditSession =
editSession.redo(); new EditSession(editSession.getWorld(), -1, newBlockBag);
editSession.redo(newEditSession);
historyPointer++; historyPointer++;
return editSession; return editSession;
} }
@ -156,7 +171,7 @@ public class LocalSession {
/** /**
* Returns true if the region is fully defined. * Returns true if the region is fully defined.
* *
* @throws IncompleteRegionException * @return
*/ */
public boolean isRegionDefined() { public boolean isRegionDefined() {
return pos1 != null && pos2 != null; return pos1 != null && pos2 != null;
@ -303,8 +318,6 @@ public class LocalSession {
/** /**
* Enable super pick axe. * Enable super pick axe.
*
* @param superPickaxe
*/ */
public void enableSuperPickAxe() { public void enableSuperPickAxe() {
superPickaxe = true; superPickaxe = true;
@ -312,8 +325,6 @@ public class LocalSession {
/** /**
* Disable super pick axe. * Disable super pick axe.
*
* @param superPickaxe
*/ */
public void disableSuperPickAxe() { public void disableSuperPickAxe() {
superPickaxe = false; superPickaxe = false;
@ -330,6 +341,9 @@ public class LocalSession {
} }
/** /**
* Get the placement position.
*
* @param player
* @return position * @return position
* @throws IncompleteRegionException * @throws IncompleteRegionException
*/ */
@ -344,7 +358,9 @@ public class LocalSession {
} }
/** /**
* Toggle placement position; * Toggle placement position.
*
* @return
*/ */
public boolean togglePlacementPosition() { public boolean togglePlacementPosition() {
placeAtPos1 = !placeAtPos1; placeAtPos1 = !placeAtPos1;
@ -365,13 +381,17 @@ public class LocalSession {
} }
/** /**
* @return the snapshotName * Get the snapshot that has been selected.
*
* @return the snapshot
*/ */
public Snapshot getSnapshot() { public Snapshot getSnapshot() {
return snapshot; return snapshot;
} }
/** /**
* Select a snapshot.
*
* @param snapshot * @param snapshot
*/ */
public void setSnapshot(Snapshot snapshot) { public void setSnapshot(Snapshot snapshot) {
@ -381,46 +401,61 @@ public class LocalSession {
/** /**
* @return the superPickaxeMode * @return the superPickaxeMode
*/ */
public SuperPickaxeMode getLeftClickMode() { public BlockTool getSuperPickaxe() {
return leftClickMode; return pickaxeMode;
} }
/** /**
* @param superPickaxeMode the superPickaxeMode to set * Set the super pickaxe tool.
*
* @param tool
*/ */
public void setLeftClickMode(SuperPickaxeMode leftClickMode) { public void setSuperPickaxe(BlockTool tool) {
this.leftClickMode = leftClickMode; this.pickaxeMode = tool;
} }
/** /**
* Get the tool assigned to the item.
*
* @param item
* @return the tool * @return the tool
*/ */
public SuperPickaxeMode getRightClickMode() { public Tool getTool(int item) {
return rightClickMode; return tools.get(item);
} }
/** /**
* Get the brush tool assigned to the item. If there is no tool assigned
* or the tool is not assigned, the slot will be replaced with the
* brush tool.
*
* @param item
* @return the tool
*/
public Brush getBrushTool(int item) {
Tool tool = getTool(item);
if (tool == null || !(tool instanceof Brush)) {
tool = new Brush();
setTool(item, tool);
}
return (Brush)tool;
}
/**
* Set the tool.
*
* @param item
* @param tool the tool to set * @param tool the tool to set
*/ */
public void setRightClickMode(SuperPickaxeMode rightClickMode) { public void setTool(int item, Tool tool) {
this.rightClickMode = rightClickMode; this.tools.put(item, tool);
}
/**
* @return the arm swing mode
*/
public SuperPickaxeMode getArmSwingMode() {
return armSwingMode;
}
/**
* @param rightClickMode the tool to set
*/
public void setArmSwingMode(SuperPickaxeMode armSwingMode) {
this.armSwingMode = armSwingMode;
} }
/** /**
* Returns whether inventory usage is enabled for this session.
*
* @return the useInventory * @return the useInventory
*/ */
public boolean isUsingInventory() { public boolean isUsingInventory() {
@ -428,6 +463,8 @@ public class LocalSession {
} }
/** /**
* Set the state of inventory usage.
*
* @param useInventory the useInventory to set * @param useInventory the useInventory to set
*/ */
public void setUseInventory(boolean useInventory) { public void setUseInventory(boolean useInventory) {
@ -435,6 +472,8 @@ public class LocalSession {
} }
/** /**
* Get the last script used.
*
* @return the lastScript * @return the lastScript
*/ */
public String getLastScript() { public String getLastScript() {
@ -442,6 +481,8 @@ public class LocalSession {
} }
/** /**
* Set the last script used.
*
* @param lastScript the lastScript to set * @param lastScript the lastScript to set
*/ */
public void setLastScript(String lastScript) { public void setLastScript(String lastScript) {
@ -449,6 +490,8 @@ public class LocalSession {
} }
/** /**
* Get the compass mode.
*
* @return the compassMode * @return the compassMode
*/ */
public CompassMode getCompassMode() { public CompassMode getCompassMode() {
@ -456,28 +499,18 @@ public class LocalSession {
} }
/** /**
* Set the compass mode.
*
* @param compassMode the compassMode to set * @param compassMode the compassMode to set
*/ */
public void setCompassMode(CompassMode compassMode) { public void setCompassMode(CompassMode compassMode) {
this.compassMode = compassMode; this.compassMode = compassMode;
} }
/**
* @return the brushShape
*/
public BrushShape getBrushShape() {
return brushShape;
}
/**
* @param brushShape the brushShape to set
*/
public void setBrushShape(BrushShape brushShape) {
this.brushShape = brushShape;
}
/** /**
* Tell the player the WorldEdit version. * Tell the player the WorldEdit version.
*
* @param player
*/ */
public void tellVersion(LocalPlayer player) { public void tellVersion(LocalPlayer player) {
if (config.showFirstUseVersion) { if (config.showFirstUseVersion) {

View File

@ -21,78 +21,62 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.masks.Mask;
/** /**
* An edit session that can be set to not replace existing blocks. * An edit session that will only replace blocks as specified.
* *
* @author sk89q * @author sk89q
*/ */
public class ReplacingEditSession extends EditSession { public class ReplacingEditSession extends EditSession {
/** /**
* True to prevent replacing. * Filter to use to filter blocks.
*/ */
private boolean noReplace = false; private Mask mask;
/** /**
* Construct the object. * Construct the object.
* *
* @param server
* @param world * @param world
* @param maxBlocks * @param maxBlocks
* @param mask
*/ */
public ReplacingEditSession(ServerInterface server, LocalWorld world, public ReplacingEditSession(LocalWorld world,
int maxBlocks) { int maxBlocks, Mask mask) {
super(server, world, maxBlocks); super(world, maxBlocks);
this.mask = mask;
} }
/** /**
* Construct the object. * Construct the object.
* *
* @param server
* @param world * @param world
* @param maxBlocks * @param maxBlocks
* @param blockBag * @param blockBag
* @param mask
*/ */
public ReplacingEditSession(ServerInterface server, LocalWorld world, public ReplacingEditSession(LocalWorld world, int maxBlocks,
int maxBlocks, BlockBag blockBag) { BlockBag blockBag, Mask mask) {
super(server, world, maxBlocks, blockBag); super(world, maxBlocks, blockBag);
} this.mask = mask;
/**
* Enables block replacing.
*/
public void enableReplacing() {
noReplace = false;
}
/**
* Disables block replacing.
*/
public void disableReplacing() {
noReplace = true;
} }
/** /**
* Sets a block without changing history. * Sets a block without changing history.
* *
* @param pt * @param pt
* @param blockType * @param block
* @return Whether the block changed * @return Whether the block changed
*/ */
@Override
public boolean rawSetBlock(Vector pt, BaseBlock block) { public boolean rawSetBlock(Vector pt, BaseBlock block) {
if (!noReplace) {
return super.rawSetBlock(pt, block);
}
int y = pt.getBlockY(); int y = pt.getBlockY();
if (y < 0 || y > 127) { if (y < 0 || y > 127) {
return false; return false;
} }
int existing = world.getBlockType(pt); if (!mask.matches(this, pt)) {
if (existing != 0) {
return false; return false;
} }

View File

@ -1,102 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* An edit session that can be set to only replace existing blocks.
*
* @author sk89q
*/
public class ReplacingExistingEditSession extends EditSession {
/**
* True to replace existing.
*/
private boolean replaceExisting = false;
/**
* Construct the object.
*
* @param server
* @param world
* @param maxBlocks
*/
public ReplacingExistingEditSession(ServerInterface server, LocalWorld world,
int maxBlocks) {
super(server, world, maxBlocks);
}
/**
* Construct the object.
*
* @param server
* @param world
* @param maxBlocks
* @param blockBag
*/
public ReplacingExistingEditSession(ServerInterface server, LocalWorld world,
int maxBlocks, BlockBag blockBag) {
super(server, world, maxBlocks, blockBag);
}
/**
* Enables block replacing.
*/
public void enableReplacing() {
replaceExisting = true;
}
/**
* Disables block replacing.
*/
public void disableReplacing() {
replaceExisting = false;
}
/**
* Sets a block without changing history.
*
* @param pt
* @param blockType
* @return Whether the block changed
*/
public boolean rawSetBlock(Vector pt, BaseBlock block) {
if (!replaceExisting) {
return super.rawSetBlock(pt, block);
}
int y = pt.getBlockY();
if (y < 0 || y > 127) {
return false;
}
int existing = world.getBlockType(pt);
if (existing == 0) {
return false;
}
return super.rawSetBlock(pt, block);
}
}

View File

@ -29,7 +29,6 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.io.*; import java.io.*;
import javax.script.ScriptException; import javax.script.ScriptException;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandsManager; import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.util.StringUtil; import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalSession.CompassMode; import com.sk89q.worldedit.LocalSession.CompassMode;
@ -37,6 +36,12 @@ import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.*; import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.commands.*; import com.sk89q.worldedit.commands.*;
import com.sk89q.worldedit.scripting.*; import com.sk89q.worldedit.scripting.*;
import com.sk89q.worldedit.tools.BlockTool;
import com.sk89q.worldedit.tools.Tool;
import com.sk89q.worldedit.tools.TraceTool;
import com.sk89q.worldedit.masks.BlockTypeMask;
import com.sk89q.worldedit.masks.ExistingBlockMask;
import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.patterns.*; import com.sk89q.worldedit.patterns.*;
/** /**
@ -105,8 +110,8 @@ public class WorldEdit {
commands.register(ScriptingCommands.class); commands.register(ScriptingCommands.class);
commands.register(SelectionCommands.class); commands.register(SelectionCommands.class);
commands.register(SnapshotCommands.class); commands.register(SnapshotCommands.class);
commands.register(SuperPickaxeCommands.class); commands.register(ToolUtilCommands.class);
commands.register(BrushShapeCommands.class); commands.register(ToolCommands.class);
commands.register(UtilityCommands.class); commands.register(UtilityCommands.class);
} }
@ -290,6 +295,8 @@ public class WorldEdit {
* @param player * @param player
* @param list * @param list
* @return pattern * @return pattern
* @throws UnknownItemException
* @throws DisallowedItemException
*/ */
public Pattern getBlockPattern(LocalPlayer player, String list) public Pattern getBlockPattern(LocalPlayer player, String list)
throws UnknownItemException, DisallowedItemException { throws UnknownItemException, DisallowedItemException {
@ -335,6 +342,29 @@ public class WorldEdit {
return new RandomFillPattern(blockChances); return new RandomFillPattern(blockChances);
} }
/**
* Get a block mask. Block masks are used to determine which
* blocks to include when replacing.
*
* @param player
* @param list
* @return
* @throws UnknownItemException
* @throws DisallowedItemException
*/
public Mask getBlockMask(LocalPlayer player, String list)
throws UnknownItemException, DisallowedItemException {
if (list.charAt(0) == '#') {
if (list.equalsIgnoreCase("#existing")) {
return new ExistingBlockMask();
} else {
throw new UnknownItemException(list);
}
} else {
return new BlockTypeMask(getBlockIDs(player, list, true));
}
}
/** /**
* Get a list of blocks as a set. * Get a list of blocks as a set.
* *
@ -342,6 +372,8 @@ public class WorldEdit {
* @param list * @param list
* @param allBlocksAllowed * @param allBlocksAllowed
* @return set * @return set
* @throws UnknownItemException
* @throws DisallowedItemException
*/ */
public Set<Integer> getBlockIDs(LocalPlayer player, public Set<Integer> getBlockIDs(LocalPlayer player,
String list, boolean allBlocksAllowed) String list, boolean allBlocksAllowed)
@ -361,6 +393,7 @@ public class WorldEdit {
* traversal exploits by checking the root directory and the file directory. * traversal exploits by checking the root directory and the file directory.
* On success, a <code>java.io.File</code> object will be returned. * On success, a <code>java.io.File</code> object will be returned.
* *
* @param player
* @param dir sub-directory to look in * @param dir sub-directory to look in
* @param filename filename (user-submitted) * @param filename filename (user-submitted)
* @param defaultExt append an extension if missing one, null to not use * @param defaultExt append an extension if missing one, null to not use
@ -380,6 +413,7 @@ public class WorldEdit {
* traversal exploits by checking the root directory and the file directory. * traversal exploits by checking the root directory and the file directory.
* On success, a <code>java.io.File</code> object will be returned. * On success, a <code>java.io.File</code> object will be returned.
* *
* @param player
* @param dir sub-directory to look in * @param dir sub-directory to look in
* @param filename filename (user-submitted) * @param filename filename (user-submitted)
* @param defaultExt append an extension if missing one, null to not use * @param defaultExt append an extension if missing one, null to not use
@ -493,8 +527,9 @@ public class WorldEdit {
* null if a direction could not be found. * null if a direction could not be found.
* *
* @param player * @param player
* @param dir * @param dirStr
* @return * @return
* @throws UnknownDirectionException
*/ */
public Vector getDirection(LocalPlayer player, String dirStr) public Vector getDirection(LocalPlayer player, String dirStr)
throws UnknownDirectionException { throws UnknownDirectionException {
@ -540,8 +575,9 @@ public class WorldEdit {
* null if a direction could not be found. * null if a direction could not be found.
* *
* @param player * @param player
* @param dir * @param dirStr
* @return * @return
* @throws UnknownDirectionException
*/ */
public CuboidClipboard.FlipDirection getFlipDirection( public CuboidClipboard.FlipDirection getFlipDirection(
LocalPlayer player, String dirStr) LocalPlayer player, String dirStr)
@ -589,7 +625,6 @@ public class WorldEdit {
* Flush a block bag's changes to a player. * Flush a block bag's changes to a player.
* *
* @param player * @param player
* @param blockBag
* @param editSession * @param editSession
*/ */
public void flushBlockBag(LocalPlayer player, public void flushBlockBag(LocalPlayer player,
@ -651,13 +686,7 @@ public class WorldEdit {
public boolean handleArmSwing(LocalPlayer player) { public boolean handleArmSwing(LocalPlayer player) {
LocalSession session = getSession(player); LocalSession session = getSession(player);
if (player.isHoldingPickAxe()) { if (player.getItemInHand() == config.navigationWand
if (session.getArmSwingMode() != null) {
session.getArmSwingMode().act(server, config,
player, session, null);
return true;
}
} else if (player.getItemInHand() == config.navigationWand
&& config.navigationWandMaxDistance > 0) { && config.navigationWandMaxDistance > 0) {
CompassMode mode = session.getCompassMode(); CompassMode mode = session.getCompassMode();
@ -687,13 +716,7 @@ public class WorldEdit {
public boolean handleRightClick(LocalPlayer player) { public boolean handleRightClick(LocalPlayer player) {
LocalSession session = getSession(player); LocalSession session = getSession(player);
if (player.isHoldingPickAxe()) { if (player.getItemInHand() == config.navigationWand) {
if (session.getArmSwingMode() != null) {
session.getArmSwingMode().act(server, config,
player, session, null);
return true;
}
} else if (player.getItemInHand() == config.navigationWand) {
CompassMode mode = session.getCompassMode(); CompassMode mode = session.getCompassMode();
if (mode == CompassMode.JUMPTO) { if (mode == CompassMode.JUMPTO) {
@ -715,6 +738,13 @@ public class WorldEdit {
return true; return true;
} }
Tool tool = session.getTool(player.getItemInHand());
if (tool != null && tool instanceof TraceTool) {
((TraceTool)tool).act(server, config, player, session);
return true;
}
return false; return false;
} }
@ -733,6 +763,7 @@ public class WorldEdit {
if (itemInHand == config.wandItem && session.isToolControlEnabled() if (itemInHand == config.wandItem && session.isToolControlEnabled()
&& player.hasPermission("worldedit.selection.pos")) { && player.hasPermission("worldedit.selection.pos")) {
session.setPos2(clicked); session.setPos2(clicked);
try { try {
player.print("Second position set to " + clicked player.print("Second position set to " + clicked
+ " (" + session.getRegion().getSize() + ")."); + " (" + session.getRegion().getSize() + ").");
@ -741,8 +772,13 @@ public class WorldEdit {
} }
return true; return true;
} else if (player.isHoldingPickAxe() && session.getRightClickMode() != null) { }
return session.getRightClickMode().act(server, config, player, session, clicked);
Tool tool = session.getTool(player.getItemInHand());
if (tool != null && tool instanceof BlockTool) {
((BlockTool)tool).act(server, config, player, session, clicked);
return true;
} }
return false; return false;
@ -785,8 +821,8 @@ public class WorldEdit {
return true; return true;
} }
} else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) { } else if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
if (session.getLeftClickMode() != null) { if (session.getSuperPickaxe() != null) {
return session.getLeftClickMode().act(server, config, return session.getSuperPickaxe().act(server, config,
player, session, clicked); player, session, clicked);
} }
} }
@ -830,7 +866,7 @@ public class WorldEdit {
session.tellVersion(player); session.tellVersion(player);
EditSession editSession = EditSession editSession =
new EditSession(server, player.getWorld(), new EditSession(player.getWorld(),
session.getBlockChangeLimit(), blockBag); session.getBlockChangeLimit(), blockBag);
editSession.enableQueue(); editSession.enableQueue();
@ -913,7 +949,7 @@ public class WorldEdit {
* Executes a WorldEdit script. * Executes a WorldEdit script.
* *
* @param player * @param player
* @param filename * @param f
* @param args * @param args
* @throws WorldEditException * @throws WorldEditException
*/ */

View File

@ -30,28 +30,29 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.superpickaxe.brushes.ClipboardBrushShape; import com.sk89q.worldedit.tools.Brush;
import com.sk89q.worldedit.superpickaxe.brushes.CylinderBrushShape; import com.sk89q.worldedit.tools.brushes.ClipboardBrush;
import com.sk89q.worldedit.superpickaxe.brushes.HollowCylinderBrushShape; import com.sk89q.worldedit.tools.brushes.CylinderBrush;
import com.sk89q.worldedit.superpickaxe.brushes.SphereBrushShape; import com.sk89q.worldedit.tools.brushes.HollowCylinderBrush;
import com.sk89q.worldedit.superpickaxe.brushes.HollowSphereBrushShape; import com.sk89q.worldedit.tools.brushes.HollowSphereBrush;
import com.sk89q.worldedit.tools.brushes.SphereBrush;
/** /**
* Brush shape commands. * Brush shape commands.
* *
* @author sk89q * @author sk89q
*/ */
public class BrushShapeCommands { public class BrushCommands {
@Command( @Command(
aliases = {"/sb", "/sphereb"}, aliases = {"sphere", "s"},
usage = "<block> [radius]", usage = "<block> [radius]",
flags = "h", flags = "h",
desc = "Choose the sphere brush", desc = "Choose the sphere brush",
min = 1, min = 1,
max = 2 max = 2
) )
@CommandPermissions({"worldedit.superpickaxe.drawing.brush.sphere"}) @CommandPermissions({"worldedit.brush.sphere"})
public static void sphereBrush(CommandContext args, WorldEdit we, public static void sphereBrush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
@ -65,26 +66,30 @@ public class BrushShapeCommands {
return; return;
} }
BaseBlock targetBlock = we.getBlock(player, args.getString(0)); Brush tool = session.getBrushTool(player.getItemInHand());
Pattern fill = we.getBlockPattern(player, args.getString(0));
tool.setFill(fill);
tool.setSize(radius);
if (args.hasFlag('h')) { if (args.hasFlag('h')) {
session.setBrushShape(new HollowSphereBrushShape(targetBlock, radius)); tool.setBrush(new HollowSphereBrush());
} else { } else {
session.setBrushShape(new SphereBrushShape(targetBlock, radius)); tool.setBrush(new SphereBrush());
} }
player.print("Sphere brush shape equipped."); player.print(String.format("Sphere brush shape equipped (%d).",
radius));
} }
@Command( @Command(
aliases = {"/cb", "/cylb"}, aliases = {"cylinder", "cyl", "c"},
usage = "<block> [radius] [height]", usage = "<block> [radius] [height]",
flags = "h", flags = "h",
desc = "Choose the cylinder brush", desc = "Choose the cylinder brush",
min = 1, min = 1,
max = 2 max = 3
) )
@CommandPermissions({"worldedit.superpickaxe.drawing.brush.cylinder"}) @CommandPermissions({"worldedit.brush.cylinder"})
public static void cylinderBrush(CommandContext args, WorldEdit we, public static void cylinderBrush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
@ -98,33 +103,37 @@ public class BrushShapeCommands {
return; return;
} }
int height = args.argsLength() > 1 ? args.getInteger(1) : 1; int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
if (height > config.maxBrushRadius) { if (height > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius/height: " player.printError("Maximum allowed brush radius/height: "
+ config.maxBrushRadius); + config.maxBrushRadius);
return; return;
} }
BaseBlock targetBlock = we.getBlock(player, args.getString(0)); Brush tool = session.getBrushTool(player.getItemInHand());
Pattern fill = we.getBlockPattern(player, args.getString(0));
tool.setFill(fill);
tool.setSize(radius);
if (args.hasFlag('h')) { if (args.hasFlag('h')) {
session.setBrushShape(new HollowCylinderBrushShape(targetBlock, radius, height)); tool.setBrush(new HollowCylinderBrush(height));
} else { } else {
session.setBrushShape(new CylinderBrushShape(targetBlock, radius, height)); tool.setBrush(new CylinderBrush(height));
} }
player.print("Cylinder brush shape equipped."); player.print(String.format("Cylinder brush shape equipped (%d by %d).",
radius, height));
} }
@Command( @Command(
aliases = {"/cbb", "/copyb"}, aliases = {"clipboard", "copy"},
usage = "", usage = "",
flags = "a", flags = "a",
desc = "Choose the clipboard brush", desc = "Choose the clipboard brush",
min = 0, min = 0,
max = 0 max = 0
) )
@CommandPermissions({"worldedit.superpickaxe.drawing.brush.clipboard"}) @CommandPermissions({"worldedit.brush.clipboard"})
public static void clipboardBrush(CommandContext args, WorldEdit we, public static void clipboardBrush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
@ -148,7 +157,8 @@ public class BrushShapeCommands {
return; return;
} }
session.setBrushShape(new ClipboardBrushShape(clipboard, args.hasFlag('a'))); Brush tool = session.getBrushTool(player.getItemInHand());
tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')));
player.print("Clipboard brush shape equipped."); player.print("Clipboard brush shape equipped.");
} }

View File

@ -0,0 +1,67 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.commands;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.tools.Brush;
import com.sk89q.worldedit.tools.ReplacingBrush;
public class BrushModeCommands {
@Command(
aliases = {"normal", "s"},
usage = "",
desc = "Normal brush mode",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.brush.mode.normal"})
public static void normal(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setRightClickMode(null);
session.setArmSwingMode(new Brush(true));
player.print("Normal brush mode set.");
}
@Command(
aliases = {"replace", "r"},
usage = "",
desc = "Replace existing blocks only",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.brush.mode.replace"})
public static void replace(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setRightClickMode(null);
session.setArmSwingMode(new ReplacingBrush());
player.print("Replacing brush mode equipped.");
}
}

View File

@ -23,7 +23,7 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
/** /**
@ -44,7 +44,7 @@ public class GenerationCommands {
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0)); Pattern block = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1)); int radius = Math.max(1, args.getInteger(1));
int height = args.argsLength() > 2 ? args.getInteger(2) : 1; int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
@ -65,7 +65,7 @@ public class GenerationCommands {
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0)); Pattern block = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1)); int radius = Math.max(1, args.getInteger(1));
int height = args.argsLength() > 2 ? args.getInteger(2) : 1; int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
@ -86,7 +86,7 @@ public class GenerationCommands {
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0)); Pattern block = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1)); int radius = Math.max(1, args.getInteger(1));
boolean raised = args.argsLength() > 2 boolean raised = args.argsLength() > 2
? (args.getString(2).equalsIgnoreCase("true") ? (args.getString(2).equalsIgnoreCase("true")
@ -115,7 +115,7 @@ public class GenerationCommands {
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0)); Pattern block = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1)); int radius = Math.max(1, args.getInteger(1));
boolean raised = args.argsLength() > 2 boolean raised = args.argsLength() > 2
? (args.getString(2).equalsIgnoreCase("true") ? (args.getString(2).equalsIgnoreCase("true")

View File

@ -25,8 +25,8 @@ import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.filters.GaussianKernel; import com.sk89q.worldedit.filtering.GaussianKernel;
import com.sk89q.worldedit.filters.HeightMapFilter; import com.sk89q.worldedit.filtering.HeightMapFilter;
import com.sk89q.worldedit.patterns.*; import com.sk89q.worldedit.patterns.*;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;

View File

@ -1,7 +1,7 @@
// $Id$ // $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> * Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,37 +22,17 @@ package com.sk89q.worldedit.commands;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.NestedCommand; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.superpickaxe.*; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.tools.AreaPickaxe;
import com.sk89q.worldedit.tools.RecursivePickaxe;
import com.sk89q.worldedit.tools.SinglePickaxe;
/**
* Super pickaxe commands.
*
* @author sk89q
*/
public class SuperPickaxeCommands { public class SuperPickaxeCommands {
@Command(
aliases = {"/", ","},
usage = "",
desc = "Toggle the super pickaxe pickaxe function",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.pickaxe"})
public static void togglePickaxe(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (session.toggleSuperPickAxe()) {
player.print("Super pick axe enabled.");
} else {
player.print("Super pick axe disabled.");
}
}
@Command( @Command(
aliases = {"single"}, aliases = {"single"},
usage = "", usage = "",
@ -60,12 +40,12 @@ public class SuperPickaxeCommands {
min = 0, min = 0,
max = 0 max = 0
) )
@CommandPermissions({"worldedit.superpickaxe.pickaxe"}) @CommandPermissions({"worldedit.superpickaxe"})
public static void single(CommandContext args, WorldEdit we, public static void single(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
session.setLeftClickMode(new SinglePickaxe()); session.setSuperPickaxe(new SinglePickaxe());
session.enableSuperPickAxe(); session.enableSuperPickAxe();
player.print("Mode changed. Left click with a pickaxe. // to disable."); player.print("Mode changed. Left click with a pickaxe. // to disable.");
} }
@ -77,7 +57,7 @@ public class SuperPickaxeCommands {
min = 1, min = 1,
max = 1 max = 1
) )
@CommandPermissions({"worldedit.superpickaxe.pickaxe.area"}) @CommandPermissions({"worldedit.superpickaxe.area"})
public static void area(CommandContext args, WorldEdit we, public static void area(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
@ -90,19 +70,19 @@ public class SuperPickaxeCommands {
return; return;
} }
session.setLeftClickMode(new AreaPickaxe(range)); session.setSuperPickaxe(new AreaPickaxe(range));
session.enableSuperPickAxe(); session.enableSuperPickAxe();
player.print("Mode changed. Left click with a pickaxe. // to disable."); player.print("Mode changed. Left click with a pickaxe. // to disable.");
} }
@Command( @Command(
aliases = {"recur"}, aliases = {"recur", "recursive"},
usage = "<radius>", usage = "<radius>",
desc = "Enable the recursive super pickaxe pickaxe mode", desc = "Enable the recursive super pickaxe pickaxe mode",
min = 1, min = 1,
max = 1 max = 1
) )
@CommandPermissions({"worldedit.superpickaxe.pickaxe.recursive"}) @CommandPermissions({"worldedit.superpickaxe.recursive"})
public static void recursive(CommandContext args, WorldEdit we, public static void recursive(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession) LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException { throws WorldEditException {
@ -115,143 +95,8 @@ public class SuperPickaxeCommands {
return; return;
} }
session.setLeftClickMode(new RecursivePickaxe(range)); session.setSuperPickaxe(new RecursivePickaxe(range));
session.enableSuperPickAxe(); session.enableSuperPickAxe();
player.print("Mode changed. Left click with a pickaxe. // to disable."); player.print("Mode changed. Left click with a pickaxe. // to disable.");
} }
@Command(
aliases = {"none"},
usage = "",
desc = "Turn off all superpickaxe alternate modes",
min = 0,
max = 0
)
public static void none(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(null);
player.print("Now no longer equipping a tool.");
}
@Command(
aliases = {"info"},
usage = "",
desc = "Block information tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.info"})
public static void info(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(new QueryTool());
player.print("Info tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"tree"},
usage = "[type]",
desc = "Tree generator tool",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.superpickaxe.tree"})
public static void tree(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
TreeGenerator.TreeType type = args.argsLength() > 0 ?
type = TreeGenerator.lookup(args.getString(0))
: TreeGenerator.TreeType.TREE;
if (type == null) {
player.printError("Tree type '" + args.getString(0) + "' is unknown.");
return;
}
session.setArmSwingMode(null);
session.setRightClickMode(new TreePlanter(new TreeGenerator(type)));
player.print("Tree tool equipped. Right click grass with a pickaxe.");
}
@Command(
aliases = {"repl"},
usage = "<block>",
desc = "Block replacer tool",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.superpickaxe.replacer"})
public static void repl(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
session.setArmSwingMode(null);
session.setRightClickMode(new BlockReplacer(targetBlock));
player.print("Block replacer tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"cycler"},
usage = "",
desc = "Block data cycler tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.data-cycler"})
public static void cycler(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(new BlockDataCyler());
player.print("Block cycler tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"/brush"},
usage = "",
flags = "r",
desc = "Build from far away",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.drawing.brush"})
public static void brush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
boolean nonReplacing = args.hasFlag('r');
session.setRightClickMode(null);
session.setArmSwingMode(new Brush(nonReplacing));
if (nonReplacing) {
player.print("Non-replacing brush tool equipped.");
} else {
player.print("Brush tool equipped. Swing with a pickaxe.");
}
}
@Command(
aliases = {"/rbrush"},
usage = "",
desc = "Brush tool that will only replace blocks",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.drawing.brush"})
public static void rbrush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setRightClickMode(null);
session.setArmSwingMode(new ReplacingBrush());
player.print("Replacing brush tool equipped. Swing with a pickaxe.");
}
} }

View File

@ -0,0 +1,130 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.commands;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.NestedCommand;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.tools.*;
import com.sk89q.worldedit.util.TreeGenerator;
public class ToolCommands {
@Command(
aliases = {"none"},
usage = "",
desc = "Turn off all superpickaxe alternate modes",
min = 0,
max = 0
)
public static void none(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setTool(player.getItemInHand(), null);
player.print("Now no longer equipping a tool.");
}
@Command(
aliases = {"info"},
usage = "",
desc = "Block information tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.tool.info"})
public static void info(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setTool(player.getItemInHand(), new QueryTool());
player.print("Info tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"tree"},
usage = "[type]",
desc = "Tree generator tool",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.tool.tree"})
public static void tree(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
TreeGenerator.TreeType type = args.argsLength() > 0 ?
type = TreeGenerator.lookup(args.getString(0))
: TreeGenerator.TreeType.TREE;
if (type == null) {
player.printError("Tree type '" + args.getString(0) + "' is unknown.");
return;
}
session.setTool(player.getItemInHand(), new TreePlanter(new TreeGenerator(type)));
player.print("Tree tool equipped. Right click grass with a pickaxe.");
}
@Command(
aliases = {"repl"},
usage = "<block>",
desc = "Block replacer tool",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.tool.replacer"})
public static void repl(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock));
player.print("Block replacer tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"cycler"},
usage = "",
desc = "Block data cycler tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.tool.data-cycler"})
public static void cycler(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setTool(player.getItemInHand(), new BlockDataCyler());
player.print("Block cycler tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"brush", "b"},
desc = "Brush tool"
)
@NestedCommand({BrushCommands.class})
public static void brush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
}
}

View File

@ -0,0 +1,93 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.commands;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.NestedCommand;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.masks.Mask;
/**
* Tool commands.
*
* @author sk89q
*/
public class ToolUtilCommands {
@Command(
aliases = {"/", ","},
usage = "",
desc = "Toggle the super pickaxe pickaxe function",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe"})
public static void togglePickaxe(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (session.toggleSuperPickAxe()) {
player.print("Super pick axe enabled.");
} else {
player.print("Super pick axe disabled.");
}
}
@Command(
aliases = {"pickaxe", "pa", "spa"},
desc = "Select super pickaxe mode"
)
@NestedCommand({SuperPickaxeCommands.class})
public static void pickaxe(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
}
@Command(
aliases = {"tool", "t"},
desc = "Select a tool to bind"
)
@NestedCommand({ToolCommands.class})
public static void tool(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
}
@Command(
aliases = {"mask"},
usage = "[mask]",
desc = "Set the brush mask",
min = 0,
max = 1
)
public static void mask(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (args.argsLength() == 0) {
session.getBrushTool(player.getItemInHand()).setMask(null);
player.print("Brush mask disabled.");
} else {
Mask mask = we.getBlockMask(player, args.getString(0));
session.getBrushTool(player.getItemInHand()).setMask(mask);
player.print("Brush mask set.");
}
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.filters; package com.sk89q.worldedit.filtering;
import java.awt.image.Kernel; import java.awt.image.Kernel;

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.filters; package com.sk89q.worldedit.filtering;
import java.awt.image.Kernel; import java.awt.image.Kernel;

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.filters; package com.sk89q.worldedit.filtering;
import java.awt.image.Kernel; import java.awt.image.Kernel;

View File

@ -17,26 +17,40 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe.brushes; package com.sk89q.worldedit.masks;
import java.util.HashSet;
import java.util.Set;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
public class HollowCylinderBrushShape implements BrushShape { /**
private BaseBlock targetBlock; * A filter that matches blocks based on block types.
private int radius; *
private int height; * @author sk89q
*/
public class BlockTypeMask implements Mask {
private Set<Integer> types;
public HollowCylinderBrushShape(BaseBlock targetBlock, int radius, int height) { public BlockTypeMask() {
this.targetBlock = targetBlock; types = new HashSet<Integer>();
this.radius = radius;
this.height = height;
} }
public void build(EditSession editSession, Vector pos) public BlockTypeMask(Set<Integer> types) {
throws MaxChangedBlocksException { this.types = types;
editSession.makeHollowCylinder(pos, targetBlock, radius, height);
} }
public BlockTypeMask(int type) {
this();
add(type);
}
public void add(int type) {
types.add(type);
}
public boolean matches(EditSession editSession, Vector pos) {
return types.contains(editSession.getBlockType(pos));
}
} }

View File

@ -0,0 +1,29 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
public class ExistingBlockMask implements Mask {
public boolean matches(EditSession editSession, Vector pos) {
return editSession.getBlockType(pos) != 0;
}
}

View File

@ -0,0 +1,42 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
/**
* Base matcher for the block filtering framework. Implementing classes
* can be used to filter blocks to set or replace
*
* @author sk89q
*/
public interface Mask {
/**
* Given a block position, this method returns true if the block at
* that position matches the filter. Block information is not provided
* as getting a BaseBlock has unneeded overhead in most block querying
* situations (enumerating a chest's contents is a waste, for example).
*
* @param pos
* @return
*/
public boolean matches(EditSession editSession, Vector pos);
}

View File

@ -61,7 +61,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
*/ */
public EditSession remember() { public EditSession remember() {
EditSession editSession = EditSession editSession =
new EditSession(server, player.getWorld(), new EditSession(player.getWorld(),
session.getBlockChangeLimit(), session.getBlockBag(player)); session.getBlockChangeLimit(), session.getBlockBag(player));
editSession.enableQueue(); editSession.enableQueue();
editSessions.add(editSession); editSessions.add(editSession);

View File

@ -1,79 +0,0 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.superpickaxe;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.superpickaxe.brushes.BrushShape;
/**
* Builds a shape at the place being looked at.
*
* @author sk89q
*/
public class Brush implements SuperPickaxeMode {
private boolean nonReplacing;
public Brush(boolean nonReplacing) {
this.nonReplacing = nonReplacing;
}
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
WorldVector target = player.getBlockTrace(500);
if (target == null) {
player.printError("No block in sight!");
return true;
}
BlockBag bag = session.getBlockBag(player);
BrushShape shape = session.getBrushShape();
if (shape == null) {
player.printError("Select a brush first.");
return true;
}
ReplacingEditSession editSession = new ReplacingEditSession(server, target.getWorld(),
session.getBlockChangeLimit(), bag);
if (nonReplacing) {
editSession.disableReplacing();
}
try {
shape.build(editSession, target);
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
if (bag != null) {
bag.flushChanges();
}
editSession.enableReplacing();
session.remember(editSession);
}
return true;
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
@ -28,7 +28,7 @@ import com.sk89q.worldedit.blocks.BlockID;
* *
* @author sk89q * @author sk89q
*/ */
public class AreaPickaxe implements SuperPickaxeMode { public class AreaPickaxe implements BlockTool {
private static final BaseBlock air = new BaseBlock(0); private static final BaseBlock air = new BaseBlock(0);
private int range; private int range;
@ -53,8 +53,8 @@ public class AreaPickaxe implements SuperPickaxeMode {
return true; return true;
} }
EditSession editSession = new EditSession(server, world, EditSession editSession =
session.getBlockChangeLimit()); new EditSession(world, session.getBlockChangeLimit());
try { try {
for (int x = ox - range; x <= ox + range; x++) { for (int x = ox - range; x <= ox + range; x++) {

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockID;
@ -27,7 +27,7 @@ import com.sk89q.worldedit.blocks.BlockID;
* *
* @author sk89q * @author sk89q
*/ */
public class BlockDataCyler implements SuperPickaxeMode { public class BlockDataCyler implements BlockTool {
@Override @Override
public boolean act(ServerInterface server, LocalConfiguration config, public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) { LocalPlayer player, LocalSession session, WorldVector clicked) {

View File

@ -17,18 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
/** /**
* A smode that replaces one block. * A mode that replaces one block.
* *
* @author sk89q * @author sk89q
*/ */
public class BlockReplacer implements SuperPickaxeMode { public class BlockReplacer implements BlockTool {
private BaseBlock targetBlock; private BaseBlock targetBlock;
public BlockReplacer(BaseBlock targetBlock) { public BlockReplacer(BaseBlock targetBlock) {
@ -42,7 +42,7 @@ public class BlockReplacer implements SuperPickaxeMode {
BlockBag bag = session.getBlockBag(player); BlockBag bag = session.getBlockBag(player);
LocalWorld world = clicked.getWorld(); LocalWorld world = clicked.getWorld();
EditSession editSession = new EditSession(server, world, -1, bag); EditSession editSession = new EditSession(world, -1, bag);
try { try {
editSession.setBlock(clicked, targetBlock); editSession.setBlock(clicked, targetBlock);

View File

@ -17,20 +17,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
/** /**
* Represents a super pickaxe mode. * Represents a tool that uses a block..
* *
* @author sk89q * @author sk89q
*/ */
public interface SuperPickaxeMode { public interface BlockTool extends Tool {
/** /**
* Perform the action. Should return true to deny the default * Perform the action. Should return true to deny the default
* action. * action.
* *
* @param server
* @param config
* @param player * @param player
* @param session * @param session
* @param clicked * @param clicked

View File

@ -0,0 +1,159 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.patterns.SingleBlockPattern;
import com.sk89q.worldedit.tools.brushes.BrushShape;
import com.sk89q.worldedit.tools.brushes.SphereBrush;
/**
* Builds a shape at the place being looked at.
*
* @author sk89q
*/
public class Brush implements TraceTool {
private Mask mask = null;
private BrushShape brush = new SphereBrush();
private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE));
private int size = 1;
/**
* Get the filter.
*
* @return the filter
*/
public Mask getMask() {
return mask;
}
/**
* Set the block filter used for identifying blocks to replace.
*
* @param filter the filter to set
*/
public void setMask(Mask filter) {
this.mask = filter;
}
/**
* Set the brush.
*
* @param brush
*/
public void setBrush(BrushShape brush) {
this.brush = brush;
}
/**
* Get the current brush.
*
* @return
*/
public BrushShape getBrush() {
return brush;
}
/**
* Set the material.
*
* @param material
*/
public void setFill(Pattern material) {
this.material = material;
}
/**
* Get the material.
*
* @return
*/
public Pattern getMaterial() {
return material;
}
/**
* Get the set brush size.
*
* @return
*/
public int getSize() {
return size;
}
/**
* Set the set brush size.
*
* @param size
*/
public void setSize(int size) {
this.size = size;
}
/**
* Perform the action. Should return true to deny the default
* action.
*
* @param player
* @param session
* @return true to deny
*/
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session) {
WorldVector target = player.getBlockTrace(500);
if (target == null) {
player.printError("No block in sight!");
return true;
}
BlockBag bag = session.getBlockBag(player);
EditSession editSession;
if (mask == null) {
editSession = new EditSession(target.getWorld(),
session.getBlockChangeLimit(), bag);
} else {
editSession = new ReplacingEditSession(target.getWorld(),
session.getBlockChangeLimit(), bag, mask);
}
try {
brush.build(editSession, target, material, size);
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
if (bag != null) {
bag.flushChanges();
}
session.remember(editSession);
}
return true;
}
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.*; import com.sk89q.worldedit.blocks.*;
@ -27,14 +27,14 @@ import com.sk89q.worldedit.blocks.*;
* *
* @author sk89q * @author sk89q
*/ */
public class QueryTool implements SuperPickaxeMode { public class QueryTool implements BlockTool {
@Override @Override
public boolean act(ServerInterface server, LocalConfiguration config, public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) { LocalPlayer player, LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld(); LocalWorld world = clicked.getWorld();
BaseBlock block = (new EditSession(server, world, 0)).rawGetBlock(clicked); BaseBlock block = (new EditSession(world, 0)).rawGetBlock(clicked);
player.print("\u00A79@" + clicked + ": " + "\u00A7e" player.print("\u00A79@" + clicked + ": " + "\u00A7e"
+ "Type: " + block.getType() + "\u00A77" + " (" + "Type: " + block.getType() + "\u00A77" + " ("

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -31,7 +31,7 @@ import com.sk89q.worldedit.blocks.BlockID;
* *
* @author sk89q * @author sk89q
*/ */
public class RecursivePickaxe implements SuperPickaxeMode { public class RecursivePickaxe implements BlockTool {
private static final BaseBlock air = new BaseBlock(0); private static final BaseBlock air = new BaseBlock(0);
private int range; private int range;
@ -54,8 +54,8 @@ public class RecursivePickaxe implements SuperPickaxeMode {
return true; return true;
} }
EditSession editSession = new EditSession(server, world, EditSession editSession =
session.getBlockChangeLimit()); new EditSession(world, session.getBlockChangeLimit());
try { try {
recurse(server, editSession, world, clicked.toBlockVector(), recurse(server, editSession, world, clicked.toBlockVector(),

View File

@ -17,18 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.superpickaxe.brushes.BrushShape; import com.sk89q.worldedit.tools.brushes.BrushShape;
/** /**
* Builds a sphere at the place being looked at. * Builds a sphere at the place being looked at.
* *
* @author sk89q * @author sk89q
*/ */
public class ReplacingBrush implements SuperPickaxeMode { public class ReplacingBrush implements Tool {
public boolean act(ServerInterface server, LocalConfiguration config, public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) { LocalPlayer player, LocalSession session, WorldVector clicked) {
WorldVector target = player.getBlockTrace(500); WorldVector target = player.getBlockTrace(500);

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockID;
@ -27,7 +27,7 @@ import com.sk89q.worldedit.blocks.BlockID;
* *
* @author sk89q * @author sk89q
*/ */
public class SinglePickaxe implements SuperPickaxeMode { public class SinglePickaxe implements BlockTool {
@Override @Override
public boolean act(ServerInterface server, LocalConfiguration config, public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) { LocalPlayer player, LocalSession session, WorldVector clicked) {

View File

@ -0,0 +1,29 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.tools;
/**
* Represents a tool. This interface alone defines nothing. A tool also
* has to implement <code>BlockTool</code> or <code>TraceTool</code>.
*
* @author sk89q
*/
public abstract interface Tool {
}

View File

@ -0,0 +1,45 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
/**
* Represents a tool that does not require a block.
*
* @author sk89q
*/
public interface TraceTool extends Tool {
/**
* Perform the action. Should return true to deny the default
* action.
*
* @param server
* @param config
* @param player
* @param session
* @return true to deny
*/
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session);
}

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe; package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
@ -27,7 +27,7 @@ import com.sk89q.worldedit.util.TreeGenerator;
* *
* @author sk89q * @author sk89q
*/ */
public class TreePlanter implements SuperPickaxeMode { public class TreePlanter implements BlockTool {
private TreeGenerator gen; private TreeGenerator gen;
public TreePlanter(TreeGenerator gen) { public TreePlanter(TreeGenerator gen) {
@ -40,7 +40,7 @@ public class TreePlanter implements SuperPickaxeMode {
LocalWorld world = clicked.getWorld(); LocalWorld world = clicked.getWorld();
EditSession editSession = EditSession editSession =
new EditSession(server, world, session.getBlockChangeLimit()); new EditSession(world, session.getBlockChangeLimit());
try { try {
if (!gen.generate(editSession, clicked.add(0, 1, 0))) { if (!gen.generate(editSession, clicked.add(0, 1, 0))) {

View File

@ -17,11 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe.brushes; package com.sk89q.worldedit.tools.brushes;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.patterns.Pattern;
/** /**
* Represents a shape. * Represents a shape.
@ -34,8 +35,10 @@ public interface BrushShape {
* *
* @param build * @param build
* @param pos * @param pos
* @param mat
* @param size
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public void build(EditSession editSession, Vector pos) public void build(EditSession editSession, Vector pos, Pattern mat, int size)
throws MaxChangedBlocksException; throws MaxChangedBlocksException;
} }

View File

@ -17,23 +17,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe.brushes; package com.sk89q.worldedit.tools.brushes;
import com.sk89q.worldedit.CuboidClipboard; import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.patterns.Pattern;
public class ClipboardBrushShape implements BrushShape { public class ClipboardBrush implements BrushShape {
private CuboidClipboard clipboard; private CuboidClipboard clipboard;
private boolean noAir; private boolean noAir;
public ClipboardBrushShape(CuboidClipboard clipboard, boolean noAir) { public ClipboardBrush(CuboidClipboard clipboard, boolean noAir) {
this.clipboard = clipboard; this.clipboard = clipboard;
this.noAir = noAir; this.noAir = noAir;
} }
public void build(EditSession editSession, Vector pos) public void build(EditSession editSession, Vector pos, Pattern mat, int size)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
clipboard.place(editSession, clipboard.place(editSession,
pos.subtract(clipboard.getSize().divide(2)), noAir); pos.subtract(clipboard.getSize().divide(2)), noAir);

View File

@ -17,26 +17,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe.brushes; package com.sk89q.worldedit.tools.brushes;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.patterns.Pattern;
public class CylinderBrushShape implements BrushShape { public class CylinderBrush implements BrushShape {
private BaseBlock targetBlock;
private int radius;
private int height; private int height;
public CylinderBrushShape(BaseBlock targetBlock, int radius, int height) { public CylinderBrush(int height) {
this.targetBlock = targetBlock;
this.radius = radius;
this.height = height; this.height = height;
} }
public void build(EditSession editSession, Vector pos) public void build(EditSession editSession, Vector pos, Pattern mat, int size)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
editSession.makeCylinder(pos, targetBlock, radius, height); editSession.makeCylinder(pos, mat, size, height);
} }
} }

View File

@ -17,24 +17,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe.brushes; package com.sk89q.worldedit.tools.brushes;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.patterns.Pattern;
public class SphereBrushShape implements BrushShape { public class HollowCylinderBrush implements BrushShape {
private BaseBlock targetBlock; private int height;
private int radius;
public SphereBrushShape(BaseBlock targetBlock, int radius) { public HollowCylinderBrush(int height) {
this.targetBlock = targetBlock; this.height = height;
this.radius = radius;
} }
public void build(EditSession editSession, Vector pos) public void build(EditSession editSession, Vector pos, Pattern mat, int size)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
editSession.makeSphere(pos, targetBlock, radius, true); editSession.makeHollowCylinder(pos, mat, size, height);
} }
} }

View File

@ -17,24 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.superpickaxe.brushes; package com.sk89q.worldedit.tools.brushes;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.patterns.Pattern;
public class HollowSphereBrushShape implements BrushShape { public class HollowSphereBrush implements BrushShape {
private BaseBlock targetBlock; public HollowSphereBrush() {
private int radius;
public HollowSphereBrushShape(BaseBlock targetBlock, int radius) {
this.targetBlock = targetBlock;
this.radius = radius;
} }
public void build(EditSession editSession, Vector pos) public void build(EditSession editSession, Vector pos, Pattern mat, int size)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
editSession.makeSphere(pos, targetBlock, radius, false); editSession.makeSphere(pos, mat, size, false);
} }
} }

View File

@ -0,0 +1,35 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.tools.brushes;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.patterns.Pattern;
public class SphereBrush implements BrushShape {
public SphereBrush() {
}
public void build(EditSession editSession, Vector pos, Pattern mat, int size)
throws MaxChangedBlocksException {
editSession.makeSphere(pos, mat, size, true);
}
}