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

@ -473,13 +473,13 @@ public class WorldEdit {
public Mask getBlockMask(LocalPlayer player, LocalSession session, public Mask getBlockMask(LocalPlayer player, LocalSession session,
String maskString) throws WorldEditException { String maskString) throws WorldEditException {
Mask mask = null; Mask mask = null;
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;
} }
if (component.charAt(0) == '#') { if (component.charAt(0) == '#') {
if (component.equalsIgnoreCase("#existing")) { if (component.equalsIgnoreCase("#existing")) {
current = new ExistingBlockMask(); current = new ExistingBlockMask();
@ -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);
} if (!(ids.equals("*") || ids.equals(""))) {
else{ for (String sid : ids.split(",")) {
String[] split = ids.split(","); try {
for(String sid :split){ int pid = Integer.parseInt(sid);
try{ if (!world.isValidBlockType(pid)) {
int pid = Integer.parseInt(sid); throw new UnknownItemException(sid);
if(!world.isValidBlockType(pid)){ }
throw new UnknownItemException(sid); set.add(pid);
} } catch (NumberFormatException e) {
else{ BlockType type = BlockType.lookup(sid);
set.add(pid); int id = type.getID();
} if (!world.isValidBlockType(id)) {
}catch(NumberFormatException e){ throw new UnknownItemException(sid);
BlockType type = BlockType.lookup(sid); }
int id = type.getID(); set.add(id);
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>();
String ids = component.replaceAll("<", "");
if(ids.equalsIgnoreCase("*")){
current = new UnderOverlayMask(set,false,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, 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) {
if(!wildcard){ public boolean matches(EditSession editSession, Vector pos) {
int id = editSession.getBlock(pos.setY(pos.getBlockY() + (overlay ? -1 :1))).getType(); int id = editSession.getBlock(pos.setY(pos.getBlockY() + (overlay ? -1 : 1))).getType();
if(overlay){ return ids.isEmpty() ? id != BlockID.AIR : ids.contains(id);
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;
}
}