From 846a1b076942eea38bcf524f1d7013f736753736 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 29 Jun 2019 00:01:51 +1000 Subject: [PATCH] 6c94cca15e3422babb1ffe9ef24b1e8e8a64dd14 --- .../brush/perform/PatternPerformer.java | 4 +- .../fawe/bukkit/regions/FreeBuildRegion.java | 5 +- .../fawe/bukkit/regions/Worldguard.java | 4 +- .../EditSessionBlockChangeDelegate.java | 6 +- .../fawe/jnbt/anvil/WritableMCAChunk.java | 4 +- .../boydti/fawe/object/brush/ErodeBrush.java | 5 +- .../clipboard/ResizableClipboardBuilder.java | 2 +- .../object/collection/BlockVectorSet.java | 7 +- .../boydti/fawe/util/EditSessionBuilder.java | 2 +- .../java/com/sk89q/worldedit/EditSession.java | 105 +++++++++--------- .../worldedit/command/GenerationCommands.java | 7 +- .../worldedit/command/tool/BlockReplacer.java | 2 +- .../command/tool/brush/CylinderBrush.java | 2 +- .../command/tool/brush/GravityBrush.java | 30 ++--- .../tool/brush/HollowCylinderBrush.java | 2 +- .../command/tool/brush/HollowSphereBrush.java | 2 +- .../command/tool/brush/SphereBrush.java | 2 +- .../extent/clipboard/BlockArrayClipboard.java | 83 +++++++------- .../extent/inventory/BlockBagExtent.java | 14 +-- .../function/generator/FloraGenerator.java | 12 +- .../generator/GardenPatchGenerator.java | 4 +- .../function/pattern/BlockPattern.java | 2 + .../function/visitor/BreadthFirstSearch.java | 4 +- .../worldedit/math/convolution/HeightMap.java | 2 +- .../registry/state/IntegerProperty.java | 6 +- .../com/sk89q/worldedit/util/Direction.java | 28 ++++- 26 files changed, 192 insertions(+), 154 deletions(-) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PatternPerformer.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PatternPerformer.java index d7c39db37..7ef13cfbb 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PatternPerformer.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PatternPerformer.java @@ -6,6 +6,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector3; import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.SnipeData; @@ -13,6 +14,7 @@ public class PatternPerformer extends vPerformer { private String info; private Pattern pattern; private Extent extent; + private final MutableBlockVector3 mutable = new MutableBlockVector3(); @Override public void info(Message vm) { @@ -31,7 +33,7 @@ public class PatternPerformer extends vPerformer { @Override public void perform(AsyncBlock block) { - BlockVector3 bv = BlockVector3.at(block.getX(), block.getY(), block.getZ()); + BlockVector3 bv = mutable.setComponents(block.getX(), block.getY(), block.getZ()); try { pattern.apply(extent, bv, bv); } catch (WorldEditException e) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java index b559ef377..0db780230 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java @@ -55,9 +55,8 @@ public class FreeBuildRegion extends BukkitMaskManager { World bukkitWorld = player.parent.getWorld(); AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld); - BlockVector3 vec1 = BlockVector3.at(0, 0, 0); - Location pos1 = BukkitAdapter.adapt(bukkitWorld, vec1); - Location pos2 = BukkitAdapter.adapt(bukkitWorld, vec1); + Location pos1 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO); + Location pos2 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO); AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0); BlockBreakEvent event = new BlockBreakEvent(block, player.parent); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java index 21e56280b..887c47a01 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java @@ -74,7 +74,7 @@ public class Worldguard extends BukkitMaskManager implements Listener { } public boolean isAllowed(LocalPlayer localplayer, ProtectedRegion region) { - if (region.isOwner(localplayer) || region.isOwner(localplayer)) { + if (region.isOwner(localplayer) || region.isOwner(localplayer.getName())) { return true; } else if (region.getId().toLowerCase().equals(localplayer.getName().toLowerCase())) { return true; @@ -84,7 +84,7 @@ public class Worldguard extends BukkitMaskManager implements Listener { return true; } if (localplayer.hasPermission("fawe.worldguard.member")) { - if (region.isMember(localplayer) || region.isMember(localplayer)) { + if (region.isMember(localplayer) || region.isMember(localplayer.getName())) { return true; } else if (region.isMember("*")) { return true; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java index e0613cd97..bae579d2b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java @@ -40,7 +40,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { @Override public boolean setBlockData(int x, int y, int z, BlockData blockData) { try { - editSession.setBlock(BlockVector3.at(x, y, z), BukkitAdapter.adapt(blockData)); + editSession.setBlock(x, y, z, BukkitAdapter.adapt(blockData)); } catch (MaxChangedBlocksException e) { return false; } @@ -49,7 +49,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { @Override public BlockData getBlockData(int x, int y, int z) { - return BukkitAdapter.adapt(editSession.getBlock(BlockVector3.at(x, y, z))); + return BukkitAdapter.adapt(editSession.getBlock(x, y, z)); } @Override @@ -59,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { @Override public boolean isEmpty(int x, int y, int z) { - return editSession.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isAir(); + return editSession.getBlock(x, y, z).getBlockType().getMaterial().isAir(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java index 9a5cbe717..1e9005880 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/WritableMCAChunk.java @@ -108,7 +108,9 @@ public class WritableMCAChunk extends FaweChunk { } out.writeNamedTag("InhabitedTime", inhabitedTime); out.writeNamedTag("LastUpdate", lastUpdate); - out.writeNamedTag("Biomes", biomes); + if (hasBiomes) { + out.writeNamedTag("Biomes", biomes); + } int len = 0; for (boolean hasSection : hasSections) { if (hasSection) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java index 2d65de252..272c950de 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java @@ -8,14 +8,17 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.Arrays; +import java.util.function.Function; +import java.util.stream.Stream; public class ErodeBrush implements Brush { - private static final BlockVector3[] FACES_TO_CHECK = {BlockVector3.at(0, 0, 1), BlockVector3.at(0, 0, -1), BlockVector3.at(0, 1, 0), BlockVector3.at(0, -1, 0), BlockVector3.at(1, 0, 0), BlockVector3.at(-1, 0, 0)}; + private static final BlockVector3[] FACES_TO_CHECK = Direction.valuesOf(Direction.Flag.CARDINAL).stream().map(direction -> direction.toBlockVector()).toArray(size -> new BlockVector3[size]); @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java index cd65424a2..41390a822 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java @@ -77,7 +77,7 @@ public class ResizableClipboardBuilder extends MemoryOptimizedHistory { int x = tileChange.tag.getInt("x"); int y = tileChange.tag.getInt("y"); int z = tileChange.tag.getInt("z"); - clipboard.setTile(BlockVector3.at(x,y,z), tileChange.tag); + clipboard.setTile(x,y,z, tileChange.tag); } } } catch (WorldEditException e) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java index 9b5ab33b6..b406d553c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java @@ -19,6 +19,7 @@ import java.util.*; */ public class BlockVectorSet extends AbstractCollection implements Set { private Int2ObjectMap localSets = new Int2ObjectOpenHashMap<>(); + private MutableBlockVector3 mutable = new MutableBlockVector3(); @Override public int size() { @@ -37,12 +38,12 @@ public class BlockVectorSet extends AbstractCollection implements int newSize = count + size; if (newSize > index) { int localIndex = index - count; - MutableBlockVector3 pos = new MutableBlockVector3(set.getIndex(localIndex)); + BlockVector3 pos = mutable.setComponents(set.getIndex(localIndex)); int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); int cz = MathMan.unpairY(pair); - pos.mutX((cx << 11) + pos.getBlockX()); - pos.mutZ((cz << 11) + pos.getBlockZ()); + pos = pos.mutX((cx << 11) + pos.getBlockX()); + pos = pos.mutZ((cz << 11) + pos.getBlockZ()); return pos; } count += newSize; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java index 29654d459..fe6e585d4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java @@ -54,7 +54,7 @@ public class EditSessionBuilder { public EditSessionBuilder(@Nonnull World world) { checkNotNull(world); this.world = world; - this.worldName = world.getName(); + this.worldName = Fawe.imp().getWorldName(world); } public EditSessionBuilder(@Nonnull String worldName) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index c2dab5bd1..e4eed01bb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -613,7 +613,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @param reorderMode The reorder mode */ public void setReorderMode(ReorderMode reorderMode) { - //TODO Not working yet. + //TODO Not working yet. - It shouldn't need to work. FAWE doesn't need reordering. } //TODO: Reorder mode. @@ -1106,7 +1106,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return height of highest block found or 'minY' */ public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { - return getHighestTerrainBlock(x, z, minY, maxY, null); + for (int y = maxY; y >= minY; --y) { + if (getBlock(x, y, z).getBlockType().getMaterial().isMovementBlocker()) { + return y; + } + } + return minY; } /** @@ -1121,10 +1126,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, */ public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) { for (int y = maxY; y >= minY; --y) { - BlockVector3 pt = BlockVector3.at(x, y, z); - if (filter == null - ? getBlock(pt).getBlockType().getMaterial().isMovementBlocker() - : filter.test(pt)) { + if (filter.test(mutablebv.setComponents(x, y, z))) { return y; } } @@ -1583,7 +1585,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int fillXZ(BlockVector3 origin, B block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException { - return fillXZ(origin, new BlockPattern(block), radius, depth, recursive); + return fillXZ(origin, (block), radius, depth, recursive); } /** @@ -1648,7 +1650,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, getWorld(), // Causes clamping of Y range position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, height - 1, apothem - 1)); - Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); + Pattern pattern = (BlockTypes.AIR.getDefaultState()); return setBlocks(region, pattern); } @@ -1670,7 +1672,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, getWorld(), // Causes clamping of Y range position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, -height + 1, apothem - 1)); - Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); + Pattern pattern = (BlockTypes.AIR.getDefaultState()); return setBlocks(region, pattern); } @@ -1745,7 +1747,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, getWorld(), // Causes clamping of Y range position.add(adjustment.multiply(-1)), position.add(adjustment)); - Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); + Pattern pattern = (BlockTypes.AIR.getDefaultState()); return replaceBlocks(region, mask, pattern); } @@ -1817,7 +1819,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int replaceBlocks(Region region, Set filter, B replacement) throws MaxChangedBlocksException { - return replaceBlocks(region, filter, new BlockPattern(replacement)); + return replaceBlocks(region, filter, (replacement)); } /** @@ -1889,7 +1891,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int makeCuboidFaces(Region region, B block) throws MaxChangedBlocksException { - return makeCuboidFaces(region, new BlockPattern(block)); + return makeCuboidFaces(region, (block)); } /** @@ -1941,7 +1943,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int makeCuboidWalls(Region region, B block) throws MaxChangedBlocksException { - return makeCuboidWalls(region, new BlockPattern(block)); + return makeCuboidWalls(region, (block)); } /** @@ -2003,7 +2005,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public > int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException { checkNotNull(block); - return overlayCuboidBlocks(region, new BlockPattern(block)); + return overlayCuboidBlocks(region, (block)); } /** @@ -2186,7 +2188,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, if (waterlogged) { replace = new BlockReplace(this, new WaterloggedRemover(this)); } else { - replace = new BlockReplace(this, new BlockPattern(BlockTypes.AIR.getDefaultState())); + replace = new BlockReplace(this, (BlockTypes.AIR.getDefaultState())); } RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), this); @@ -2228,7 +2230,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, blockMask ); - BlockReplace replace = new BlockReplace(this, new BlockPattern(fluid.getDefaultState())); + BlockReplace replace = new BlockReplace(this, (fluid.getDefaultState())); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); // Around the origin in a 3x3 block @@ -2585,7 +2587,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public int makePyramid(BlockVector3 position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException { - int affected = 0; + int bx = position.getX(); + int by = position.getY(); + int bz = position.getZ(); int height = size; @@ -2595,19 +2599,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, for (int z = 0; z <= size; ++z) { if ((filled && z <= size && x <= size) || z == size || x == size) { - - if (setBlock(position.add(x, y, z), block)) { - ++affected; - } - if (setBlock(position.add(-x, y, z), block)) { - ++affected; - } - if (setBlock(position.add(x, y, -z), block)) { - ++affected; - } - if (setBlock(position.add(-x, y, -z), block)) { - ++affected; - } + setBlock(x + bx, y + by, z + bz, block); + setBlock(-x + bx, y + by, z + bz, block); + setBlock(x + bx, y + by, -z + bz, block); + setBlock(-x + bx, y + by, -z + bz, block); } } } @@ -2643,16 +2638,15 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, continue; } - for (int y = world.getMaxY(); y >= 1; --y) { - BlockVector3 pt = BlockVector3.at(x, y, z); - BlockType id = getBlock(pt).getBlockType(); + for (int y = maxY; y >= 1; --y) { + BlockType id = getBlock(x, y, z).getBlockType(); if (id == BlockTypes.ICE) { - if (setBlock(pt, water)) { + if (setBlock(x, y, z, water)) { ++affected; } } else if (id == BlockTypes.SNOW) { - if (setBlock(pt, air)) { + if (setBlock(x, y, z, air)) { ++affected; } } else if (id.getMaterial().isAir()) { @@ -2718,7 +2712,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } // Too high? - if (y == world.getMaxY()) { + if (y == maxY) { break; } @@ -2743,13 +2737,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int green(BlockVector3 position, double radius, boolean onlyNormalDirt) + public int green(BlockVector3 position, double radius, final boolean onlyNormalDirt) throws MaxChangedBlocksException { - int affected = 0; final double radiusSq = radius * radius; final int ox = position.getBlockX(); - final int oy = position.getBlockY(); final int oz = position.getBlockZ(); final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState(); @@ -2765,20 +2757,20 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, continue; } loop: - for (int y = world.getMaxY(); y >= 1; --y) { - final BlockVector3 pt = BlockVector3.at(x, y, z); - final BlockState block = getBlock(pt); - - if (block.getBlockType() == BlockTypes.DIRT || - (!onlyNormalDirt && block.getBlockType() == BlockTypes.COARSE_DIRT)) { - if (setBlock(pt, grass)) { - break; - } - break; - } else if (block.getBlockType() == BlockTypes.WATER || block.getBlockType() == BlockTypes.LAVA) { - break; - } else if (block.getBlockType().getMaterial().isMovementBlocker()) { - break; + for (int y = maxY; y >= 1; --y) { + BlockType block = getBlockType(x, y, z); + switch (block.getInternalId()) { + case BlockID.COARSE_DIRT: + if (onlyNormalDirt) break loop; + case BlockID.DIRT: + this.setBlock(x, y, z, BlockTypes.GRASS_BLOCK.getDefaultState()); + break loop; + case BlockID.WATER: + case BlockID.LAVA: + default: + if (block.getMaterial().isMovementBlocker()) { + break loop; + } } } } @@ -2795,7 +2787,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of patches created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makePumpkinPatches(BlockVector3 position, int apothem) throws MaxChangedBlocksException { + public int makePumpkinPatches(final BlockVector3 position, final int apothem) { + return makePumpkinPatches(position, apothem, 0.02); + } + + public int makePumpkinPatches(final BlockVector3 position, final int apothem, double density) { // We want to generate pumpkins GardenPatchGenerator generator = new GardenPatchGenerator(this); generator.setPlant(GardenPatchGenerator.getPumpkinPattern()); @@ -2805,7 +2801,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, getWorld(), // Causes clamping of Y range position.add(-apothem, -5, -apothem), position.add(apothem, 10, apothem)); - double density = 0.02; GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator); LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index 3f662819c..3845a5ac5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -53,6 +53,7 @@ import com.sk89q.worldedit.util.command.binding.Range; import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.binding.Text; import com.sk89q.worldedit.util.command.parametric.Optional; +import com.sk89q.worldedit.util.command.parametric.ParameterException; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockType; @@ -293,15 +294,15 @@ public class GenerationCommands extends MethodCommands { @Command( aliases = { "pumpkins" }, - usage = "[size]", + usage = "[size=10] [density=0.02]", desc = "Generate pumpkin patches", min = 0, max = 2 ) @CommandPermissions("worldedit.generation.pumpkins") @Logging(POSITION) - public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException { - int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem); + public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem, @Optional("0.02") double density) throws WorldEditException, ParameterException { + int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem, density); BBC.COMMAND_PUMPKIN.send(player, affected); } 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 10b5790ec..5995234f9 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 @@ -76,7 +76,7 @@ public class BlockReplacer implements DoubleActionBlockTool { BlockState targetBlock = editSession.getBlock(clicked.toVector().toBlockPoint()); if (targetBlock != null) { - pattern = new BlockPattern(targetBlock); + pattern = (targetBlock); player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java index 12a663ed3..d1ef66637 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java @@ -37,7 +37,7 @@ public class CylinderBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = (BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeCylinder(position, pattern, size, size, height, true); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java index 173dd7936..8e2754779 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java @@ -21,11 +21,16 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; +import java.util.Vector; + public class GravityBrush implements Brush { private final boolean fullHeight; @@ -35,21 +40,20 @@ public class GravityBrush implements Brush { } @Override - public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { - double endY = position.getBlockY() + size; - double startPerformY = Math.max(0, position.getBlockY() - size); - double startCheckY = fullHeight ? 0 : startPerformY; - for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { - for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { - double freeSpot = startCheckY; - for (double y = startCheckY; y <= endY; ++y) { - final BlockVector3 pt = BlockVector3.at(x, y, z); - final BlockState block = editSession.getLazyBlock(pt); + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { + int size = (int) sizeDouble; + int endY = position.getBlockY() + size; + int startPerformY = Math.max(0, position.getBlockY() - size); + int startCheckY = fullHeight ? 0 : startPerformY; + for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { + for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { + int freeSpot = startCheckY; + for (int y = startCheckY; y <= endY; y++) { + BlockStateHolder block = editSession.getLazyBlock(x, y, z); if (!block.getBlockType().getMaterial().isAir()) { if (y != freeSpot) { - editSession.setBlock(pt, BlockTypes.AIR.getDefaultState()); - final BlockVector3 pt2 = BlockVector3.at(x, freeSpot, z); - editSession.setBlock(pt2, block); + editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState()); + editSession.setBlock(x, freeSpot, z, block); } freeSpot = y + 1; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java index dbf959e1b..d96a44819 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java @@ -37,7 +37,7 @@ public class HollowCylinderBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = (BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeCylinder(position, pattern, size, size, height, false); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java index 0e89b3c16..bbba333b3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java @@ -31,7 +31,7 @@ public class HollowSphereBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = (BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeSphere(position, pattern, size, size, size, false); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java index d8028f2ae..07e852da6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java @@ -31,7 +31,7 @@ public class SphereBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = (BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeSphere(position, pattern, size, size, size, true); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index e3646fb49..96adbf2bf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -58,10 +58,11 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable private Region region; private BlockVector3 origin; - private BaseBlock[][][] blocks; - private BiomeType[][] biomes = null; public FaweClipboard IMP; private BlockVector3 size; + private int mx; + private int my; + private int mz; private final List entities = new ArrayList<>(); public BlockArrayClipboard(Region region) { @@ -70,7 +71,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable this.size = getDimensions(); this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()); this.origin = region.getMinimumPoint(); - this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()]; + this.mx = origin.getBlockX(); + this.my = origin.getBlockY(); + this.mz = origin.getBlockZ(); } /** @@ -86,7 +89,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable this.size = getDimensions(); this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ(), clipboardId) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()); this.origin = region.getMinimumPoint(); - this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()]; + this.mx = origin.getBlockX(); + this.my = origin.getBlockY(); + this.mz = origin.getBlockZ(); } public BlockArrayClipboard(Region region, FaweClipboard clipboard) { @@ -95,7 +100,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable this.size = getDimensions(); this.origin = region.getMinimumPoint(); this.IMP = clipboard; - this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()]; + this.mx = origin.getBlockX(); + this.my = origin.getBlockY(); + this.mz = origin.getBlockZ(); } public void init(Region region, FaweClipboard fc) { @@ -105,7 +112,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable this.size = getDimensions(); this.IMP = fc; this.origin = region.getMinimumPoint(); - this.blocks = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()]; + this.mx = origin.getBlockX(); + this.my = origin.getBlockY(); + this.mz = origin.getBlockZ(); } @Override @@ -179,8 +188,10 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable @Override public BlockState getBlock(BlockVector3 position) { if (region.contains(position)) { - BlockVector3 v = position.subtract(region.getMinimumPoint()); - return IMP.getBlock(v.getX(),v.getY(),v.getZ()).toImmutableState(); + int x = position.getBlockX() - mx; + int y = position.getBlockY() - my; + int z = position.getBlockZ() - mz; + return IMP.getBlock(x, y, z).toImmutableState(); } return BlockTypes.AIR.getDefaultState(); @@ -193,11 +204,12 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable @Override public BaseBlock getFullBlock(BlockVector3 position) { - if (region.contains(position)) { - BlockVector3 v = position.subtract(region.getMinimumPoint()); - return IMP.getBlock(v.getX(),v.getY(),v.getZ()); - } - + if(region.contains(position)) { + int x = position.getBlockX() - mx; + int y = position.getBlockY() - my; + int z = position.getBlockZ() - mz; + return IMP.getBlock(x, y, z); + } return BlockTypes.AIR.getDefaultState().toBaseBlock(); } @@ -212,50 +224,41 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable return false; } + public boolean setTile(int x, int y, int z, CompoundTag tag) { + x -= mx; + y -= my; + z -= mz; + return IMP.setTile(x, y, z, tag); + } + public boolean setTile(BlockVector3 position, CompoundTag tag) { - BlockVector3 v = position.subtract(region.getMinimumPoint()); - return IMP.setTile(v.getX(), v.getY(), v.getZ(), tag); + return setTile(position.getX(), position.getY(), position.getZ(), tag); } @Override public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { - BlockVector3 position = BlockVector3.at(x, y, z); - BlockVector3 v = position.subtract(region.getMinimumPoint()); - return IMP.setBlock(v.getX(), v.getY(), v.getZ(), block); + x -= mx; + y -= my; + z -= mz; + return IMP.setBlock(x, y, z, block); } @Override public boolean hasBiomes() { - return biomes != null; + return IMP.hasBiomes(); } @Override public BiomeType getBiome(BlockVector2 position) { - if (biomes != null - && position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) { - BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2()); - BiomeType biomeType = biomes[v.getBlockX()][v.getBlockZ()]; - if (biomeType != null) { - return IMP.getBiome(v.getX(), v.getZ()); - //TODO Remove the line above and replace with this: return biomeType; - } - return IMP.getBiome(v.getX(), v.getZ()); - } - return BiomeTypes.OCEAN; + BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2()); + return IMP.getBiome(v.getX(), v.getZ()); } @Override public boolean setBiome(BlockVector2 position, BiomeType biome) { - if (position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) { - BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2()); - IMP.setBiome(v.getX(), v.getZ(), biome); - if (biomes == null) { - biomes = new BiomeType[region.getWidth()][region.getLength()]; - } - biomes[v.getBlockX()][v.getBlockZ()] = biome; - return true; - } - return false; + int x = position.getBlockX() - mx; + int z = position.getBlockZ() - mz; + return IMP.setBiome(x, z, biome); } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java index 22900c012..c6b7d3552 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java @@ -82,8 +82,13 @@ public class BlockBagExtent extends AbstractDelegateExtent { @Override public > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { + return setBlock(position.getX(), position.getY(), position.getZ(), block); + } + + @Override + public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { if (blockBag != null) { - BlockState existing = getExtent().getBlock(position); + BlockState existing = getLazyBlock(x, y, z); if (!block.getBlockType().equals(existing.getBlockType())) { if (!block.getBlockType().getMaterial().isAir()) { @@ -110,11 +115,6 @@ public class BlockBagExtent extends AbstractDelegateExtent { } } - return super.setBlock(position, block); - } - - @Override - public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { - return setBlock(BlockVector3.at(x,y,z),block); + return super.setBlock(x, y, z, block); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java index 039d1a7fd..d453ab448 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java @@ -83,9 +83,9 @@ public class FloraGenerator implements RegionFunction { */ public static Pattern getDesertPattern() { RandomPattern pattern = new RandomPattern(); - pattern.add(new BlockPattern(BlockTypes.DEAD_BUSH.getDefaultState()), 30); - pattern.add(new BlockPattern(BlockTypes.CACTUS.getDefaultState()), 20); - pattern.add(new BlockPattern(BlockTypes.AIR.getDefaultState()), 300); + pattern.add((BlockTypes.DEAD_BUSH.getDefaultState()), 30); + pattern.add((BlockTypes.CACTUS.getDefaultState()), 20); + pattern.add((BlockTypes.AIR.getDefaultState()), 300); return pattern; } @@ -96,9 +96,9 @@ public class FloraGenerator implements RegionFunction { */ public static Pattern getTemperatePattern() { RandomPattern pattern = new RandomPattern(); - pattern.add(new BlockPattern(BlockTypes.GRASS.getDefaultState()), 300); - pattern.add(new BlockPattern(BlockTypes.POPPY.getDefaultState()), 5); - pattern.add(new BlockPattern(BlockTypes.DANDELION.getDefaultState()), 5); + pattern.add((BlockTypes.GRASS.getDefaultState()), 300); + pattern.add((BlockTypes.POPPY.getDefaultState()), 5); + pattern.add((BlockTypes.DANDELION.getDefaultState()), 5); return pattern; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java index 0d31760af..14bbf7e2b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java @@ -187,7 +187,7 @@ public class GardenPatchGenerator implements RegionFunction { * @return a pumpkin pattern */ public static Pattern getPumpkinPattern() { - return new BlockPattern(BlockTypes.PUMPKIN.getDefaultState()); + return (BlockTypes.PUMPKIN.getDefaultState()); } /** @@ -208,6 +208,6 @@ public class GardenPatchGenerator implements RegionFunction { * @return a melon pattern */ public static Pattern getMelonPattern() { - return new BlockPattern(BlockTypes.MELON.getDefaultState()); + return (BlockTypes.MELON.getDefaultState()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java index fa49f5108..6fb46180f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java @@ -28,6 +28,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; /** * A pattern that returns the same {@link BaseBlock} each time. */ +@Deprecated public class BlockPattern extends AbstractPattern { private BaseBlock block; @@ -37,6 +38,7 @@ public class BlockPattern extends AbstractPattern { * * @param block the block */ + @Deprecated public BlockPattern(BlockStateHolder block) { setBlock(block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 1815a0c5f..74b25e576 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.util.Direction; import java.util.ArrayList; @@ -243,6 +244,7 @@ public abstract class BreadthFirstSearch implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { + MutableBlockVector3 mutable = new MutableBlockVector3(); IntegerTrio[] dirs = getIntDirections(); BlockVectorSet tempQueue = new BlockVectorSet(); BlockVectorSet chunkLoadSet = new BlockVectorSet(); @@ -280,7 +282,7 @@ public abstract class BreadthFirstSearch implements Operation { int x = from.getBlockX() + direction.x; int z = from.getBlockZ() + direction.z; if (!visited.contains(x, y, z)) { - if (isVisitable(from, BlockVector3.at(x, y, z))) { + if (isVisitable(from, mutable.setComponents(x, y, z))) { j++; visited.add(x, y, z); tempQueue.add(x, y, z); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java index 969893032..c1bc08f28 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java @@ -287,7 +287,7 @@ public class HeightMap { BlockState existing = session.getBlock(BlockVector3.at(xr, curHeight, zr)); // Skip water/lava - if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) { + if (existing.getBlockType().getMaterial().isMovementBlocker()) { int y0 = newHeight - 1; for (int setY = y0, getY = curHeight - 1; setY >= curHeight; setY--, getY--) { BlockState get = session.getBlock(xr, getY, zr); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java index b2ced727c..f8ce2a5b5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/IntegerProperty.java @@ -67,9 +67,9 @@ public class IntegerProperty extends AbstractProperty { public Integer getValueFor(String string) { try { int val = Integer.parseInt(string); - if (!getValues().contains(val)) { - throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString()); - } +// if (!getValues().contains(val)) { // This check is slow +// throw new IllegalArgumentException("Invalid int value: " + string + ". Must be in " + getValues().toString()); +// } return val; } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid int value: " + string + ". Not an int."); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java index 0361716e9..ac823fc28 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java @@ -69,7 +69,7 @@ public enum Direction { private final int right; private final BlockVector3 blockPoint; - private static HashMap map = new HashMap<>(); + private static HashMap map = new HashMap<>(); static { for (Direction dir : Direction.values()) { @@ -79,7 +79,7 @@ public enum Direction { } Direction(Vector3 vector, int flags, int left, int right) { - this.blockPoint = vector.toBlockPoint(); + this.blockPoint = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ())); this.direction = vector.normalize(); this.flags = flags; this.left = left; @@ -98,6 +98,30 @@ public enum Direction { return right != -1 ? values()[right] : null; } + public double getX() { + return direction.getX(); + } + + public double getY() { + return direction.getY(); + } + + public double getZ() { + return direction.getZ(); + } + + public int getBlockX() { + return blockPoint.getX(); + } + + public int getBlockY() { + return blockPoint.getY(); + } + + public int getBlockZ() { + return blockPoint.getZ(); + } + /** * Return true if the direction is of a cardinal direction (north, west * east, and south).