Cleanup overlay/underlay mask.

This commit is contained in:
Wizjany 2011-08-13 00:29:28 -04:00
parent af2429467d
commit 9d753c8692
2 changed files with 41 additions and 99 deletions

View File

@ -476,7 +476,7 @@ public class WorldEdit {
for (String component : maskString.split(" ")) { for (String component : maskString.split(" ")) {
Mask current = null; Mask current = null;
if (component.length() == 0) { if (component.length() == 0) {
continue; continue;
} }
@ -487,82 +487,36 @@ public class WorldEdit {
|| component.equalsIgnoreCase("#region") || component.equalsIgnoreCase("#region")
|| component.equalsIgnoreCase("#sel")) { || component.equalsIgnoreCase("#sel")) {
current = new RegionMask(session.getSelection(player.getWorld())); current = new RegionMask(session.getSelection(player.getWorld()));
} } else {
else {
throw new UnknownItemException(component); throw new UnknownItemException(component);
} }
} } else if (component.charAt(0) == '>'
else if (component.charAt(0) == '>') { || component.charAt(0) == '<') {
LocalWorld world = player.getWorld(); LocalWorld world = player.getWorld();
Set<Integer> set = new HashSet<Integer>(); boolean over = component.charAt(0) == '>';
String ids = component.replaceAll(">", ""); Set<Integer> set = new HashSet<Integer>();
if(ids.equalsIgnoreCase("*")){ String ids = component.replaceAll(">", "").replaceAll("<", "");
current = new UnderOverlayMask(set,true,true);
}
else{
String[] split = ids.split(",");
for(String sid :split){
try{
int pid = Integer.parseInt(sid);
if(!world.isValidBlockType(pid)){
throw new UnknownItemException(sid);
}
else{
set.add(pid);
}
}catch(NumberFormatException e){
BlockType type = BlockType.lookup(sid);
int id = type.getID();
if(!world.isValidBlockType(id)){
throw new UnknownItemException(sid);
}
else{
set.add(id);
}
}
current = new UnderOverlayMask(set, true, false);
}
}
}
else if (component.charAt(0) == '<') {
LocalWorld world = player.getWorld();
Set<Integer> set = new HashSet<Integer>();
if (!(ids.equals("*") || ids.equals(""))) {
String ids = component.replaceAll("<", ""); for (String sid : ids.split(",")) {
if(ids.equalsIgnoreCase("*")){ try {
current = new UnderOverlayMask(set,false,true); int pid = Integer.parseInt(sid);
if (!world.isValidBlockType(pid)) {
throw new UnknownItemException(sid);
}
set.add(pid);
} catch (NumberFormatException e) {
BlockType type = BlockType.lookup(sid);
int id = type.getID();
if (!world.isValidBlockType(id)) {
throw new UnknownItemException(sid);
}
set.add(id);
} }
else{
String[] split = ids.split(",");
for(String sid :split){
try{
int pid = Integer.parseInt(sid);
if(!world.isValidBlockType(pid)){
throw new UnknownItemException(sid);
}
else{
set.add(pid);
}
}catch(NumberFormatException e){
BlockType type = BlockType.lookup(sid);
int id = type.getID();
if(!world.isValidBlockType(id)){
throw new UnknownItemException(sid);
}
else{
set.add(id);
}
} }
current = new UnderOverlayMask(set, false, false); }
} current = new UnderOverlayMask(set, over);
} } else {
}
else {
if (component.charAt(0) == '!' && component.length() > 1) { if (component.charAt(0) == '!' && component.length() > 1) {
current = new InvertedBlockTypeMask( current = new InvertedBlockTypeMask(
getBlockIDs(player, component.substring(1), true)); getBlockIDs(player, component.substring(1), true));

View File

@ -1,4 +1,3 @@
package com.sk89q.worldedit.masks; package com.sk89q.worldedit.masks;
import java.util.HashSet; import java.util.HashSet;
@ -6,41 +5,30 @@ import java.util.Set;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
/** /**
* *
* @author 1337 * @author 1337
*/ */
public class UnderOverlayMask implements Mask{ public class UnderOverlayMask implements Mask {
boolean overlay; boolean overlay;
boolean wildcard;
Set<Integer> ids = new HashSet<Integer>(); Set<Integer> ids = new HashSet<Integer>();
public UnderOverlayMask(Set<Integer> ids,boolean overlay,boolean wildcard){
public UnderOverlayMask(Set<Integer> ids, boolean overlay) {
addAll(ids); addAll(ids);
this.overlay = overlay; this.overlay = overlay;
this.wildcard = wildcard;
} }
public void addAll(Set<Integer> ids){ public void addAll(Set<Integer> ids){
this.ids.addAll(ids); this.ids.addAll(ids);
} }
public boolean matches(EditSession editSession, Vector pos) { public boolean matches(EditSession editSession, Vector pos) {
if(!wildcard){ int id = editSession.getBlock(pos.setY(pos.getBlockY() + (overlay ? -1 : 1))).getType();
int id = editSession.getBlock(pos.setY(pos.getBlockY() + (overlay ? -1 :1))).getType(); return ids.isEmpty() ? id != BlockID.AIR : ids.contains(id);
if(overlay){
return ids.contains(id);
}
else if(!overlay){
return ids.contains(id);
}
}
else{
return (overlay ? editSession.getBlock(pos.setY(pos.getBlockY() + 1)).getType() != 0: editSession.getBlock(pos.setY(pos.getBlockY() - 1)).getType() != 0);
}
return false;
}
} }
}