From c759b9062c618a3e655f39e5344e9b8cc34649ef Mon Sep 17 00:00:00 2001 From: aumgn Date: Wed, 29 Aug 2012 11:32:14 +0200 Subject: [PATCH] Add BlockMask which is able to filter by data --- .../java/com/sk89q/worldedit/WorldEdit.java | 2 +- .../com/sk89q/worldedit/masks/BlockMask.java | 46 +++++++++++++++++++ .../sk89q/worldedit/masks/BlockTypeMask.java | 28 ++++------- .../masks/InvertedBlockTypeMask.java | 2 +- 4 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/sk89q/worldedit/masks/BlockMask.java diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index d2443a168..c3f274fe9 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -642,7 +642,7 @@ public class WorldEdit { } default: - return new BlockTypeMask(getBlockIDs(player, component, true)); + return new BlockMask(getBlocks(player, component, true, true)); } } diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java new file mode 100644 index 000000000..7172d3b10 --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java @@ -0,0 +1,46 @@ +package com.sk89q.worldedit.masks; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; + +public class BlockMask implements Mask { + + protected Set blocks; + + public BlockMask() { + blocks = new HashSet(); + } + + public BlockMask(Set types) { + this.blocks = types; + } + + public BlockMask(BaseBlock block) { + this(); + add(block); + } + + public void add(BaseBlock block) { + blocks.add(block); + } + + public void addAll(Collection blocks) { + blocks.addAll(blocks); + } + + public void prepare(LocalSession session, LocalPlayer player, Vector target) { + } + + public boolean matches(EditSession editSession, Vector pos) { + BaseBlock block = editSession.getBlock(pos); + return blocks.contains(block) + || blocks.contains(new BaseBlock(block.getType(), -1)); + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java index ce2ed7c52..c1eab46f5 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java @@ -19,27 +19,27 @@ package com.sk89q.worldedit.masks; -import java.util.HashSet; import java.util.Set; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; /** * A filter that matches blocks based on block types. * + * @deprecated replaced by {@link #BlockMask} * @author sk89q */ -public class BlockTypeMask implements Mask { - protected Set types; +@Deprecated +public class BlockTypeMask extends BlockMask { public BlockTypeMask() { - types = new HashSet(); + super(); } public BlockTypeMask(Set types) { - this.types = types; + super(); + for (int type : types) { + add(type); + } } public BlockTypeMask(int type) { @@ -48,14 +48,6 @@ public class BlockTypeMask implements Mask { } public void add(int type) { - types.add(type); + add(new BaseBlock(type)); } - - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - } - - public boolean matches(EditSession editSession, Vector pos) { - return types.contains(editSession.getBlockType(pos)); - } - } diff --git a/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java index 1df18ca58..c4856ab09 100644 --- a/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java @@ -49,7 +49,7 @@ public class InvertedBlockTypeMask extends BlockTypeMask { @Override public boolean matches(EditSession editSession, Vector pos) { - return !types.contains(editSession.getBlockType(pos)); + return !super.matches(editSession, pos); } }