From fdc3cd56f79998c903c77c95ef0d7be2f2b10743 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 30 Aug 2018 14:51:38 +1000 Subject: [PATCH 1/2] Add a mask for block categories. Eg, you can now do //replace ##wool minecraft:sand to replace all wool with sand --- .../extension/factory/DefaultMaskParser.java | 15 +++++- .../function/mask/BlockCategoryMask.java | 53 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java index cf0565739..981e60800 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java @@ -28,6 +28,7 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BiomeMask2D; +import com.sk89q.worldedit.function.mask.BlockCategoryMask; import com.sk89q.worldedit.function.mask.BlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.ExpressionMask; @@ -47,6 +48,8 @@ import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.RequestSelection; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.Biomes; +import com.sk89q.worldedit.world.block.BlockCategories; +import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.registry.BiomeRegistry; import java.util.ArrayList; @@ -111,8 +114,16 @@ class DefaultMaskParser extends InputParser { } catch (IncompleteRegionException e) { throw new InputParseException("Please make a selection first."); } + } else if (component.startsWith("##")) { + // This means it's a tag mask. + BlockCategory category = BlockCategories.get(component.substring(2).toLowerCase()); + if (category == null) { + throw new NoMatchException("Unrecognised tag '" + component.substring(2) + '\''); + } else { + return new BlockCategoryMask(extent, category); + } } else { - throw new NoMatchException("Unrecognized mask '" + component + "'"); + throw new NoMatchException("Unrecognized mask '" + component + '\''); } case '>': @@ -135,7 +146,7 @@ class DefaultMaskParser extends InputParser { for (String biomeName : biomesList) { BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry); if (biome == null) { - throw new InputParseException("Unknown biome '" + biomeName + "'"); + throw new InputParseException("Unknown biome '" + biomeName + '\''); } biomes.add(biome); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java new file mode 100644 index 000000000..fae7888a0 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java @@ -0,0 +1,53 @@ +/* + * 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.function.mask; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.world.block.BlockCategory; + +import javax.annotation.Nullable; + +/** + * A mask that tests whether a block matches a given {@link BlockCategory}, or tag. + */ +public class BlockCategoryMask extends AbstractExtentMask { + + private BlockCategory category; + + public BlockCategoryMask(Extent extent, BlockCategory category) { + super(extent); + checkNotNull(category); + this.category = category; + } + + @Override + public boolean test(Vector vector) { + return category.contains(getExtent().getBlock(vector)); + } + + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } +} From 8bfbc55c7166f9616b2bc66adfeffc36cd8b33f6 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 30 Aug 2018 16:42:50 +1000 Subject: [PATCH 2/2] Enable experimental //walls for non-cuboid regions. --- .../src/main/java/com/sk89q/worldedit/EditSession.java | 8 ++++---- .../src/main/java/com/sk89q/worldedit/WorldEdit.java | 4 ++-- .../java/com/sk89q/worldedit/command/RegionCommands.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) 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 fdbbb8e3b..593f6ec91 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -847,7 +847,7 @@ public class EditSession implements Extent { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeCuboidFaces(Region region, BaseBlock block) throws MaxChangedBlocksException { + public int makeCuboidFaces(Region region, BlockStateHolder block) throws MaxChangedBlocksException { return makeCuboidFaces(region, new BlockPattern(block)); } @@ -899,7 +899,7 @@ public class EditSession implements Extent { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeCuboidWalls(Region region, BaseBlock block) throws MaxChangedBlocksException { + public int makeCuboidWalls(Region region, BlockStateHolder block) throws MaxChangedBlocksException { return makeCuboidWalls(region, new BlockPattern(block)); } @@ -964,7 +964,7 @@ public class EditSession implements Extent { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int overlayCuboidBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException { + public int overlayCuboidBlocks(Region region, BlockStateHolder block) throws MaxChangedBlocksException { checkNotNull(block); return overlayCuboidBlocks(region, new BlockPattern(block)); @@ -1091,7 +1091,7 @@ public class EditSession implements Extent { * @return number of blocks moved * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int moveCuboidRegion(Region region, Vector dir, int distance, boolean copyAir, BaseBlock replacement) throws MaxChangedBlocksException { + public int moveCuboidRegion(Region region, Vector dir, int distance, boolean copyAir, BlockStateHolder replacement) throws MaxChangedBlocksException { return moveRegion(region, dir, distance, copyAir, replacement); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index 5d6233f23..c25e5a2c0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -24,7 +24,6 @@ import static com.sk89q.worldedit.event.platform.Interaction.OPEN; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.BlockInteractEvent; @@ -51,6 +50,7 @@ import com.sk89q.worldedit.util.io.file.FilenameException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.util.io.file.InvalidFilenameException; import com.sk89q.worldedit.util.logging.WorldEditPrefixHandler; +import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BundledBlockData; import com.sk89q.worldedit.world.registry.BundledItemData; @@ -144,7 +144,7 @@ public class WorldEdit { } /** - * Get the block factory from which new {@link BaseBlock}s can be + * Get the block factory from which new {@link BlockStateHolder}s can be * constructed. * * @return the block factory diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 5b5c17133..3b7efa781 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -220,7 +220,7 @@ public class RegionCommands { @CommandPermissions("worldedit.region.walls") @Logging(REGION) public void walls(Player player, EditSession editSession, @Selection Region region, Pattern pattern) throws WorldEditException { - int affected = editSession.makeCuboidWalls(region, pattern); + int affected = editSession.makeWalls(region, pattern); player.print(affected + " block(s) have been changed."); }