Update from sk89q/master

This commit is contained in:
Jesse Boyd
2018-09-03 00:10:38 +10:00
59 changed files with 231 additions and 200 deletions

View File

@ -34,6 +34,6 @@ public interface EntityFunction {
* @return true if something was changed
* @throws WorldEditException thrown on an error
*/
public boolean apply(Entity entity) throws WorldEditException;
boolean apply(Entity entity) throws WorldEditException;
}

View File

@ -36,6 +36,6 @@ public interface FlatRegionFunction {
* @return true if something was changed
* @throws WorldEditException thrown on an error
*/
public boolean apply(Vector2D position) throws WorldEditException;
boolean apply(Vector2D position) throws WorldEditException;
}

View File

@ -34,6 +34,6 @@ public interface RegionFunction {
* @return true if something was changed
* @throws WorldEditException thrown on an error
*/
public boolean apply(Vector position) throws WorldEditException;
boolean apply(Vector position) throws WorldEditException;
}

View File

@ -28,7 +28,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
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 static com.google.common.base.Preconditions.checkNotNull;

View File

@ -23,9 +23,9 @@ import java.util.Map;
/**
* A mask that checks whether blocks at the given positions are matched by
* a block in a list.
* <p>
* <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 {

View File

@ -5,6 +5,12 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
public class BlockTypeMask extends AbstractExtentMask {
private final boolean[] types;
@ -19,6 +25,55 @@ public class BlockTypeMask extends AbstractExtentMask {
for (BlockType type : types) this.types[type.getInternalId()] = true;
}
/**
* Create a new block mask.
*
* @param extent the extent
* @param blocks a list of blocks to match
*/
public BlockTypeMask(Extent extent, Collection<BlockType> blocks) {
this(extent, blocks.toArray(new BlockType[blocks.size()]));
}
/**
* Add the given blocks to the list of criteria.
*
* @param blocks a list of blocks
*/
public void add(Collection<BlockType> blocks) {
checkNotNull(blocks);
for (BlockType type : blocks) {
add(type);
}
for (BlockType type : blocks) {
this.types[type.getInternalId()] = true;
}
}
/**
* Add the given blocks to the list of criteria.
*
* @param blocks an array of blocks
*/
public void add(BlockType... blocks) {
for (BlockType type : blocks) {
this.types[type.getInternalId()] = true;
}
}
/**
* Get the list of blocks that are tested with.
*
* @return a list of blocks
*/
public Collection<BlockType> getBlocks() {
Set<BlockType> blocks = new HashSet<>();
for (int i = 0; i < types.length; i++) {
if (types[i]) blocks.add(BlockTypes.get(i));
}
return blocks;
}
@Override
public boolean test(Vector vector) {
return types[getExtent().getBlockType(vector).getInternalId()];

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.function.mask;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.Vector;
@ -42,7 +41,7 @@ public class ExistingBlockMask extends AbstractExtentMask {
@Override
public boolean test(Vector vector) {
return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir();
return !getExtent().getBlock(vector).getMaterial().isAir();
}
@Nullable