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

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