From 34c366d852af91bf6dc8de14f58c2b9968025686 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Tue, 20 Mar 2012 23:40:35 -0700 Subject: [PATCH] Added a command to set biomes. Currently requires a relog for the changes to be visible clientside and is not preserved between chunk regenerations --- .../worldedit/commands/BiomeCommands.java | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java b/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java index 727d6f5f8..c7f49c4ba 100644 --- a/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/BiomeCommands.java @@ -31,7 +31,6 @@ public class BiomeCommands { aliases = { "biomelist", "biomels" }, usage = "[page]", desc = "Gets all biomes available.", - min = 0, max = 1 ) @CommandPermissions("worldedit.biome.list") @@ -66,22 +65,20 @@ public class BiomeCommands { @Command( aliases = { "biomeinfo" }, - usage = "", - flags = "ts", + flags = "pt", desc = "Get the biome of the targeted block.", help = "Get the biome of the block.\n" + - "By default use the block you are currently in.\n" + + "By default use all the blocks contained in your selection.\n" + "-t use the block you are looking at.\n" + - "-s use all the blocks contained in your selection", - min = 0, + "-p use the block you are currently in", max = 0 ) @CommandPermissions("worldedit.biome.info") public void biomeInfo(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - if (args.hasFlag('s')) { + if (!args.hasFlag('l')) { LocalWorld world = player.getWorld(); Region region = session.getSelection(world); Set biomes = new HashSet(); @@ -116,4 +113,50 @@ public class BiomeCommands { player.print("Biome: " + biome.getName()); } } + + @Command( + aliases = { "/setbiome" }, + usage = "", + flags = "p", + desc = "Sets the biome of the player's current block or region.", + help = + "Set the biome of the region.\n" + + "By default use all the blocks contained in your selection.\n" + + "-p use the block you are currently in", + min = 1, + max = 1 + ) + @CommandPermissions("worldedit.biome.set") + public void setBiome(CommandContext args, LocalSession session, LocalPlayer player, + EditSession editSession) throws WorldEditException { + + final BiomeType target = we.getServer().getBiomes().get(args.getString(0)); + if (!args.hasFlag('l')) { + int affected = 0; + LocalWorld world = player.getWorld(); + Region region = session.getSelection(world); + + if (region instanceof FlatRegion) { + for (Vector2D pt : ((FlatRegion) region).asFlatRegion()) { + world.setBiome(pt, target); + ++affected; + } + } else { + HashSet alreadyVisited = new HashSet(); + for (Vector pt : region) { + if (!alreadyVisited.contains((long)pt.getBlockX() << 32 | pt.getBlockZ() & 0xFFFFFFFFL)) { + alreadyVisited.add(((long)pt.getBlockX() << 32 | pt.getBlockZ() & 0xFFFFFFFFL)); + world.setBiome(pt.toVector2D(), target); + ++affected; + } + } + } + + player.print("Biome changed to " + target.getName() + ". " + affected + " columns affected."); + } else { + Vector2D pos = player.getPosition().toVector2D(); + player.getWorld().setBiome(pos, target); + player.print("Biome changed to " + target.getName() + " at your current location."); + } + } }