From e0e7778536e5190dce9d3b8a185bad187d76a05c Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 13 Aug 2018 22:18:12 +1000 Subject: [PATCH] Fixed some bugs and cleanup some code. --- .../worldedit/blocks/MobSpawnerBlock.java | 2 +- .../com/sk89q/worldedit/blocks/SignBlock.java | 2 +- .../sk89q/worldedit/blocks/SkullBlock.java | 2 +- .../com/sk89q/util/yaml/YAMLProcessor.java | 17 +- .../com/sk89q/worldedit/blocks/BlockID.java | 92 ---------- .../com/sk89q/worldedit/blocks/BlockType.java | 158 ------------------ .../sk89q/worldedit/command/ToolCommands.java | 50 ++---- .../worldedit/command/tool/BlockReplacer.java | 21 ++- .../command/tool/LongRangeBuildTool.java | 13 +- .../worldedit/extent/inventory/BlockBag.java | 26 +-- .../extent/reorder/MultiStageReorder.java | 19 +-- .../sk89q/worldedit/registry/Category.java | 5 + .../worldedit/world/block/BlockType.java | 5 + .../worldedit/world/entity/EntityType.java | 5 + .../worldedit/world/fluid/FluidType.java | 5 + .../worldedit/world/gamemode/GameMode.java | 5 + .../sk89q/worldedit/world/item/ItemType.java | 5 + .../worldedit/world/weather/WeatherType.java | 5 + .../com/sk89q/worldedit/forge/ForgeWorld.java | 2 +- .../worldedit/forge/TileEntityBaseBlock.java | 40 ----- .../worldedit/forge/TileEntityUtils.java | 5 + worldedit-forge/src/main/resources/mcmod.info | 2 +- 22 files changed, 92 insertions(+), 394 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java delete mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java index 0d175e974..c74c8f382 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java @@ -35,7 +35,7 @@ import java.util.Map; /** * A mob spawner block. */ -public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock { +public class MobSpawnerBlock extends BaseBlock { private String mobType; private short delay; diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java index e11330faa..4cc0e5bcb 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java @@ -32,7 +32,7 @@ import java.util.Map; /** * Represents a sign block. */ -public class SignBlock extends BaseBlock implements TileEntityBlock { +public class SignBlock extends BaseBlock { private String[] text; diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java index 4ecddddc2..e65ab3ec1 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SkullBlock.java @@ -31,7 +31,7 @@ import java.util.Map; /** * A skull block. */ -public class SkullBlock extends BaseBlock implements TileEntityBlock { +public class SkullBlock extends BaseBlock { private String owner = ""; // notchian diff --git a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java index 45ffd8776..48eb06e69 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java +++ b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java @@ -23,7 +23,6 @@ import com.sk89q.util.StringUtil; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; -import org.yaml.snakeyaml.emitter.ScalarAnalysis; import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.reader.UnicodeReader; import org.yaml.snakeyaml.representer.Representer; @@ -90,7 +89,7 @@ public class YAMLProcessor extends YAMLNode { super(new LinkedHashMap<>(), writeDefaults); this.format = format; - DumperOptions options = new FancyDumperOptions(); + DumperOptions options = new DumperOptions(); options.setIndent(4); options.setDefaultFlowStyle(format.getStyle()); Representer representer = new FancyRepresenter(); @@ -296,20 +295,6 @@ public class YAMLProcessor extends YAMLNode { return new YAMLNode(new LinkedHashMap<>(), writeDefaults); } - // This will be included in snakeyaml 1.10, but until then we have to do it manually. - private class FancyDumperOptions extends DumperOptions { - @Override - public DumperOptions.ScalarStyle calculateScalarStyle(ScalarAnalysis analysis, - DumperOptions.ScalarStyle style) { - if (format == YAMLFormat.EXTENDED - && (analysis.scalar.contains("\n") || analysis.scalar.contains("\r"))) { - return ScalarStyle.LITERAL; - } else { - return super.calculateScalarStyle(analysis, style); - } - } - } - private static class FancyRepresenter extends Representer { private FancyRepresenter() { this.nullRepresenter = o -> representScalar(Tag.NULL, ""); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java deleted file mode 100644 index 0e0fd917d..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser 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 Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.blocks; - -import com.sk89q.worldedit.world.block.BlockTypes; - -/** - * List of block IDs. - * - * {@deprecated Please use {@link BlockTypes }} - */ -@Deprecated -public final class BlockID { - static final int SAPLING = 6; - static final int POWERED_RAIL = 27; // GOLDEN_RAIL - static final int DETECTOR_RAIL = 28; - static final int LONG_GRASS = 31; // TALLGRASS - static final int DEAD_BUSH = 32; // DEADBUSH - static final int PISTON_EXTENSION = 34; // PISTON_HEAD - static final int YELLOW_FLOWER = 37; - static final int RED_FLOWER = 38; - static final int BROWN_MUSHROOM = 39; - static final int RED_MUSHROOM = 40; - static final int TORCH = 50; - static final int REDSTONE_WIRE = 55; - static final int CROPS = 59; // WHEAT - static final int SIGN_POST = 63; // STANDING_SIGN - static final int WOODEN_DOOR = 64; // WOODEN_DOOR - static final int LADDER = 65; - static final int MINECART_TRACKS = 66; // RAIL - static final int WALL_SIGN = 68; - static final int LEVER = 69; - static final int STONE_PRESSURE_PLATE = 70; - static final int IRON_DOOR = 71; - static final int WOODEN_PRESSURE_PLATE = 72; - static final int REDSTONE_TORCH_OFF = 75; // UNLIT_REDSTONE_TORCH - static final int REDSTONE_TORCH_ON = 76; // LIT_REDSTONE_TORCH - static final int STONE_BUTTON = 77; - static final int CACTUS = 81; - static final int REED = 83; // REEDS - static final int CAKE_BLOCK = 92; // CAKE - static final int REDSTONE_REPEATER_OFF = 93; // UNPOWERED_REPEATER - static final int REDSTONE_REPEATER_ON = 94; // POWERED_REPEATER - static final int TRAP_DOOR = 96; // TRAPDOOR - static final int PUMPKIN_STEM = 104; - static final int MELON_STEM = 105; - static final int VINE = 106; - static final int NETHER_WART = 115; - static final int COCOA_PLANT = 127; // COCOA - static final int TRIPWIRE_HOOK = 131; - static final int TRIPWIRE = 132; - static final int FLOWER_POT = 140; - static final int CARROTS = 141; - static final int POTATOES = 142; - static final int WOODEN_BUTTON = 143; - static final int ANVIL = 145; - static final int PRESSURE_PLATE_LIGHT = 147; // LIGHT_WEIGHTED_PRESSURE_PLATE - static final int PRESSURE_PLATE_HEAVY = 148; // HEAVY_WEIGHTED_PRESSURE_PLATE - static final int COMPARATOR_OFF = 149; // UNPOWERED_COMPARATOR - static final int COMPARATOR_ON = 150; // COMPARATOR - static final int ACTIVATOR_RAIL = 157; - static final int IRON_TRAP_DOOR = 167; - static final int CARPET = 171; - static final int DOUBLE_PLANT = 175; - static final int STANDING_BANNER = 176; - static final int WALL_BANNER = 177; - static final int SPRUCE_DOOR = 193; - static final int BIRCH_DOOR = 194; - static final int JUNGLE_DOOR = 195; - static final int ACACIA_DOOR = 196; - static final int DARK_OAK_DOOR = 197; - - private BlockID() { - } -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java deleted file mode 100644 index d21635cf5..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser 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 Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.blocks; - -import com.sk89q.worldedit.PlayerDirection; - -import java.util.HashMap; -import java.util.Map; - -/** - * Block types. - * - * {@deprecated Please use {@link com.sk89q.worldedit.world.block.BlockType }} - */ -@Deprecated -public enum BlockType { - - ; - - private static final Map dataAttachments = new HashMap<>(); - private static final Map nonDataAttachments = new HashMap<>(); - static { - nonDataAttachments.put(BlockID.SAPLING, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.LONG_GRASS, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.DEAD_BUSH, PlayerDirection.DOWN); - for (int offset = 0; offset < 16; offset += 8) { - dataAttachments.put(typeDataKey(BlockID.PISTON_EXTENSION, offset + 0), PlayerDirection.UP); - dataAttachments.put(typeDataKey(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); - nonDataAttachments.put(BlockID.BROWN_MUSHROOM, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.RED_MUSHROOM, PlayerDirection.DOWN); - for (int blockId : new int[] { BlockID.TORCH, BlockID.REDSTONE_TORCH_ON, BlockID.REDSTONE_TORCH_OFF }) { - dataAttachments.put(typeDataKey(blockId, 0), PlayerDirection.DOWN); - dataAttachments.put(typeDataKey(blockId, 5), PlayerDirection.DOWN); // According to the minecraft wiki, this one is history. Keeping both, for now... - addCardinals(blockId, 4, 1, 3, 2); - } - nonDataAttachments.put(BlockID.REDSTONE_WIRE, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.CROPS, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.SIGN_POST, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.WOODEN_DOOR, PlayerDirection.DOWN); - addCardinals(BlockID.LADDER, 2, 5, 3, 4); - addCardinals(BlockID.WALL_SIGN, 2, 5, 3, 4); - for (int offset = 0; offset < 16; offset += 8) { - addCardinals(BlockID.LEVER, offset + 4, offset + 1, offset + 3, offset + 2); - dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 5), PlayerDirection.DOWN); - dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 6), PlayerDirection.DOWN); - dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 7), PlayerDirection.UP); - dataAttachments.put(typeDataKey(BlockID.LEVER, offset + 0), PlayerDirection.UP); - } - 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 < 16; offset += 8) { - addCardinals(BlockID.STONE_BUTTON, offset + 4, offset + 1, offset + 3, offset + 2); - addCardinals(BlockID.WOODEN_BUTTON, offset + 4, offset + 1, offset + 3, offset + 2); - } - dataAttachments.put(typeDataKey(BlockID.STONE_BUTTON, 0), PlayerDirection.UP); - dataAttachments.put(typeDataKey(BlockID.STONE_BUTTON, 5), PlayerDirection.DOWN); - dataAttachments.put(typeDataKey(BlockID.WOODEN_BUTTON, 0), PlayerDirection.UP); - dataAttachments.put(typeDataKey(BlockID.WOODEN_BUTTON, 5), PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.CACTUS, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.REED, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.CAKE_BLOCK, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.REDSTONE_REPEATER_OFF, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.REDSTONE_REPEATER_ON, PlayerDirection.DOWN); - for (int offset = 0; offset < 16; offset += 4) { - addCardinals(BlockID.TRAP_DOOR, offset + 0, offset + 3, offset + 1, offset + 2); - addCardinals(BlockID.IRON_TRAP_DOOR, offset + 0, offset + 3, offset + 1, offset + 2); - } - nonDataAttachments.put(BlockID.PUMPKIN_STEM, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.MELON_STEM, PlayerDirection.DOWN); - // vines are complicated, but I'll list the single-attachment variants anyway - dataAttachments.put(typeDataKey(BlockID.VINE, 0), PlayerDirection.UP); - addCardinals(BlockID.VINE, 1, 2, 4, 8); - nonDataAttachments.put(BlockID.NETHER_WART, PlayerDirection.DOWN); - for (int offset = 0; offset < 16; offset += 4) { - addCardinals(BlockID.COCOA_PLANT, offset + 0, offset + 1, offset + 2, offset + 3); - } - for (int offset = 0; offset < 16; offset += 4) { - addCardinals(BlockID.TRIPWIRE_HOOK, offset + 2, offset + 3, offset + 0, offset + 1); - } - nonDataAttachments.put(BlockID.TRIPWIRE, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.FLOWER_POT, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.CARROTS, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.POTATOES, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.ANVIL, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.PRESSURE_PLATE_LIGHT, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.PRESSURE_PLATE_HEAVY, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.COMPARATOR_OFF, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.COMPARATOR_ON, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.CARPET, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.DOUBLE_PLANT, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.STANDING_BANNER, PlayerDirection.DOWN); - addCardinals(BlockID.WALL_BANNER, 4, 2, 5, 3); - nonDataAttachments.put(BlockID.SPRUCE_DOOR, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.BIRCH_DOOR, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.JUNGLE_DOOR, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.ACACIA_DOOR, PlayerDirection.DOWN); - nonDataAttachments.put(BlockID.DARK_OAK_DOOR, PlayerDirection.DOWN); - - // Rails are hardcoded to be attached to the block below them. - // In addition to that, let's attach ascending rails to the block they're ascending towards. - for (int offset = 0; offset < 16; offset += 8) { - addCardinals(BlockID.POWERED_RAIL, offset + 3, offset + 4, offset + 2, offset + 5); - addCardinals(BlockID.DETECTOR_RAIL, offset + 3, offset + 4, offset + 2, offset + 5); - addCardinals(BlockID.MINECART_TRACKS, offset + 3, offset + 4, offset + 2, offset + 5); - addCardinals(BlockID.ACTIVATOR_RAIL, offset + 3, offset + 4, offset + 2, offset + 5); - } - } - - /** - * Returns the direction to the block(B) this block(A) is attached to. - * Attached means that if block B is destroyed, block A will pop off. - * - * @param type the block id of block A - * @param data the data value of block A - * @return direction to block B - */ - public static PlayerDirection getAttachment(int type, int data) { - PlayerDirection direction = nonDataAttachments.get(type); - if (direction != null) return direction; - - return dataAttachments.get(typeDataKey(type, data)); - } - - private static int typeDataKey(int type, int data) { - return (type << 4) | (data & 0xf); - } - - private static void addCardinals(int type, int west, int north, int east, int south) { - dataAttachments.put(typeDataKey(type, west), PlayerDirection.WEST); - dataAttachments.put(typeDataKey(type, north), PlayerDirection.NORTH); - dataAttachments.put(typeDataKey(type, east), PlayerDirection.EAST); - dataAttachments.put(typeDataKey(type, south), PlayerDirection.SOUTH); - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java index 7b80fbd73..0391e0bf2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java @@ -37,11 +37,10 @@ import com.sk89q.worldedit.command.tool.LongRangeBuildTool; import com.sk89q.worldedit.command.tool.QueryTool; import com.sk89q.worldedit.command.tool.TreePlanter; import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.TreeGenerator; -import com.sk89q.worldedit.world.block.BlockStateHolder; public class ToolCommands { private final WorldEdit we; @@ -111,18 +110,9 @@ public class ToolCommands { max = 1 ) @CommandPermissions("worldedit.tool.replacer") - public void repl(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - - ParserContext context = new ParserContext(); - context.setActor(player); - context.setWorld(player.getWorld()); - context.setSession(session); - context.setRestricted(true); - context.setPreferringWildcard(false); - - BlockStateHolder targetBlock = we.getBlockFactory().parseFromInput(args.getString(0), context); + public void repl(Player player, LocalSession session, Pattern pattern) throws WorldEditException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); - session.setTool(itemStack.getType(), new BlockReplacer(targetBlock)); + session.setTool(itemStack.getType(), new BlockReplacer(pattern)); player.print("Block replacer tool bound to " + itemStack.getType().getName() + "."); } @@ -149,22 +139,15 @@ public class ToolCommands { max = 2 ) @CommandPermissions("worldedit.tool.flood-fill") - public void floodFill(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + public void floodFill(Player player, LocalSession session, Pattern pattern, int range) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); - int range = args.getInteger(1); if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; } - ParserContext context = new ParserContext(); - context.setActor(player); - context.setWorld(player.getWorld()); - context.setSession(session); - Pattern pattern = we.getPatternFactory().parseFromInput(args.getString(0), context); - BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new FloodFillTool(range, pattern)); player.print("Block flood fill tool bound to " + itemStack.getType().getName() + "."); @@ -209,23 +192,20 @@ public class ToolCommands { max = 2 ) @CommandPermissions("worldedit.tool.lrbuild") - public void longrangebuildtool(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - - ParserContext context = new ParserContext(); - context.setActor(player); - context.setWorld(player.getWorld()); - context.setSession(session); - context.setRestricted(true); - context.setPreferringWildcard(false); - - BlockStateHolder secondary = we.getBlockFactory().parseFromInput(args.getString(0), context); - BlockStateHolder primary = we.getBlockFactory().parseFromInput(args.getString(1), context); - + public void longrangebuildtool(Player player, LocalSession session, Pattern secondary, Pattern primary) throws WorldEditException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new LongRangeBuildTool(primary, secondary)); player.print("Long-range building tool bound to " + itemStack.getType().getName() + "."); - player.print("Left-click set to " + secondary.getBlockType().getName() + "; right-click set to " - + primary.getBlockType().getName() + "."); + String primaryName = "pattern"; + String secondaryName = "pattern"; + if (primary instanceof BlockPattern) { + primaryName = ((BlockPattern) primary).getBlock().getBlockType().getName(); + } + if (secondary instanceof BlockPattern) { + secondaryName = ((BlockPattern) secondary).getBlock().getBlockType().getName(); + } + player.print("Left-click set to " + secondaryName + "; right-click set to " + + primaryName + "."); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java index 9d0b9c9fc..1388b66ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java @@ -23,22 +23,24 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.function.pattern.BlockPattern; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockType; /** * A mode that replaces one block. */ public class BlockReplacer implements DoubleActionBlockTool { - private BlockStateHolder targetBlock; + private Pattern pattern; - public BlockReplacer(BlockStateHolder targetBlock) { - this.targetBlock = targetBlock; + public BlockReplacer(Pattern pattern) { + this.pattern = pattern; } @Override @@ -53,7 +55,8 @@ public class BlockReplacer implements DoubleActionBlockTool { EditSession editSession = session.createEditSession(player); try { - editSession.setBlock(clicked.toVector(), targetBlock); + Vector position = clicked.toVector(); + editSession.setBlock(position, pattern.apply(position)); } catch (MaxChangedBlocksException ignored) { } finally { if (bag != null) { @@ -69,11 +72,11 @@ public class BlockReplacer implements DoubleActionBlockTool { @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { EditSession editSession = session.createEditSession(player); - targetBlock = (editSession).getBlock(clicked.toVector()); - BlockType type = targetBlock.getBlockType(); + BlockStateHolder targetBlock = editSession.getBlock(clicked.toVector()); - if (type != null) { - player.print("Replacer tool switched to: " + type.getName()); + if (targetBlock != null) { + pattern = new BlockPattern(targetBlock); + player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName()); } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java index 908ec5325..af20ea56d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -35,10 +36,10 @@ import com.sk89q.worldedit.world.block.BlockTypes; */ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTool { - private BlockStateHolder primary; - private BlockStateHolder secondary; + private Pattern primary; + private Pattern secondary; - public LongRangeBuildTool(BlockStateHolder primary, BlockStateHolder secondary) { + public LongRangeBuildTool(Pattern secondary, Pattern primary) { super("worldedit.tool.lrbuild"); this.primary = primary; this.secondary = secondary; @@ -55,7 +56,8 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo if (pos == null) return false; EditSession eS = session.createEditSession(player); try { - if (secondary.getBlockType() == BlockTypes.AIR) { + BlockStateHolder applied = secondary.apply(pos.toVector()); + if (applied.getBlockType() == BlockTypes.AIR) { eS.setBlock(pos.toVector(), secondary); } else { eS.setBlock(pos.getDirection(), secondary); @@ -74,7 +76,8 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo if (pos == null) return false; EditSession eS = session.createEditSession(player); try { - if (primary.getBlockType() == BlockTypes.AIR) { + BlockStateHolder applied = primary.apply(pos.toVector()); + if (applied.getBlockType() == BlockTypes.AIR) { eS.setBlock(pos.toVector(), primary); } else { eS.setBlock(pos.getDirection(), primary); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java index d55771266..c779f833d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java @@ -51,29 +51,9 @@ public abstract class BlockBag { public void fetchPlacedBlock(BlockState blockState) throws BlockBagException { try { // Blocks that can't be fetched... -// TODO switch (id) { -// case BlockID.BEDROCK: -// case BlockID.GOLD_ORE: -// case BlockID.IRON_ORE: -// case BlockID.COAL_ORE: -// case BlockID.DIAMOND_ORE: -// case BlockID.TNT: -// case BlockID.MOB_SPAWNER: -// case BlockID.CROPS: -// case BlockID.REDSTONE_ORE: -// case BlockID.GLOWING_REDSTONE_ORE: -// case BlockID.SNOW: -// case BlockID.LIGHTSTONE: -// case BlockID.PORTAL: -// throw new UnplaceableBlockException(); -// -// case BlockID.WATER: -// case BlockID.STATIONARY_WATER: -// case BlockID.LAVA: -// case BlockID.STATIONARY_LAVA: -// // Override liquids -// return; -// } + if (blockState.getBlockType().getMaterial().isReplacedDuringPlacement()) { + return; + } fetchBlock(blockState); } catch (OutOfBlocksException e) { BlockState placed = blockState;// TODO BlockType.getBlockBagItem(id, data); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 57be96226..153ad1af0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -21,10 +21,8 @@ package com.sk89q.worldedit.extent.reorder; import com.google.common.collect.Iterators; import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.PlayerDirection; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.Blocks; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; @@ -175,19 +173,18 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder } } - final PlayerDirection attachment = BlockType.getAttachment(blockStateHolder.getBlockType().getLegacyId(), 0); // TODO - if (attachment == null) { + if (!blockStateHolder.getBlockType().getMaterial().isFragileWhenPushed()) { // Block is not attached to anything => we can place it break; } - current = current.add(attachment.vector()).toBlockVector(); - - if (!blocks.contains(current)) { - // We ran outside the remaining set => assume we can place blocks on this - break; - } - +// current = current.add(attachment.vector()).toBlockVector(); +// +// if (!blocks.contains(current)) { +// // We ran outside the remaining set => assume we can place blocks on this +// break; +// } +// if (walked.contains(current)) { // Cycle detected => This will most likely go wrong, but there's nothing we can do about it. break; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Category.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Category.java index ee077cd70..0f7f256a8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Category.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Category.java @@ -59,4 +59,9 @@ public abstract class Category { this.set.clear(); this.empty = true; } + + @Override + public String toString() { + return getId(); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index a6ecd79dc..05cd6543b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -175,6 +175,11 @@ public class BlockType { } } + @Override + public String toString() { + return getId(); + } + @Override public int hashCode() { return this.id.hashCode(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java index 1f7cb5925..71779e953 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java @@ -48,6 +48,11 @@ public class EntityType { return getId(); } + @Override + public String toString() { + return getId(); + } + @Override public int hashCode() { return this.id.hashCode(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java index 3207619ca..5b94015e1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java @@ -44,6 +44,11 @@ public class FluidType { return this.id; } + @Override + public String toString() { + return getId(); + } + @Override public int hashCode() { return this.id.hashCode(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java index bb0d0d6cf..9cfd4b111 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java @@ -44,6 +44,11 @@ public class GameMode { return getId(); } + @Override + public String toString() { + return getId(); + } + @Override public int hashCode() { return this.id.hashCode(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java index 6452451d0..90ccf072d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java @@ -78,6 +78,11 @@ public class ItemType { return BlockTypes.get(this.id); } + @Override + public String toString() { + return getId(); + } + @Override public int hashCode() { return this.id.hashCode(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java index dac65115f..c44392df0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java @@ -44,6 +44,11 @@ public class WeatherType { return getId(); } + @Override + public String toString() { + return getId(); + } + @Override public int hashCode() { return this.id.hashCode(); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index c35684059..b7bf6cd76 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -386,7 +386,7 @@ public class ForgeWorld extends AbstractWorld { TileEntity tile = getWorld().getTileEntity(pos); if (tile != null) { - return new TileEntityBaseBlock(getBlock(position), tile); + return getBlock(position).toBaseBlock(NBTConverter.fromNative(TileEntityUtils.copyNbtData(tile))); } else { return getBlock(position).toBaseBlock(); } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java deleted file mode 100644 index c1700150f..000000000 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser 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 Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.forge; - -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.blocks.TileEntityBlock; -import com.sk89q.worldedit.world.block.BlockState; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - -public class TileEntityBaseBlock extends BaseBlock implements TileEntityBlock { - - public TileEntityBaseBlock(BlockState state, TileEntity tile) { - super(state, NBTConverter.fromNative(copyNbtData(tile))); - } - - private static NBTTagCompound copyNbtData(TileEntity tile) { - NBTTagCompound tag = new NBTTagCompound(); - tile.writeToNBT(tag); - return tag; - } - -} \ No newline at end of file diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java index 803407766..f87293db8 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java @@ -140,4 +140,9 @@ final class TileEntityUtils { return genericTE; } + public static NBTTagCompound copyNbtData(TileEntity tile) { + NBTTagCompound tag = new NBTTagCompound(); + tile.writeToNBT(tag); + return tag; + } } diff --git a/worldedit-forge/src/main/resources/mcmod.info b/worldedit-forge/src/main/resources/mcmod.info index 599e2f5e1..bcee1cd4a 100644 --- a/worldedit-forge/src/main/resources/mcmod.info +++ b/worldedit-forge/src/main/resources/mcmod.info @@ -6,7 +6,7 @@ "mcversion": "${mcVersion}", "url": "http://wiki.sk89q.com/wiki/WorldEdit", "updateUrl": "", - "authors": [ "sk89q", "wizjany", "TomyLobo", "kenzierocks" ], + "authors": [ "sk89q", "wizjany", "TomyLobo", "kenzierocks", "Me4502" ], "credits": "", "logoFile": "", "screenshots": [],