From 60442354d0581aac0a3eb7cb384b1af0f1132369 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 29 Jan 2011 22:07:56 -0800 Subject: [PATCH] Added block data cycling super pickaxe tool. --- plugin.yml | 5 +- .../sk89q/worldedit/LocalConfiguration.java | 1 + .../worldedit/bukkit/BukkitConfiguration.java | 2 + .../commands/SuperPickaxeCommands.java | 17 +++ .../superpickaxe/BlockDataCyler.java | 107 ++++++++++++++++++ 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 src/com/sk89q/worldedit/superpickaxe/BlockDataCyler.java diff --git a/plugin.yml b/plugin.yml index 825218dd2..09503f6d3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -40,7 +40,7 @@ commands: usage: / searchitem: description: Search for an item - usage: / + usage: / [-bi] aliases: ['/l'] /limit: description: Modify block change limit @@ -194,6 +194,9 @@ commands: repl: description: Block replacer tool usage: / + cycler: + description: Block data cycler tool + usage: / brush: description: Build spheres from far away usage: / [radius] [no-replace?] diff --git a/src/com/sk89q/worldedit/LocalConfiguration.java b/src/com/sk89q/worldedit/LocalConfiguration.java index 10c80b989..370f84ca6 100644 --- a/src/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/com/sk89q/worldedit/LocalConfiguration.java @@ -57,6 +57,7 @@ public abstract class LocalConfiguration { public int navigationWand = 345; public int navigationWandMaxDistance = 50; public int scriptTimeout = 3000; + public Set allowedDataCycleBlocks = new HashSet(); public String saveDir = "schematics"; public String scriptsDir = "craftscripts"; diff --git a/src/com/sk89q/worldedit/bukkit/BukkitConfiguration.java b/src/com/sk89q/worldedit/bukkit/BukkitConfiguration.java index ffd9efe6c..2b59c7008 100644 --- a/src/com/sk89q/worldedit/bukkit/BukkitConfiguration.java +++ b/src/com/sk89q/worldedit/bukkit/BukkitConfiguration.java @@ -72,6 +72,8 @@ public class BukkitConfiguration extends LocalConfiguration { disallowedBlocks = new HashSet(config.getIntList("limits.disallowed-blocks", null)); + allowedDataCycleBlocks = new HashSet(config.getIntList("limits.allowed-data-cycle-blocks", null)); + String snapshotsDir = config.getString("snapshots.directory", ""); if (!snapshotsDir.trim().equals("")) { snapshotRepo = new SnapshotRepository(snapshotsDir); diff --git a/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java b/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java index 562324557..f3f8bdc4d 100644 --- a/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java +++ b/src/com/sk89q/worldedit/commands/SuperPickaxeCommands.java @@ -219,6 +219,23 @@ public class SuperPickaxeCommands { player.print("Block replacer tool equipped. Right click with a pickaxe."); } + @Command( + aliases = {"cycler"}, + usage = "", + desc = "Block data cycler tool", + min = 0, + max = 0 + ) + @CommandPermissions({"worldedit.superpickaxe.data-cycler"}) + public static void cycler(CommandContext args, WorldEdit we, + LocalSession session, LocalPlayer player, EditSession editSession) + throws WorldEditException { + + session.setArmSwingMode(null); + session.setRightClickMode(new BlockDataCyler()); + player.print("Block cycler tool equipped. Right click with a pickaxe."); + } + @Command( aliases = {"brush"}, usage = " [radius] [no-replace?]", diff --git a/src/com/sk89q/worldedit/superpickaxe/BlockDataCyler.java b/src/com/sk89q/worldedit/superpickaxe/BlockDataCyler.java new file mode 100644 index 000000000..11bcb5411 --- /dev/null +++ b/src/com/sk89q/worldedit/superpickaxe/BlockDataCyler.java @@ -0,0 +1,107 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.superpickaxe; + +import com.sk89q.worldedit.*; +import com.sk89q.worldedit.blocks.BlockID; + +/** + * A mode that cycles the data values of supported blocks. + * + * @author sk89q + */ +public class BlockDataCyler implements SuperPickaxeMode { + @Override + public boolean act(ServerInterface server, LocalConfiguration config, + LocalPlayer player, LocalSession session, WorldVector clicked) { + + LocalWorld world = clicked.getWorld(); + + int type = world.getBlockType(clicked); + int data = world.getBlockData(clicked); + + if (config.allowedDataCycleBlocks.size() > 0 + && !player.hasPermission("worldedit.superpickaxe.data-cycler.any") + && !config.allowedDataCycleBlocks.contains(type)) { + player.printError("You are not permitted to cycle the data value of that block."); + return true; + } + + if (type == BlockID.LOG) { + data = (data + 1) % 3; + } else if (type == BlockID.LEAVES) { + data = (data + 1) % 3; + } else if (type == BlockID.CACTUS) { + data = (data + 1) % 16; + } else if (type == BlockID.SOIL) { + data = (data + 1) % 9; + } else if (type == BlockID.CROPS) { + data = (data + 1) % 6; + } else if (type == BlockID.MINECART_TRACKS) { + if (data >= 6 && data <= 9) { + data = (data + 1) % 4 + 6; + } else { + player.printError("This minecart track orientation is not supported."); + return true; + } + } else if (type == BlockID.WOODEN_STAIRS || type == BlockID.COBBLESTONE_STAIRS) { + data = (data + 1) % 4; + } else if (type == BlockID.SIGN_POST) { + data = (data + 1) % 16; + } else if (type == BlockID.FURNACE || type == BlockID.BURNING_FURNACE + || type == BlockID.DISPENSER) { + data = (data + 1) % 4 + 2; + } else if (type == BlockID.PUMPKIN || type == BlockID.JACKOLANTERN) { + data = (data + 1) % 4; + } else if (type == BlockID.CLOTH) { + data = nextClothColor(data); + } else { + player.printError("That block's data cannot be cycled."); + return true; + } + + world.setBlockData(clicked, data); + + return true; + } + + private static int nextClothColor(int data) { + switch (data) { + case 0: return 8; + case 8: return 7; + case 7: return 15; + case 15: return 12; + case 12: return 14; + case 14: return 1; + case 1: return 4; + case 4: return 5; + case 5: return 13; + case 13: return 9; + case 9: return 3; + case 3: return 11; + case 11: return 10; + case 10: return 2; + case 2: return 6; + case 6: return 0; + } + + return 0; + } +}