mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 12:36:40 +00:00
Added new Mask interface and deprecated old one.
This commit is contained in:
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.Extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link Mask} that takes uses an {@link Extent}.
|
||||
*/
|
||||
public abstract class AbstractExtentMask extends AbstractMask {
|
||||
|
||||
private Extent extent;
|
||||
|
||||
/**
|
||||
* Construct a new mask.
|
||||
*
|
||||
* @param extent the extent
|
||||
*/
|
||||
protected AbstractExtentMask(Extent extent) {
|
||||
setExtent(extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extent.
|
||||
*
|
||||
* @return the extent
|
||||
*/
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the extent.
|
||||
*
|
||||
* @param extent the extent
|
||||
*/
|
||||
public void setExtent(Extent extent) {
|
||||
checkNotNull(extent);
|
||||
this.extent = extent;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
/**
|
||||
* A base class of {@link Mask} that all masks should inherit from.
|
||||
*/
|
||||
public abstract class AbstractMask implements Mask {
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
/**
|
||||
* A base class of {@link Mask2D} that all masks should inherit from.
|
||||
*/
|
||||
public abstract class AbstractMask2D implements Mask2D {
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A mask that checks whether blocks at the given positions are listed
|
||||
* in a list of block types.
|
||||
* </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.
|
||||
*/
|
||||
public class BlockMask extends AbstractExtentMask {
|
||||
|
||||
private final Set<BaseBlock> blocks = new HashSet<BaseBlock>();
|
||||
|
||||
/**
|
||||
* Create a new block mask.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param blocks a list of blocks to match
|
||||
*/
|
||||
public BlockMask(Extent extent, Collection<BaseBlock> blocks) {
|
||||
super(extent);
|
||||
checkNotNull(blocks);
|
||||
blocks.addAll(blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new block mask.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param block an array of blocks to match
|
||||
*/
|
||||
public BlockMask(Extent extent, BaseBlock... 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<BaseBlock> blocks) {
|
||||
checkNotNull(blocks);
|
||||
blocks.addAll(blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given blocks to the list of criteria.
|
||||
*
|
||||
* @param block an array of blocks
|
||||
*/
|
||||
public void add(BaseBlock... block) {
|
||||
add(Arrays.asList(checkNotNull(block)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of blocks that are tested with.
|
||||
*
|
||||
* @return a list of blocks
|
||||
*/
|
||||
public Collection<BaseBlock> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
BaseBlock block = getExtent().getBlock(vector);
|
||||
return blocks.contains(block) || blocks.contains(new BaseBlock(block.getType(), -1));
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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 static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
* Has the criteria where the Y value of passed positions must be within
|
||||
* a certain range of Y values (inclusive).
|
||||
*/
|
||||
public class BoundedHeightMask extends AbstractMask {
|
||||
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
|
||||
/**
|
||||
* Create a new bounded height mask.
|
||||
*
|
||||
* @param minY the minimum Y
|
||||
* @param maxY the maximum Y (must be equal to or greater than minY)
|
||||
*/
|
||||
public BoundedHeightMask(int minY, int maxY) {
|
||||
checkArgument(minY <= maxY, "minY <= maxY required");
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return vector.getY() >= minY && vector.getY() <= maxY;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* A mask that returns true whenever the block at the location is not
|
||||
* an air block (it contains some other block).
|
||||
*/
|
||||
public class ExistingBlockMask extends AbstractExtentMask {
|
||||
|
||||
/**
|
||||
* Create a new existing block map.
|
||||
*
|
||||
* @param extent the extent to check
|
||||
*/
|
||||
public ExistingBlockMask(Extent extent) {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return getExtent().getBlockType(vector) != BlockID.AIR;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class FuzzyBlockMask extends BlockMask {
|
||||
|
||||
public FuzzyBlockMask(Extent extent, Collection<BaseBlock> blocks) {
|
||||
super(extent, blocks);
|
||||
}
|
||||
|
||||
public FuzzyBlockMask(Extent extent, BaseBlock... block) {
|
||||
super(extent, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
Extent extent = getExtent();
|
||||
Collection<BaseBlock> blocks = getBlocks();
|
||||
BaseBlock compare = new BaseBlock(extent.getBlockType(vector), extent.getBlockData(vector));
|
||||
return BaseBlock.containsFuzzy(blocks, compare);
|
||||
}
|
||||
}
|
37
src/main/java/com/sk89q/worldedit/function/mask/Mask.java
Normal file
37
src/main/java/com/sk89q/worldedit/function/mask/Mask.java
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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;
|
||||
|
||||
/**
|
||||
* Tests whether a given vector meets a criteria.
|
||||
*/
|
||||
public interface Mask {
|
||||
|
||||
/**
|
||||
* Returns true if the criteria is met.
|
||||
*
|
||||
* @param vector the vector to test
|
||||
* @return true if the criteria is met
|
||||
*/
|
||||
boolean test(Vector vector);
|
||||
|
||||
}
|
37
src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java
Normal file
37
src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.Vector2D;
|
||||
|
||||
/**
|
||||
* Tests whether a given vector meets a criteria.
|
||||
*/
|
||||
public interface Mask2D {
|
||||
|
||||
/**
|
||||
* Returns true if the criteria is met.
|
||||
*
|
||||
* @param vector the vector to test
|
||||
* @return true if the criteria is met
|
||||
*/
|
||||
boolean test(Vector2D vector);
|
||||
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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 java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Combines several masks and requires that all masks return true
|
||||
* when a certain position is tested. It serves as a logical AND operation
|
||||
* on a list of masks.
|
||||
*/
|
||||
public class MaskIntersection extends AbstractMask {
|
||||
|
||||
private final Set<Mask> masks = new HashSet<Mask>();
|
||||
|
||||
/**
|
||||
* Create a new intersection.
|
||||
*
|
||||
* @param masks a list of masks
|
||||
*/
|
||||
public MaskIntersection(Collection<Mask> masks) {
|
||||
checkNotNull(masks);
|
||||
masks.addAll(masks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new intersection.
|
||||
*
|
||||
* @param mask a list of masks
|
||||
*/
|
||||
public MaskIntersection(Mask... mask) {
|
||||
this(Arrays.asList(checkNotNull(mask)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some masks to the list.
|
||||
*
|
||||
* @param masks the masks
|
||||
*/
|
||||
public void add(Collection<Mask> masks) {
|
||||
checkNotNull(masks);
|
||||
masks.addAll(masks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some masks to the list.
|
||||
*
|
||||
* @param mask the masks
|
||||
*/
|
||||
public void add(Mask... mask) {
|
||||
add(Arrays.asList(checkNotNull(mask)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the masks that are tested with.
|
||||
*
|
||||
* @return the masks
|
||||
*/
|
||||
public Collection<Mask> getMasks() {
|
||||
return masks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
if (masks.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Mask mask : masks) {
|
||||
if (!mask.test(vector)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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 java.util.Collection;
|
||||
|
||||
/**
|
||||
* Combines several masks and requires that one or more masks return true
|
||||
* when a certain position is tested. It serves as a logical OR operation
|
||||
* on a list of masks.
|
||||
*/
|
||||
public class MaskUnion extends MaskIntersection {
|
||||
|
||||
/**
|
||||
* Create a new union.
|
||||
*
|
||||
* @param masks a list of masks
|
||||
*/
|
||||
public MaskUnion(Collection<Mask> masks) {
|
||||
super(masks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new union.
|
||||
*
|
||||
* @param mask a list of masks
|
||||
*/
|
||||
public MaskUnion(Mask... mask) {
|
||||
super(mask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
Collection<Mask> masks = getMasks();
|
||||
|
||||
for (Mask mask : masks) {
|
||||
if (mask.test(vector)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
113
src/main/java/com/sk89q/worldedit/function/mask/Masks.java
Normal file
113
src/main/java/com/sk89q/worldedit/function/mask/Masks.java
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Various utility functions related to {@link Mask} and {@link Mask2D}.
|
||||
*/
|
||||
public final class Masks {
|
||||
|
||||
private Masks() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 3D mask that always returns true;
|
||||
*
|
||||
* @return a mask
|
||||
*/
|
||||
public static Mask alwaysTrue() {
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 2D mask that always returns true;
|
||||
*
|
||||
* @return a mask
|
||||
*/
|
||||
public static Mask2D alwaysTrue2D() {
|
||||
return new AbstractMask2D() {
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the given mask.
|
||||
*
|
||||
* @param mask the mask
|
||||
* @return a new mask
|
||||
*/
|
||||
public static Mask negate(final Mask mask) {
|
||||
checkNotNull(mask);
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return !mask.test(vector);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the given mask.
|
||||
*
|
||||
* @param mask the mask
|
||||
* @return a new mask
|
||||
*/
|
||||
public static Mask2D negate(final Mask2D mask) {
|
||||
checkNotNull(mask);
|
||||
return new AbstractMask2D() {
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
return !mask.test(vector);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an old-style mask and convert it to a new mask.
|
||||
*
|
||||
* @param editSession the edit session to bind to
|
||||
* @param mask the old-style mask
|
||||
* @return a new-style mask
|
||||
*/
|
||||
public static Mask wrap(final EditSession editSession, final com.sk89q.worldedit.masks.Mask mask) {
|
||||
checkNotNull(mask);
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return mask.matches(editSession, vector);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.math.noise.NoiseGenerator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A mask that uses a noise generator and returns true whenever the noise
|
||||
* generator returns a value above the given density.
|
||||
*/
|
||||
public class NoiseFilter extends AbstractMask {
|
||||
|
||||
private NoiseGenerator noiseGenerator;
|
||||
private double density;
|
||||
|
||||
/**
|
||||
* Create a new noise filter.
|
||||
*
|
||||
* @param noiseGenerator the noise generator
|
||||
* @param density the density
|
||||
*/
|
||||
public NoiseFilter(NoiseGenerator noiseGenerator, double density) {
|
||||
setNoiseGenerator(noiseGenerator);
|
||||
setDensity(density);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the noise generator.
|
||||
*
|
||||
* @return the noise generator
|
||||
*/
|
||||
public NoiseGenerator getNoiseGenerator() {
|
||||
return noiseGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the noise generator.
|
||||
*
|
||||
* @param noiseGenerator a noise generator
|
||||
*/
|
||||
public void setNoiseGenerator(NoiseGenerator noiseGenerator) {
|
||||
checkNotNull(noiseGenerator);
|
||||
this.noiseGenerator = noiseGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the probability of passing as a number between 0 and 1 (inclusive).
|
||||
*
|
||||
* @return the density
|
||||
*/
|
||||
public double getDensity() {
|
||||
return density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the probability of passing as a number between 0 and 1 (inclusive).
|
||||
*
|
||||
* @return the density
|
||||
*/
|
||||
public void setDensity(double density) {
|
||||
checkArgument(density >= 0, "density must be >= 0");
|
||||
checkArgument(density <= 1, "density must be >= 1");
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return noiseGenerator.noise(vector) <= density;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.Vector2D;
|
||||
import com.sk89q.worldedit.math.noise.NoiseGenerator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A mask that uses a noise generator and returns true whenever the noise
|
||||
* generator returns a value above the given density.
|
||||
*/
|
||||
public class NoiseFilter2D extends AbstractMask2D {
|
||||
|
||||
private NoiseGenerator noiseGenerator;
|
||||
private double density;
|
||||
|
||||
/**
|
||||
* Create a new noise filter.
|
||||
*
|
||||
* @param noiseGenerator the noise generator
|
||||
* @param density the density
|
||||
*/
|
||||
public NoiseFilter2D(NoiseGenerator noiseGenerator, double density) {
|
||||
setNoiseGenerator(noiseGenerator);
|
||||
setDensity(density);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the noise generator.
|
||||
*
|
||||
* @return the noise generator
|
||||
*/
|
||||
public NoiseGenerator getNoiseGenerator() {
|
||||
return noiseGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the noise generator.
|
||||
*
|
||||
* @param noiseGenerator a noise generator
|
||||
*/
|
||||
public void setNoiseGenerator(NoiseGenerator noiseGenerator) {
|
||||
checkNotNull(noiseGenerator);
|
||||
this.noiseGenerator = noiseGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the probability of passing as a number between 0 and 1 (inclusive).
|
||||
*
|
||||
* @return the density
|
||||
*/
|
||||
public double getDensity() {
|
||||
return density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the probability of passing as a number between 0 and 1 (inclusive).
|
||||
*
|
||||
* @return the density
|
||||
*/
|
||||
public void setDensity(double density) {
|
||||
checkArgument(density >= 0, "density must be >= 0");
|
||||
checkArgument(density <= 1, "density must be >= 1");
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector2D pos) {
|
||||
return noiseGenerator.noise(pos) <= density;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.regions.Region;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A mask that tests whether given positions are contained within a region.
|
||||
*/
|
||||
public class RegionMask extends AbstractMask {
|
||||
|
||||
private Region region;
|
||||
|
||||
/**
|
||||
* Create a new region mask.
|
||||
*
|
||||
* @param region the region
|
||||
*/
|
||||
public RegionMask(Region region) {
|
||||
setRegion(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region.
|
||||
*
|
||||
* @return the region
|
||||
*/
|
||||
public Region getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the region that positions must be contained within.
|
||||
*
|
||||
* @param region the region
|
||||
*/
|
||||
public void setRegion(Region region) {
|
||||
checkNotNull(region);
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return region.contains(vector);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU 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.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
|
||||
public class SolidBlockMask extends AbstractExtentMask {
|
||||
|
||||
public SolidBlockMask(Extent extent) {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
Extent extent = getExtent();
|
||||
return !BlockType.canPassThrough(extent.getBlockType(vector), extent.getBlockData(vector));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user