Permalink
Browse files

Replace FuzzyBlockMask with BlockMask, and added BlockTypeMask as a m…

…ore performant mask for just block types.
  • Loading branch information...
me4502 committed Aug 20, 2018
1 parent d3b3d57 commit 69ab1781c6b1070669173288abf0b5af9eb31925
@@ -25,7 +25,6 @@
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
@@ -51,9 +50,9 @@
import com.sk89q.worldedit.function.block.Naturalizer;
import com.sk89q.worldedit.function.generator.GardenPatchGenerator;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.BoundedHeightMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.FuzzyBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.function.mask.MaskUnion;
@@ -102,6 +101,7 @@
import com.sk89q.worldedit.world.NullWorld;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@@ -601,7 +601,7 @@ public void flushQueue() {
* @return the number of blocks that matched the pattern
*/
public int countBlocks(Region region, Set<BlockStateHolder> searchBlocks) {
FuzzyBlockMask mask = new FuzzyBlockMask(this, searchBlocks);
BlockMask mask = new BlockMask(this, searchBlocks);
Counter count = new Counter();
RegionMaskingFilter filter = new RegionMaskingFilter(mask, count);
RegionVisitor visitor = new RegionVisitor(region, filter);
@@ -725,7 +725,7 @@ public int removeNear(Vector position, BlockType blockType, int apothem) throws
checkNotNull(position);
checkArgument(apothem >= 1, "apothem >= 1");
Mask mask = new FuzzyBlockMask(this, blockType.getDefaultState().toFuzzy());
Mask mask = new BlockTypeMask(this, blockType);
Vector adjustment = new Vector(1, 1, 1).multiply(apothem - 1);
Region region = new CuboidRegion(
getWorld(), // Causes clamping of Y range
@@ -790,7 +790,7 @@ public int replaceBlocks(Region region, Set<BlockStateHolder> filter, BlockState
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int replaceBlocks(Region region, Set<BlockStateHolder> filter, Pattern pattern) throws MaxChangedBlocksException {
Mask mask = filter == null ? new ExistingBlockMask(this) : new FuzzyBlockMask(this, filter);
Mask mask = filter == null ? new ExistingBlockMask(this) : new BlockMask(this, filter);
return replaceBlocks(region, mask, pattern);
}
@@ -1141,10 +1141,10 @@ public int fixLiquid(Vector origin, double radius, BlockType fluid) throws MaxCh
checkArgument(radius >= 0, "radius >= 0 required");
// Our origins can only be liquids
BlockMask liquidMask = new BlockMask(this, fluid.getDefaultState().toFuzzy());
Mask liquidMask = new BlockTypeMask(this, fluid);
// But we will also visit air blocks
MaskIntersection blockMask = new MaskUnion(liquidMask, new BlockMask(this, BlockTypes.AIR.getDefaultState()));
MaskIntersection blockMask = new MaskUnion(liquidMask, Masks.negate(new ExistingBlockMask(this)));
// There are boundaries that the routine needs to stay in
MaskIntersection mask = new MaskIntersection(
@@ -42,7 +42,7 @@
import com.sk89q.worldedit.command.util.CreatureButcher;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.session.ClipboardHolder;
@@ -192,7 +192,7 @@ public void extinguishBrush(Player player, LocalSession session, EditSession edi
Pattern fill = new BlockPattern(BlockTypes.AIR.getDefaultState());
tool.setFill(fill);
tool.setSize(radius);
tool.setMask(new BlockMask(editSession, BlockTypes.FIRE.getDefaultState().toFuzzy()));
tool.setMask(new BlockTypeMask(editSession, BlockTypes.FIRE));
tool.setBrush(new SphereBrush(), "worldedit.brush.ex");
player.print(String.format("Extinguisher equipped (%.0f).", radius));
@@ -21,12 +21,11 @@
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.LayerFunction;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.world.block.BlockTypes;
@@ -49,11 +48,7 @@
public Naturalizer(EditSession editSession) {
checkNotNull(editSession);
this.editSession = editSession;
this.mask = new BlockMask(editSession, Sets.newHashSet(
BlockTypes.GRASS_BLOCK.getDefaultState(),
BlockTypes.DIRT.getDefaultState(),
BlockTypes.STONE.getDefaultState()
));
this.mask = new BlockTypeMask(editSession, BlockTypes.GRASS_BLOCK, BlockTypes.DIRT, BlockTypes.STONE);
}
/**
@@ -36,8 +36,8 @@
* A mask that checks whether blocks at the given positions are matched by
* a block in a list.
*
* <p>This mask checks for both an exact block ID and data value match, as well
* for a block with the same ID but a data value of -1.</p>
* <p>This mask checks for both an exact block type and state value match,
* respecting fuzzy status of the BlockState.</p>
*/
public class BlockMask extends AbstractExtentMask {
@@ -0,0 +1,106 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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.BlockType;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;
/**
* A mask that checks whether blocks at the given positions are matched by
* a block in a list.
*
* <p>This mask checks for ONLY the block type. If state should also be checked,
* use {@link BlockMask}.</p>
*/
public class BlockTypeMask extends AbstractExtentMask {
private final Set<BlockType> blocks = new HashSet<>();
/**
* Create a new block mask.
*
* @param extent the extent
* @param blocks a list of blocks to match
*/
public BlockTypeMask(Extent extent, Collection<BlockType> blocks) {
super(extent);
checkNotNull(blocks);
this.blocks.addAll(blocks);
}
/**
* Create a new block mask.
*
* @param extent the extent
* @param block an array of blocks to match
*/
public BlockTypeMask(Extent extent, BlockType... block) {
this(extent, Arrays.asList(checkNotNull(block)));
}
/**
* Add the given blocks to the list of criteria.
*
* @param blocks a list of blocks
*/
public void add(Collection<BlockType> blocks) {
checkNotNull(blocks);
this.blocks.addAll(blocks);
}
/**
* Add the given blocks to the list of criteria.
*
* @param block an array of blocks
*/
public void add(BlockType... block) {
add(Arrays.asList(checkNotNull(block)));
}
/**
* Get the list of blocks that are tested with.
*
* @return a list of blocks
*/
public Collection<BlockType> getBlocks() {
return blocks;
}
@Override
public boolean test(Vector vector) {
return blocks.contains(getExtent().getBlock(vector).getBlockType());
}
@Nullable
@Override
public Mask2D toMask2D() {
return null;
}
}

This file was deleted.

Oops, something went wrong.
@@ -25,7 +25,7 @@
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.util.Direction;
@@ -62,9 +62,7 @@ public int getMaxY() {
@Override
public Mask createLiquidMask() {
return new BlockMask(this,
BlockTypes.LAVA.getDefaultState().toFuzzy(),
BlockTypes.WATER.getDefaultState().toFuzzy());
return new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER);
}
@Override

0 comments on commit 69ab178

Please sign in to comment.