From 2846119f081cde9ae8a6f406bae064cf6c3932bc Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 28 Mar 2013 19:53:42 -0400 Subject: [PATCH] Make //setbiome respect global mask, if set to a biome mask --- .../worldedit/commands/BiomeCommands.java | 33 +++++++++++++++---- .../sk89q/worldedit/masks/BiomeTypeMask.java | 9 +++-- .../sk89q/worldedit/masks/InvertedMask.java | 3 ++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java b/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java index 8783d1286..fa5004110 100644 --- a/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java @@ -19,6 +19,9 @@ import com.sk89q.worldedit.Vector; 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 class BiomeCommands { 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 class BiomeCommands { 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 alreadyVisited = new HashSet(); 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; + } } } } diff --git a/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java index c25621f17..ea448cbcf 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java @@ -8,6 +8,7 @@ import com.sk89q.worldedit.EditSession; 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 class BiomeTypeMask implements Mask { 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()); + } + } diff --git a/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java b/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java index 6f4c6c99c..d4c222551 100644 --- a/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java @@ -22,4 +22,7 @@ public class InvertedMask implements Mask { return !mask.matches(editSession, pos); } + public Mask getInvertedMask() { + return mask; + } }