mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
Implemented new biome API.
This commit is contained in:
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.biome;
|
||||
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.FlatRegionFunction;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Replaces the biome at the locations that this function is applied to.
|
||||
*/
|
||||
public class BiomeReplace implements FlatRegionFunction {
|
||||
|
||||
private final Extent extent;
|
||||
private BaseBiome biome;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param extent an extent
|
||||
* @param biome a biome
|
||||
*/
|
||||
public BiomeReplace(Extent extent, BaseBiome biome) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(biome);
|
||||
this.extent = extent;
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Vector2D position) throws WorldEditException {
|
||||
return extent.setBiome(position, biome);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.Vector2D;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Tests true if the biome at applied points is the same as the one given.
|
||||
*/
|
||||
public class BiomeMask2D extends AbstractMask2D {
|
||||
|
||||
private final Extent extent;
|
||||
private final Set<BaseBiome> biomes = new HashSet<BaseBiome>();
|
||||
|
||||
/**
|
||||
* Create a new biome mask.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param biomes a list of biomes to match
|
||||
*/
|
||||
public BiomeMask2D(Extent extent, Collection<BaseBiome> biomes) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(biomes);
|
||||
this.extent = extent;
|
||||
this.biomes.addAll(biomes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new biome mask.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param biome an array of biomes to match
|
||||
*/
|
||||
public BiomeMask2D(Extent extent, BaseBiome... biome) {
|
||||
this(extent, Arrays.asList(checkNotNull(biome)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given biomes to the list of criteria.
|
||||
*
|
||||
* @param biomes a list of biomes
|
||||
*/
|
||||
public void add(Collection<BaseBiome> biomes) {
|
||||
checkNotNull(biomes);
|
||||
this.biomes.addAll(biomes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given biomes to the list of criteria.
|
||||
*
|
||||
* @param biome an array of biomes
|
||||
*/
|
||||
public void add(BaseBiome... biome) {
|
||||
add(Arrays.asList(checkNotNull(biome)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of biomes that are tested with.
|
||||
*
|
||||
* @return a list of biomes
|
||||
*/
|
||||
public Collection<BaseBiome> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
BaseBiome biome = extent.getBiome(vector);
|
||||
return biomes.contains(biome);
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -96,4 +97,11 @@ public class BlockMask extends AbstractExtentMask {
|
||||
BaseBlock block = getExtent().getBlock(vector);
|
||||
return blocks.contains(block) || blocks.contains(new BaseBlock(block.getType(), -1));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
@ -49,4 +51,10 @@ public class BoundedHeightMask extends AbstractMask {
|
||||
return vector.getY() >= minY && vector.getY() <= maxY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A mask that returns true whenever the block at the location is not
|
||||
* an air block (it contains some other block).
|
||||
@ -43,4 +45,10 @@ public class ExistingBlockMask extends AbstractExtentMask {
|
||||
return getExtent().getLazyBlock(vector).getType() != BlockID.AIR;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Tests whether a given vector meets a criteria.
|
||||
*/
|
||||
@ -34,4 +36,12 @@ public interface Mask {
|
||||
*/
|
||||
boolean test(Vector vector);
|
||||
|
||||
/**
|
||||
* Get the 2D version of this mask if one exists.
|
||||
*
|
||||
* @return a 2D mask version or {@code null} if this mask can't be 2D
|
||||
*/
|
||||
@Nullable
|
||||
Mask2D toMask2D();
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,12 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -86,7 +89,7 @@ public class MaskIntersection extends AbstractMask {
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
if (masks.size() == 0) {
|
||||
if (masks.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -99,4 +102,19 @@ public class MaskIntersection extends AbstractMask {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
List<Mask2D> mask2dList = new ArrayList<Mask2D>();
|
||||
for (Mask mask : masks) {
|
||||
Mask2D mask2d = mask.toMask2D();
|
||||
if (mask2d != null) {
|
||||
mask2dList.add(mask2d);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new MaskIntersection2D(mask2dList);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.Vector2D;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Tests true if all contained masks test true.
|
||||
*/
|
||||
public class MaskIntersection2D implements Mask2D {
|
||||
|
||||
private final Set<Mask2D> masks = new HashSet<Mask2D>();
|
||||
|
||||
/**
|
||||
* Create a new intersection.
|
||||
*
|
||||
* @param masks a list of masks
|
||||
*/
|
||||
public MaskIntersection2D(Collection<Mask2D> masks) {
|
||||
checkNotNull(masks);
|
||||
this.masks.addAll(masks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new intersection.
|
||||
*
|
||||
* @param mask a list of masks
|
||||
*/
|
||||
public MaskIntersection2D(Mask2D... mask) {
|
||||
this(Arrays.asList(checkNotNull(mask)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some masks to the list.
|
||||
*
|
||||
* @param masks the masks
|
||||
*/
|
||||
public void add(Collection<Mask2D> masks) {
|
||||
checkNotNull(masks);
|
||||
this.masks.addAll(masks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some masks to the list.
|
||||
*
|
||||
* @param mask the masks
|
||||
*/
|
||||
public void add(Mask2D... mask) {
|
||||
add(Arrays.asList(checkNotNull(mask)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the masks that are tested with.
|
||||
*
|
||||
* @return the masks
|
||||
*/
|
||||
public Collection<Mask2D> getMasks() {
|
||||
return masks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
if (masks.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Mask2D mask : masks) {
|
||||
if (!mask.test(vector)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -21,7 +21,10 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Combines several masks and requires that one or more masks return true
|
||||
@ -61,4 +64,18 @@ public class MaskUnion extends MaskIntersection {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
List<Mask2D> mask2dList = new ArrayList<Mask2D>();
|
||||
for (Mask mask : getMasks()) {
|
||||
Mask2D mask2d = mask.toMask2D();
|
||||
if (mask2d != null) {
|
||||
mask2dList.add(mask2d);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new MaskUnion2D(mask2dList);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.Vector2D;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Tests true if any contained mask is true, even if it just one.
|
||||
*/
|
||||
public class MaskUnion2D extends MaskIntersection2D {
|
||||
|
||||
/**
|
||||
* Create a new union.
|
||||
*
|
||||
* @param masks a list of masks
|
||||
*/
|
||||
public MaskUnion2D(Collection<Mask2D> masks) {
|
||||
super(masks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new union.
|
||||
*
|
||||
* @param mask a list of masks
|
||||
*/
|
||||
public MaskUnion2D(Mask2D... mask) {
|
||||
super(mask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
Collection<Mask2D> masks = getMasks();
|
||||
|
||||
for (Mask2D mask : masks) {
|
||||
if (mask.test(vector)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -22,6 +22,8 @@ package com.sk89q.worldedit.function.mask;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
@ -29,6 +31,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public final class Masks {
|
||||
|
||||
private static final AlwaysTrue ALWAYS_TRUE = new AlwaysTrue();
|
||||
private static final AlwaysFalse ALWAYS_FALSE = new AlwaysFalse();
|
||||
|
||||
private Masks() {
|
||||
}
|
||||
|
||||
@ -38,12 +43,7 @@ public final class Masks {
|
||||
* @return a mask
|
||||
*/
|
||||
public static Mask alwaysTrue() {
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
return ALWAYS_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,12 +52,7 @@ public final class Masks {
|
||||
* @return a mask
|
||||
*/
|
||||
public static Mask2D alwaysTrue2D() {
|
||||
return new AbstractMask2D() {
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
return ALWAYS_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,12 +62,29 @@ public final class Masks {
|
||||
* @return a new mask
|
||||
*/
|
||||
public static Mask negate(final Mask mask) {
|
||||
if (mask instanceof AlwaysTrue) {
|
||||
return ALWAYS_FALSE;
|
||||
} else if (mask instanceof AlwaysFalse) {
|
||||
return ALWAYS_TRUE;
|
||||
}
|
||||
|
||||
checkNotNull(mask);
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return !mask.test(vector);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
Mask2D mask2d = mask.toMask2D();
|
||||
if (mask2d != null) {
|
||||
return negate(mask2d);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -83,6 +95,12 @@ public final class Masks {
|
||||
* @return a new mask
|
||||
*/
|
||||
public static Mask2D negate(final Mask2D mask) {
|
||||
if (mask instanceof AlwaysTrue) {
|
||||
return ALWAYS_FALSE;
|
||||
} else if (mask instanceof AlwaysFalse) {
|
||||
return ALWAYS_TRUE;
|
||||
}
|
||||
|
||||
checkNotNull(mask);
|
||||
return new AbstractMask2D() {
|
||||
@Override
|
||||
@ -92,6 +110,27 @@ public final class Masks {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 3-dimensional version of a 2D mask.
|
||||
*
|
||||
* @param mask the mask to make 3D
|
||||
* @return a 3D mask
|
||||
*/
|
||||
public static Mask asMask(final Mask2D mask) {
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return mask.test(vector.toVector2D());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return mask;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an old-style mask and convert it to a new mask.
|
||||
* </p>
|
||||
@ -113,6 +152,12 @@ public final class Masks {
|
||||
public boolean test(Vector vector) {
|
||||
return mask.matches(editSession, vector);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -135,6 +180,12 @@ public final class Masks {
|
||||
EditSession editSession = Request.request().getEditSession();
|
||||
return editSession != null && mask.matches(editSession, vector);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -156,4 +207,40 @@ public final class Masks {
|
||||
};
|
||||
}
|
||||
|
||||
private static class AlwaysTrue implements Mask, Mask2D {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AlwaysFalse implements Mask, Mask2D {
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ package com.sk89q.worldedit.function.mask;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.noise.NoiseGenerator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -89,4 +91,10 @@ public class NoiseFilter extends AbstractMask {
|
||||
return noiseGenerator.noise(vector) <= density;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return new NoiseFilter2D(getNoiseGenerator(), getDensity());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,10 +21,13 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Checks whether the provided mask tests true for an offset position.
|
||||
* Checks whether another mask tests true for a position that is offset
|
||||
* a given vector.
|
||||
*/
|
||||
public class OffsetMask extends AbstractMask {
|
||||
|
||||
@ -87,4 +90,15 @@ public class OffsetMask extends AbstractMask {
|
||||
return getMask().test(vector.add(offset));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
Mask2D childMask = getMask().toMask2D();
|
||||
if (childMask != null) {
|
||||
return new OffsetMask2D(childMask, getOffset().toVector2D());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.Vector2D;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Checks whether another mask tests true for a position that is offset
|
||||
* a given vector.
|
||||
*/
|
||||
public class OffsetMask2D extends AbstractMask2D {
|
||||
|
||||
private Mask2D mask;
|
||||
private Vector2D offset;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param mask the mask
|
||||
* @param offset the offset
|
||||
*/
|
||||
public OffsetMask2D(Mask2D mask, Vector2D offset) {
|
||||
checkNotNull(mask);
|
||||
checkNotNull(offset);
|
||||
this.mask = mask;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mask.
|
||||
*
|
||||
* @return the mask
|
||||
*/
|
||||
public Mask2D getMask() {
|
||||
return mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the mask.
|
||||
*
|
||||
* @param mask the mask
|
||||
*/
|
||||
public void setMask(Mask2D mask) {
|
||||
checkNotNull(mask);
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the offset.
|
||||
*
|
||||
* @return the offset
|
||||
*/
|
||||
public Vector2D getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the offset.
|
||||
*
|
||||
* @param offset the offset
|
||||
*/
|
||||
public void setOffset(Vector2D offset) {
|
||||
checkNotNull(offset);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector2D vector) {
|
||||
return getMask().test(vector.add(offset));
|
||||
}
|
||||
|
||||
}
|
@ -22,6 +22,8 @@ package com.sk89q.worldedit.function.mask;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
@ -64,4 +66,10 @@ public class RegionMask extends AbstractMask {
|
||||
return region.contains(vector);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SolidBlockMask extends AbstractExtentMask {
|
||||
|
||||
public SolidBlockMask(Extent extent) {
|
||||
@ -37,4 +39,10 @@ public class SolidBlockMask extends AbstractExtentMask {
|
||||
return !BlockType.canPassThrough(lazyBlock.getType(), lazyBlock.getData());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user