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

Add a dynamic region mask

Dieser Commit ist enthalten in:
aumgn 2012-03-21 10:15:29 +01:00 committet von zml2008
Ursprung 84c1492b3f
Commit eb14efd2df
11 geänderte Dateien mit 80 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -686,6 +686,9 @@ public class LocalSession {
new EditSession(player.isPlayer() ? player.getWorld() : null, new EditSession(player.isPlayer() ? player.getWorld() : null,
getBlockChangeLimit(), blockBag); getBlockChangeLimit(), blockBag);
editSession.setFastMode(fastMode); editSession.setFastMode(fastMode);
if (mask != null) {
mask.prepare(this, player, null);
}
editSession.setMask(mask); editSession.setMask(mask);
return editSession; return editSession;

Datei anzeigen

@ -600,6 +600,10 @@ public class WorldEdit {
case '#': case '#':
if (component.equalsIgnoreCase("#existing")) { if (component.equalsIgnoreCase("#existing")) {
return new ExistingBlockMask(); return new ExistingBlockMask();
} else if (component.equalsIgnoreCase("#dregion")
|| component.equalsIgnoreCase("#dselection")
|| component.equalsIgnoreCase("#dsel")) {
return new DynamicRegionMask();
} else if (component.equalsIgnoreCase("#selection") } else if (component.equalsIgnoreCase("#selection")
|| component.equalsIgnoreCase("#region") || component.equalsIgnoreCase("#region")
|| component.equalsIgnoreCase("#sel")) { || component.equalsIgnoreCase("#sel")) {

Datei anzeigen

@ -5,6 +5,8 @@ import java.util.Set;
import com.sk89q.worldedit.BiomeType; import com.sk89q.worldedit.BiomeType;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
public class BiomeTypeMask implements Mask { public class BiomeTypeMask implements Mask {
@ -19,6 +21,9 @@ public class BiomeTypeMask implements Mask {
this.biomes = biomes; this.biomes = biomes;
} }
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
public boolean matches(EditSession editSession, Vector pos) { public boolean matches(EditSession editSession, Vector pos) {
BiomeType biome = editSession.getWorld().getBiome(pos.toVector2D()); BiomeType biome = editSession.getWorld().getBiome(pos.toVector2D());
return biomes.contains(biome); return biomes.contains(biome);

Datei anzeigen

@ -22,6 +22,8 @@ package com.sk89q.worldedit.masks;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
/** /**
@ -49,6 +51,9 @@ public class BlockTypeMask implements Mask {
types.add(type); types.add(type);
} }
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
public boolean matches(EditSession editSession, Vector pos) { public boolean matches(EditSession editSession, Vector pos) {
return types.contains(editSession.getBlockType(pos)); return types.contains(editSession.getBlockType(pos));
} }

Datei anzeigen

@ -22,6 +22,8 @@ package com.sk89q.worldedit.masks;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
public class CombinedMask implements Mask { public class CombinedMask implements Mask {
@ -51,6 +53,12 @@ public class CombinedMask implements Mask {
return masks.contains(mask); return masks.contains(mask);
} }
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
for (Mask mask : masks) {
mask.prepare(session, player, target);
}
}
public boolean matches(EditSession editSession, Vector pos) { public boolean matches(EditSession editSession, Vector pos) {
for (Mask mask : masks) { for (Mask mask : masks) {
if (!mask.matches(editSession, pos)) { if (!mask.matches(editSession, pos)) {

Datei anzeigen

@ -0,0 +1,26 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
public class DynamicRegionMask implements Mask {
private Region region;
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
try {
region = session.getSelection(player.getWorld());
} catch (IncompleteRegionException exc) {
region = null;
}
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return region == null || region.contains(pos);
}
}

Datei anzeigen

@ -20,10 +20,16 @@
package com.sk89q.worldedit.masks; package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockID;
public class ExistingBlockMask implements Mask { public class ExistingBlockMask implements Mask {
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
public boolean matches(EditSession editSession, Vector pos) { public boolean matches(EditSession editSession, Vector pos) {
return editSession.getBlockType(pos) != BlockID.AIR; return editSession.getBlockType(pos) != BlockID.AIR;
} }

Datei anzeigen

@ -20,6 +20,8 @@
package com.sk89q.worldedit.masks; package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
/** /**
@ -29,6 +31,16 @@ import com.sk89q.worldedit.Vector;
* @author sk89q * @author sk89q
*/ */
public interface Mask { public interface Mask {
/**
* Called one time before each edit session.
*
* @param session
* @param player
* @param target target of the brush, null if not a brush mask
*/
public void prepare(LocalSession session, LocalPlayer player, Vector target);
/** /**
* Given a block position, this method returns true if the block at * Given a block position, this method returns true if the block at
* that position matches the filter. Block information is not provided * that position matches the filter. Block information is not provided

Datei anzeigen

@ -20,6 +20,8 @@
package com.sk89q.worldedit.masks; package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
@ -31,6 +33,9 @@ public class RegionMask implements Mask {
this.region = region.clone(); this.region = region.clone();
} }
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
public boolean matches(EditSession editSession, Vector pos) { public boolean matches(EditSession editSession, Vector pos) {
return region.contains(pos); return region.contains(pos);
} }

Datei anzeigen

@ -23,6 +23,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockID;
@ -44,6 +46,9 @@ public class UnderOverlayMask implements Mask {
this.ids.addAll(ids); this.ids.addAll(ids);
} }
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
public boolean matches(EditSession editSession, Vector pos) { 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();
return ids.isEmpty() ? id != BlockID.AIR : ids.contains(id); return ids.isEmpty() ? id != BlockID.AIR : ids.contains(id);

Datei anzeigen

@ -178,6 +178,7 @@ public class BrushTool implements TraceTool {
EditSession editSession = session.createEditSession(player); EditSession editSession = session.createEditSession(player);
if (mask != null) { if (mask != null) {
mask.prepare(session, player, target);
Mask existingMask = editSession.getMask(); Mask existingMask = editSession.getMask();
if (existingMask == null) { if (existingMask == null) {
editSession.setMask(mask); editSession.setMask(mask);