mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Replace FuzzyBlockMask with BlockMask, and added BlockTypeMask as a more performant mask for just block types.
This commit is contained in:
@ -21,12 +21,11 @@ package com.sk89q.worldedit.function.block;
|
||||
|
||||
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 class Naturalizer implements LayerFunction {
|
||||
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 @@ 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 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;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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 com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.Blocks;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class FuzzyBlockMask extends BlockMask {
|
||||
|
||||
public FuzzyBlockMask(Extent extent, Collection<BlockStateHolder> blocks) {
|
||||
super(extent, blocks);
|
||||
}
|
||||
|
||||
public FuzzyBlockMask(Extent extent, BlockStateHolder... block) {
|
||||
super(extent, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
Extent extent = getExtent();
|
||||
Collection<BlockStateHolder> blocks = getBlocks();
|
||||
return Blocks.containsFuzzy(blocks, extent.getFullBlock(vector));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user