Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make //setbiome respect global mask, if set to a biome mask

  • Loading branch information...
commit 2846119f081cde9ae8a6f406bae064cf6c3932bc 1 parent e7d55ca
@wizjany wizjany authored
View
33 src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java
@@ -19,6 +19,9 @@
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
+import com.sk89q.worldedit.masks.BiomeTypeMask;
+import com.sk89q.worldedit.masks.InvertedMask;
+import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.regions.FlatRegion;
import com.sk89q.worldedit.regions.Region;
@@ -138,10 +141,24 @@ public void setBiome(CommandContext args, LocalSession session, LocalPlayer play
return;
}
+ Mask mask = editSession.getMask();
+ BiomeTypeMask biomeMask = null;
+ boolean inverted = false;
+ if (mask instanceof BiomeTypeMask) {
+ biomeMask = (BiomeTypeMask) mask;
+ } else if (mask instanceof InvertedMask && ((InvertedMask) mask).getInvertedMask() instanceof BiomeTypeMask) {
+ inverted = true;
+ biomeMask = (BiomeTypeMask) ((InvertedMask) mask).getInvertedMask();
+ }
+
if (args.hasFlag('p')) {
Vector2D pos = player.getPosition().toVector2D();
- player.getWorld().setBiome(pos, target);
- player.print("Biome changed to " + target.getName() + " at your current location.");
+ if (biomeMask != null && (biomeMask.matches2D(editSession, pos) ^ inverted)) {
+ player.getWorld().setBiome(pos, target);
+ player.print("Biome changed to " + target.getName() + " at your current location.");
+ } else {
+ player.print("Your global mask doesn't match this biome. Type //gmask to disable it.");
+ }
} else {
int affected = 0;
LocalWorld world = player.getWorld();
@@ -149,16 +166,20 @@ public void setBiome(CommandContext args, LocalSession session, LocalPlayer play
if (region instanceof FlatRegion) {
for (Vector2D pt : ((FlatRegion) region).asFlatRegion()) {
- world.setBiome(pt, target);
- ++affected;
+ if (biomeMask != null && (biomeMask.matches2D(editSession, pt) ^ inverted)) {
+ world.setBiome(pt, target);
+ ++affected;
+ }
}
} else {
HashSet<Long> alreadyVisited = new HashSet<Long>();
for (Vector pt : region) {
if (!alreadyVisited.contains((long)pt.getBlockX() << 32 | pt.getBlockZ())) {
alreadyVisited.add(((long)pt.getBlockX() << 32 | pt.getBlockZ()));
- world.setBiome(pt.toVector2D(), target);
- ++affected;
+ if (biomeMask != null && (biomeMask.matches(editSession, pt) ^ inverted)) {
+ world.setBiome(pt.toVector2D(), target);
+ ++affected;
+ }
}
}
}
View
9 src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java
@@ -8,6 +8,7 @@
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.Vector2D;
public class BiomeTypeMask implements Mask {
@@ -24,9 +25,13 @@ public BiomeTypeMask(Set<BiomeType> biomes) {
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
- public boolean matches(EditSession editSession, Vector pos) {
- BiomeType biome = editSession.getWorld().getBiome(pos.toVector2D());
+ public boolean matches2D(EditSession editSession, Vector2D pos) {
+ BiomeType biome = editSession.getWorld().getBiome(pos);
return biomes.contains(biome);
}
+ public boolean matches(EditSession editSession, Vector pos) {
+ return matches2D(editSession, pos.toVector2D());
+ }
+
}
View
3  src/main/java/com/sk89q/worldedit/masks/InvertedMask.java
@@ -22,4 +22,7 @@ public boolean matches(EditSession editSession, Vector pos) {
return !mask.matches(editSession, pos);
}
+ public Mask getInvertedMask() {
+ return mask;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.