diff --git a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java index bbe319749..d35db279a 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java @@ -90,21 +90,37 @@ public class BaseBlock { * @return if air */ public boolean isAir() { - return type == 0; + return type == BlockID.AIR; } /** * Rotate this block 90 degrees. */ - public void rotate90() { - data = (byte) BlockData.rotate90(type, data); + public int rotate90() { + int newData = BlockData.rotate90(type, data); + this.data = (byte) newData; + return data; } /** * Rotate this block -90 degrees. */ - public void rotate90Reverse() { - data = (byte) BlockData.rotate90Reverse(type, data); + public int rotate90Reverse() { + int newData = BlockData.rotate90Reverse(type, data); + this.data = (byte) newData; + return newData; + } + + /** + * Cycle the damage value of the block forward or backward + * + * @param increment 1 for forward, -1 for backward + * @return new data value + */ + public int cycleData(int increment) { + int newData = BlockData.cycle(this.type, this.data, increment); + this.data = (byte) newData; + return newData; } /** @@ -135,7 +151,7 @@ public class BaseBlock { @Override public int hashCode() { int ret = type << 3; - if (data != (byte)-1) ret |= data; + if (data != (byte) -1) ret |= data; return ret; } diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockData.java b/src/main/java/com/sk89q/worldedit/blocks/BlockData.java index 3ca16d50a..a199d2f87 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BlockData.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BlockData.java @@ -110,6 +110,7 @@ public final class BlockData { case BlockID.LADDER: case BlockID.WALL_SIGN: + case BlockID.CHEST: case BlockID.FURNACE: case BlockID.BURNING_FURNACE: case BlockID.DISPENSER: @@ -268,6 +269,7 @@ public final class BlockData { case BlockID.LADDER: case BlockID.WALL_SIGN: + case BlockID.CHEST: case BlockID.FURNACE: case BlockID.BURNING_FURNACE: case BlockID.DISPENSER: @@ -453,6 +455,7 @@ public final class BlockData { case BlockID.LADDER: case BlockID.WALL_SIGN: + case BlockID.CHEST: case BlockID.FURNACE: case BlockID.BURNING_FURNACE: case BlockID.DISPENSER: diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java index 1ddc98461..ad917b237 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java @@ -397,7 +397,6 @@ public enum BlockType { usesData.add(BlockID.LOG); usesData.add(BlockID.LEAVES); usesData.add(BlockID.DISPENSER); - usesData.add(BlockID.NOTE_BLOCK); usesData.add(BlockID.BED); usesData.add(BlockID.POWERED_RAIL); usesData.add(BlockID.DETECTOR_RAIL); @@ -409,7 +408,9 @@ public enum BlockType { usesData.add(BlockID.DOUBLE_STEP); usesData.add(BlockID.STEP); usesData.add(BlockID.TORCH); + usesData.add(BlockID.FIRE); usesData.add(BlockID.WOODEN_STAIRS); + usesData.add(BlockID.CHEST); usesData.add(BlockID.REDSTONE_WIRE); usesData.add(BlockID.CROPS); usesData.add(BlockID.SOIL); @@ -430,6 +431,8 @@ public enum BlockType { usesData.add(BlockID.STONE_BUTTON); usesData.add(BlockID.SNOW); usesData.add(BlockID.CACTUS); + usesData.add(BlockID.REED); + usesData.add(BlockID.JUKEBOX); usesData.add(BlockID.PUMPKIN); usesData.add(BlockID.JACKOLANTERN); usesData.add(BlockID.CAKE_BLOCK); @@ -880,9 +883,9 @@ public enum BlockType { nonDataAttachments.put(BlockID.LONG_GRASS, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.DEAD_BUSH, PlayerDirection.DOWN); for (int offset = 0; offset <= 8; offset += 8) { - dataAttachments.put(attachmentKey(BlockID.PISTON_EXTENSION, offset+0), PlayerDirection.UP); - dataAttachments.put(attachmentKey(BlockID.PISTON_EXTENSION, offset+1), PlayerDirection.DOWN); - addCardinals(BlockID.PISTON_EXTENSION, offset+2, offset+5, offset+3, offset+4); + dataAttachments.put(attachmentKey(BlockID.PISTON_EXTENSION, offset + 0), PlayerDirection.UP); + dataAttachments.put(attachmentKey(BlockID.PISTON_EXTENSION, offset + 1), PlayerDirection.DOWN); + addCardinals(BlockID.PISTON_EXTENSION, offset + 2, offset + 5, offset + 3, offset + 4); } nonDataAttachments.put(BlockID.YELLOW_FLOWER, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.RED_FLOWER, PlayerDirection.DOWN); @@ -900,16 +903,16 @@ public enum BlockType { nonDataAttachments.put(BlockID.MINECART_TRACKS, PlayerDirection.DOWN); addCardinals(BlockID.WALL_SIGN, 2, 5, 3, 4); for (int offset = 0; offset <= 8; offset += 8) { - addCardinals(BlockID.LEVER, offset+4, offset+1, offset+3, offset+2); - dataAttachments.put(attachmentKey(BlockID.LEVER, offset+5), PlayerDirection.DOWN); - dataAttachments.put(attachmentKey(BlockID.LEVER, offset+6), PlayerDirection.DOWN); + addCardinals(BlockID.LEVER, offset + 4, offset + 1, offset + 3, offset + 2); + dataAttachments.put(attachmentKey(BlockID.LEVER, offset + 5), PlayerDirection.DOWN); + dataAttachments.put(attachmentKey(BlockID.LEVER, offset + 6), PlayerDirection.DOWN); } nonDataAttachments.put(BlockID.STONE_PRESSURE_PLATE, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.IRON_DOOR, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.WOODEN_PRESSURE_PLATE, PlayerDirection.DOWN); // redstone torches: see torches for (int offset = 0; offset <= 8; offset += 8) { - addCardinals(BlockID.STONE_BUTTON, offset+4, offset+1, offset+3, offset+2); + addCardinals(BlockID.STONE_BUTTON, offset + 4, offset + 1, offset + 3, offset + 2); } nonDataAttachments.put(BlockID.CACTUS, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.REED, PlayerDirection.DOWN); @@ -917,7 +920,7 @@ public enum BlockType { nonDataAttachments.put(BlockID.REDSTONE_REPEATER_OFF, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.REDSTONE_REPEATER_ON, PlayerDirection.DOWN); for (int offset = 0; offset <= 4; offset += 4) { - addCardinals(BlockID.TRAP_DOOR, offset+0, offset+3, offset+1, offset+2); + addCardinals(BlockID.TRAP_DOOR, offset + 0, offset + 3, offset + 1, offset + 2); } nonDataAttachments.put(BlockID.PUMPKIN_STEM, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.MELON_STEM, PlayerDirection.DOWN); diff --git a/src/main/java/com/sk89q/worldedit/tools/BlockDataCyler.java b/src/main/java/com/sk89q/worldedit/tools/BlockDataCyler.java index dcec4858a..9761e02b4 100644 --- a/src/main/java/com/sk89q/worldedit/tools/BlockDataCyler.java +++ b/src/main/java/com/sk89q/worldedit/tools/BlockDataCyler.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.tools; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BlockData; +import com.sk89q.worldedit.blocks.BaseBlock; /** * A mode that cycles the data values of supported blocks. @@ -28,37 +28,38 @@ import com.sk89q.worldedit.blocks.BlockData; * @author sk89q */ public class BlockDataCyler implements DoubleActionBlockTool { - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.tool.data-cycler"); } - + private boolean handleCycle(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked, boolean forward) { - + LocalWorld world = clicked.getWorld(); - + int type = world.getBlockType(clicked); int data = world.getBlockData(clicked); - + if (config.allowedDataCycleBlocks.size() > 0 && !player.hasPermission("worldedit.override.data-cycler") && !config.allowedDataCycleBlocks.contains(type)) { player.printError("You are not permitted to cycle the data value of that block."); return true; } - + int increment = forward ? 1 : -1; - data = BlockData.cycle(type, data, increment); + data = (new BaseBlock(type, data)).cycleData(increment); + if (data < 0) { player.printError("That block's data cannot be cycled!"); - return true; + } else { + world.setBlockData(clicked, data); } - world.setBlockData(clicked, data); - + return true; } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { return handleCycle(server, config, player, session, clicked, true);