mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Make masks more stateless
This commit is contained in:
@ -54,4 +54,4 @@ public class FlatRegionMaskingFilter implements FlatRegionFunction {
|
||||
return mask.test(position) && function.apply(position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -51,7 +52,7 @@ public class RegionMaskTestFunction implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
if (mask.test(position)) {
|
||||
if (mask.test(NullExtent.INSTANCE, position)) {
|
||||
return pass.apply(position);
|
||||
} else {
|
||||
return fail.apply(position);
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.function;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -33,7 +34,8 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
public class RegionMaskingFilter implements RegionFunction {
|
||||
|
||||
private final RegionFunction function;
|
||||
private Mask mask;
|
||||
private final Extent extent;
|
||||
private final Mask mask;
|
||||
|
||||
/**
|
||||
* Create a new masking filter.
|
||||
@ -41,16 +43,18 @@ public class RegionMaskingFilter implements RegionFunction {
|
||||
* @param mask the mask
|
||||
* @param function the function
|
||||
*/
|
||||
public RegionMaskingFilter(Mask mask, RegionFunction function) {
|
||||
public RegionMaskingFilter(Extent extent, Mask mask, RegionFunction function) {
|
||||
checkNotNull(function);
|
||||
checkNotNull(mask);
|
||||
checkNotNull(extent);
|
||||
this.extent = extent;
|
||||
this.mask = mask;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
return mask.test(position) && function.apply(position);
|
||||
return mask.test(extent, position) && function.apply(position);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class Naturalizer implements LayerFunction {
|
||||
|
||||
@Override
|
||||
public boolean isGround(BlockVector3 position) {
|
||||
return mask.test(position);
|
||||
return mask.test(editSession, position);
|
||||
}
|
||||
|
||||
private BlockState getTargetBlock(int depth) {
|
||||
@ -95,7 +95,7 @@ public class Naturalizer implements LayerFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position, int depth) throws WorldEditException {
|
||||
if (mask.test(position)) {
|
||||
if (mask.test(editSession, position)) {
|
||||
if (naturalize(position, depth)) {
|
||||
++affected;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class OreGen implements Resource {
|
||||
@Override
|
||||
public boolean spawn(Random rand, int x, int z) throws WorldEditException {
|
||||
int y = rand.nextInt(maxY - minY) + minY;
|
||||
if (!mask.test(mutable.setComponents(x, y, z))) {
|
||||
if (!mask.test(extent, mutable.setComponents(x, y, z))) {
|
||||
return false;
|
||||
}
|
||||
double f = rand.nextDouble() * Math.PI;
|
||||
@ -102,7 +102,7 @@ public class OreGen implements Resource {
|
||||
double dz = (zz + 0.5D - d9) * id11o2;
|
||||
double dxyz2 = dxy2 + dz * dz;
|
||||
if ((dxyz2 < 1)) {
|
||||
if (mask.test(mutable))
|
||||
if (mask.test(extent, mutable))
|
||||
pattern.apply(extent, mutable, mutable);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class SchemGen implements Resource {
|
||||
int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), 0, 255);
|
||||
if (y == -1) return false;
|
||||
mutable.mutY(y);
|
||||
if (!mask.test(mutable)) {
|
||||
if (!mask.test(extent, mutable)) {
|
||||
return false;
|
||||
}
|
||||
mutable.mutY(y + 1);
|
||||
|
@ -2,6 +2,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -15,6 +16,11 @@ public abstract class ABlockMask extends AbstractExtentMask {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent));
|
||||
}
|
||||
|
||||
public abstract boolean test(BlockState state);
|
||||
|
||||
@Override
|
||||
|
@ -22,6 +22,8 @@ package com.sk89q.worldedit.function.mask;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link Mask} that takes uses an {@link Extent}.
|
||||
@ -39,6 +41,11 @@ public abstract class AbstractExtentMask extends AbstractMask {
|
||||
setExtent(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(getExtent(), vector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extent.
|
||||
*
|
||||
@ -58,4 +65,9 @@ public abstract class AbstractExtentMask extends AbstractMask {
|
||||
this.extent = extent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
setExtent(extent);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class BiomeMask2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
BiomeType biome = extent.getBiome(vector);
|
||||
return biomes.contains(biome);
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ public class BlockCategoryMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return category.contains(getExtent().getBlock(vector));
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return category.contains(vector.getBlock(extent));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -172,8 +172,8 @@ public class BlockMask extends ABlockMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return ordinals[vector.getOrdinal(getExtent())];
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return ordinals[vector.getOrdinal(extent)];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,8 +51,8 @@ public class BlockStateMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(vector.getBlock(getExtent()));
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent));
|
||||
}
|
||||
|
||||
public boolean test(BlockState block) {
|
||||
|
@ -106,8 +106,8 @@ public class BlockTypeMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(vector.getBlock(getExtent()).getBlockType());
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent).getBlockType());
|
||||
}
|
||||
|
||||
public boolean test(BlockType block) {
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -46,7 +47,7 @@ public class BoundedHeightMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return vector.getY() >= minY && vector.getY() <= maxY;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.boydti.fawe.object.function.mask.AbstractDelegateMask;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
public class DelegateExtentMask extends AbstractDelegateMask {
|
||||
private final Extent extent;
|
||||
|
||||
public DelegateExtentMask(Extent extent, Mask parent) {
|
||||
super(parent);
|
||||
this.extent = extent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return super.test(extent, vector);
|
||||
}
|
||||
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
return new DelegateExtentMask(extent, getMask());
|
||||
}
|
||||
}
|
@ -39,8 +39,8 @@ public class ExistingBlockMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return !vector.getBlock(getExtent()).getMaterial().isAir();
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return !vector.getBlock(extent).getMaterial().isAir();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.internal.expression.EvaluationException;
|
||||
@ -67,7 +68,7 @@ public class ExpressionMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
try {
|
||||
if (expression.getEnvironment() instanceof WorldEditExpressionEnvironment) {
|
||||
((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector.toVector3());
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.EvaluationException;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
@ -59,7 +60,7 @@ public class ExpressionMask2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
try {
|
||||
if (timeout == null) {
|
||||
return expression.evaluate(vector.getX(), 0, vector.getZ()) > 0;
|
||||
|
@ -2,6 +2,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
public class InverseMask extends AbstractMask {
|
||||
@ -12,8 +13,8 @@ public class InverseMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return !mask.test(vector);
|
||||
public boolean test(Extent extent, BlockVector3 pos) {
|
||||
return !mask.test(extent, pos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -18,8 +18,8 @@ public class InverseSingleBlockStateMask extends ABlockMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return ordinal != vector.getOrdinal(getExtent());
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return ordinal != vector.getOrdinal(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,8 +16,8 @@ public class InverseSingleBlockTypeMask extends ABlockMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(vector.getBlock(getExtent()));
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,13 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
import com.boydti.fawe.beta.implementation.filter.block.FilterBlock;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -36,12 +42,26 @@ public interface Mask {
|
||||
* @param vector the vector to test
|
||||
* @return true if the criteria is met
|
||||
*/
|
||||
boolean test(BlockVector3 vector);
|
||||
default boolean test(BlockVector3 vector) {
|
||||
Extent extent = Request.request().getExtent();
|
||||
if (extent == null) {
|
||||
extent = NullExtent.INSTANCE;
|
||||
}
|
||||
return test(extent, vector);
|
||||
}
|
||||
|
||||
default boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector);
|
||||
}
|
||||
|
||||
default <T extends Filter> MaskFilter<T> toFilter(T filter) {
|
||||
return new MaskFilter<>(filter, this);
|
||||
}
|
||||
|
||||
default Mask withExtent(Extent extent) {
|
||||
return new DelegateExtentMask(extent, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 2D version of this mask if one exists.
|
||||
*
|
||||
@ -97,7 +117,7 @@ public interface Mask {
|
||||
return new Filter() {
|
||||
@Override
|
||||
public void applyBlock(FilterBlock block) {
|
||||
if (test(block)) {
|
||||
if (test(block, block)) {
|
||||
run.accept(block);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
|
||||
/**
|
||||
* Tests whether a given vector meets a criteria.
|
||||
@ -32,6 +35,16 @@ public interface Mask2D {
|
||||
* @param vector the vector to test
|
||||
* @return true if the criteria is met
|
||||
*/
|
||||
boolean test(BlockVector2 vector);
|
||||
default boolean test(BlockVector2 vector) {
|
||||
Extent extent = Request.request().getExtent();
|
||||
if (extent == null) {
|
||||
extent = NullExtent.INSTANCE;
|
||||
}
|
||||
return test(extent, vector);
|
||||
}
|
||||
|
||||
default boolean test(Extent extent, BlockVector2 vector) {
|
||||
return test(vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class MaskFilter<T extends Filter> extends DelegateFilter<T> {
|
||||
|
||||
@Override
|
||||
public void applyBlock(FilterBlock block) {
|
||||
if (mask.test(block)) {
|
||||
if (mask.test(block, block)) {
|
||||
getParent().applyBlock(block);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
@ -224,9 +225,9 @@ public class MaskIntersection extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
for (Mask mask : masksArray) {
|
||||
if (!mask.test(vector)) {
|
||||
if (!mask.test(extent, vector)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -83,13 +84,13 @@ public class MaskIntersection2D implements Mask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
if (masks.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Mask2D mask : masks) {
|
||||
if (!mask.test(vector)) {
|
||||
if (!mask.test(extent, vector)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -84,11 +85,11 @@ public class MaskUnion extends MaskIntersection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
Mask[] masks = getMasksArray();
|
||||
|
||||
for (Mask mask : masks) {
|
||||
if (mask.test(vector)) {
|
||||
if (mask.test(extent, vector)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -47,11 +48,11 @@ public class MaskUnion2D extends MaskIntersection2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
Collection<Mask2D> masks = getMasks();
|
||||
|
||||
for (Mask2D mask : masks) {
|
||||
if (mask.test(vector)) {
|
||||
if (mask.test(extent, vector)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -89,8 +90,8 @@ public final class Masks {
|
||||
checkNotNull(mask);
|
||||
return new AbstractMask2D() {
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
return !mask.test(vector);
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
return !mask.test(extent, vector);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -104,8 +105,8 @@ public final class Masks {
|
||||
public static Mask asMask(final Mask2D mask) {
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return mask.test(vector.toBlockVector2());
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return mask.test(extent, vector.toBlockVector2());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -118,12 +119,12 @@ public final class Masks {
|
||||
|
||||
protected static class AlwaysTrue implements Mask, Mask2D {
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -142,16 +143,21 @@ public final class Masks {
|
||||
public Mask tryOr(Mask other) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class AlwaysFalse implements Mask, Mask2D {
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -170,6 +176,11 @@ public final class Masks {
|
||||
public Mask tryOr(Mask other) {
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MutableVector3;
|
||||
import com.sk89q.worldedit.math.noise.NoiseGenerator;
|
||||
@ -85,7 +86,7 @@ public class NoiseFilter extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return noiseGenerator.noise(MutableVector3.get(vector.getX(), vector.getY(), vector.getZ())) <= density;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.noise.NoiseGenerator;
|
||||
|
||||
@ -83,7 +84,7 @@ public class NoiseFilter2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 pos) {
|
||||
public boolean test(Extent extent, BlockVector2 pos) {
|
||||
return noiseGenerator.noise(pos.toVector2()) <= density;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -86,8 +87,8 @@ public class OffsetMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return getMask().test(vector.add(offset));
|
||||
public boolean test(Extent extent, BlockVector3 pos) {
|
||||
return getMask().test(extent, pos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -21,7 +21,9 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector2;
|
||||
|
||||
/**
|
||||
* Checks whether another mask tests true for a position that is offset
|
||||
@ -31,6 +33,7 @@ public class OffsetMask2D extends AbstractMask2D {
|
||||
|
||||
private Mask2D mask;
|
||||
private BlockVector2 offset;
|
||||
private MutableBlockVector2 mutable;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -43,6 +46,7 @@ public class OffsetMask2D extends AbstractMask2D {
|
||||
checkNotNull(offset);
|
||||
this.mask = mask;
|
||||
this.offset = offset;
|
||||
this.mutable = new MutableBlockVector2();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,8 +88,9 @@ public class OffsetMask2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector2 vector) {
|
||||
return getMask().test(vector.add(offset));
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
mutable.setComponents(vector.getX() + offset.getX(), vector.getZ() + offset.getZ());
|
||||
return getMask().test(extent, mutable);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import javax.annotation.Nullable;
|
||||
@ -61,7 +62,7 @@ public class RegionMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return region.contains(vector);
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ public class SingleBlockStateMask extends ABlockMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return ordinal == vector.getOrdinal(getExtent());
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return ordinal == vector.getOrdinal(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -15,11 +14,6 @@ public class SingleBlockTypeMask extends ABlockMask {
|
||||
this.internalId = type.getInternalId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(vector.getBlock(getExtent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean test(BlockState state) {
|
||||
return state.getBlockType().getInternalId() == internalId;
|
||||
|
@ -317,7 +317,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
}
|
||||
if (sourceMask != Masks.alwaysTrue()) {
|
||||
new MaskTraverser(sourceMask).reset(transExt);
|
||||
copy = new RegionMaskingFilter(sourceMask, copy);
|
||||
copy = new RegionMaskingFilter(source, sourceMask, copy);
|
||||
}
|
||||
if (copyingBiomes && source.isWorld() || (source instanceof Clipboard && ((Clipboard) source).hasBiomes())) {
|
||||
copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
|
||||
@ -371,7 +371,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
}
|
||||
if (sourceMask != Masks.alwaysTrue()) {
|
||||
if (maskFunc != null) copy = new RegionMaskTestFunction(sourceMask, copy, maskFunc);
|
||||
else copy = new RegionMaskingFilter(sourceMask, copy);
|
||||
else copy = new RegionMaskingFilter(source, sourceMask, copy);
|
||||
}
|
||||
if (copyingBiomes && source.isWorld() || (source instanceof Clipboard && ((Clipboard) source).hasBiomes())) {
|
||||
copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
|
||||
|
Reference in New Issue
Block a user