Add BlockMask which is able to filter by data

Dieser Commit ist enthalten in:
aumgn 2012-08-29 11:32:14 +02:00
Ursprung 21d603ce4e
Commit c759b9062c
4 geänderte Dateien mit 58 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -642,7 +642,7 @@ public class WorldEdit {
}
default:
return new BlockTypeMask(getBlockIDs(player, component, true));
return new BlockMask(getBlocks(player, component, true, true));
}
}

Datei anzeigen

@ -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<BaseBlock> blocks;
public BlockMask() {
blocks = new HashSet<BaseBlock>();
}
public BlockMask(Set<BaseBlock> types) {
this.blocks = types;
}
public BlockMask(BaseBlock block) {
this();
add(block);
}
public void add(BaseBlock block) {
blocks.add(block);
}
public void addAll(Collection<BaseBlock> 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));
}
}

Datei anzeigen

@ -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<Integer> types;
@Deprecated
public class BlockTypeMask extends BlockMask {
public BlockTypeMask() {
types = new HashSet<Integer>();
super();
}
public BlockTypeMask(Set<Integer> 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));
}
}

Datei anzeigen

@ -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);
}
}