3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-09 13:00:05 +01:00

Implement InvertedMask & UnderOverlayMask as decorators

Dieser Commit ist enthalten in:
aumgn 2012-03-21 11:34:45 +01:00 committet von zml2008
Ursprung eb14efd2df
Commit 30ed049918
4 geänderte Dateien mit 53 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -614,31 +614,13 @@ public class WorldEdit {
case '>':
case '<':
final LocalWorld world = player.getWorld();
final boolean over = firstChar == '>';
final String idString = component.substring(1);
final Set<Integer> ids = new HashSet<Integer>();
if (!(idString.equals("*") || idString.equals(""))) {
for (String sid : idString.split(",")) {
try {
final int pid = Integer.parseInt(sid);
if (!world.isValidBlockType(pid)) {
throw new UnknownItemException(sid);
}
ids.add(pid);
} catch (NumberFormatException e) {
final BlockType type = BlockType.lookup(sid);
final int id = type.getID();
if (!world.isValidBlockType(id)) {
throw new UnknownItemException(sid);
}
ids.add(id);
}
}
Mask submask;
if (component.length() > 1) {
submask = getBlockMaskComponent(player, session, masks, component.substring(1));
} else {
submask = new ExistingBlockMask();
}
return new UnderOverlayMask(ids, over);
return new UnderOverlayMask(submask, firstChar == '>');
case '$':
Set<BiomeType> biomes = new HashSet<BiomeType>();
@ -651,7 +633,7 @@ public class WorldEdit {
case '!':
if (component.length() > 1) {
return new InvertedBlockTypeMask(getBlockIDs(player, component.substring(1), true));
return new InvertedMask(getBlockMaskComponent(player, session, masks, component.substring(1)));
}
default:

Datei anzeigen

@ -28,6 +28,7 @@ import com.sk89q.worldedit.Vector;
*
* @author sk89q
*/
@Deprecated
public class InvertedBlockTypeMask extends BlockTypeMask {
public InvertedBlockTypeMask() {
}

Datei anzeigen

@ -0,0 +1,25 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
public class InvertedMask implements Mask {
private Mask mask;
public InvertedMask(Mask mask) {
this.mask = mask;
}
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
mask.prepare(session, player, target);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !mask.matches(editSession, pos);
}
}

Datei anzeigen

@ -19,14 +19,12 @@
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.BlockID;
/**
*
@ -34,24 +32,37 @@ import com.sk89q.worldedit.blocks.BlockID;
*/
public class UnderOverlayMask implements Mask {
boolean overlay;
Set<Integer> ids = new HashSet<Integer>();
private int yMod;
private Mask mask;
@Deprecated
public UnderOverlayMask(Set<Integer> ids, boolean overlay) {
addAll(ids);
this.overlay = overlay;
this(new BlockTypeMask(ids), overlay);
}
public UnderOverlayMask(Mask mask, boolean overlay) {
this.yMod = overlay ? -1 : 1;
this.mask = mask;
}
@Deprecated
public void addAll(Set<Integer> ids) {
this.ids.addAll(ids);
if (mask instanceof BlockTypeMask) {
BlockTypeMask blockTypeMask = (BlockTypeMask) mask;
for (Integer id : ids) {
blockTypeMask.add(id);
}
} else if (mask instanceof ExistingBlockMask) {
mask = new BlockTypeMask(ids);
}
}
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
mask.prepare(session, player, target);
}
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);
return mask.matches(editSession, pos.add(0, yMod, 0));
}
}