mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 12:36:40 +00:00
More work on masks (#607)
* Add a #air mask, the opposite of #existing (#1511) (cherry picked from commit 84fa2bbbc63de7bece01f41c0d5cb7d85cf129e6) * Remove unused methods in Mask.java * Remove `test(Extent, BlockVector3)` from Masks. This was a poorly planned idea. This should save some memory too. Authored-by: Matthew Miller <mnmiller1@me.com>
This commit is contained in:
@ -144,13 +144,13 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
|
||||
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
|
||||
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* An {@link Extent} that handles history, {@link BlockBag}s, change limits,
|
||||
@ -804,7 +804,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
*/
|
||||
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
|
||||
for (int y = maxY; y >= minY; --y) {
|
||||
if (filter.test(getExtent(), mutablebv.setComponents(x, y, z))) {
|
||||
if (filter.test(mutablebv.setComponents(x, y, z))) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@ -1135,7 +1135,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
if (direction.equals(BlockVector3.at(0, -1, 0))) {
|
||||
return fillXZ(origin, pattern, radius, depth, false);
|
||||
}
|
||||
Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this))).withExtent(getExtent());
|
||||
Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this)));
|
||||
// Want to replace blocks
|
||||
final BlockReplace replace = new BlockReplace(EditSession.this, pattern);
|
||||
|
||||
@ -1187,7 +1187,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
new BoundedHeightMask(
|
||||
Math.max(origin.getBlockY() - depth + 1, getMinimumPoint().getBlockY()),
|
||||
Math.min(getMaxY(), origin.getBlockY())),
|
||||
Masks.negate(new ExistingBlockMask(this))).withExtent(getExtent());
|
||||
Masks.negate(new ExistingBlockMask(this)));
|
||||
// Want to replace blocks
|
||||
BlockReplace replace = new BlockReplace(this, pattern);
|
||||
|
||||
@ -1399,7 +1399,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
} else {
|
||||
replaceBlocks(region, new Mask() {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 position) {
|
||||
public boolean test(BlockVector3 position) {
|
||||
int x = position.getBlockX();
|
||||
int z = position.getBlockZ();
|
||||
return !region.contains(x, z + 1) || !region.contains(x, z - 1) || !region
|
||||
@ -1660,7 +1660,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
Mask mask = new MaskIntersection(
|
||||
new BoundedHeightMask(0, getWorld().getMaxY()),
|
||||
new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
|
||||
liquidMask).withExtent(getExtent());
|
||||
liquidMask);
|
||||
BlockReplace replace;
|
||||
if (waterlogged) {
|
||||
replace = new BlockReplace(this, new WaterloggedRemover(this));
|
||||
@ -1671,7 +1671,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
|
||||
// Around the origin in a 3x3 block
|
||||
for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) {
|
||||
if (mask.test(getExtent(), position)) {
|
||||
if (mask.test(position)) {
|
||||
visitor.visit(position);
|
||||
}
|
||||
}
|
||||
@ -1705,13 +1705,13 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
new BoundedHeightMask(0, Math.min(origin.getBlockY(), getWorld().getMaxY())),
|
||||
new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
|
||||
blockMask
|
||||
).withExtent(getExtent());
|
||||
);
|
||||
BlockReplace replace = new BlockReplace(this, fluid.getDefaultState());
|
||||
NonRisingVisitor visitor = new NonRisingVisitor(mask, replace);
|
||||
|
||||
// Around the origin in a 3x3 block
|
||||
for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) {
|
||||
if (liquidMask.test(getExtent(), position)) {
|
||||
if (liquidMask.test(position)) {
|
||||
visitor.visit(position);
|
||||
}
|
||||
}
|
||||
@ -2890,7 +2890,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
while (iter.hasNext()) {
|
||||
final BlockVector3 current = iter.next();
|
||||
iter.remove();
|
||||
if (mask.test(getExtent(), current)) {
|
||||
if (mask.test(current)) {
|
||||
continue;
|
||||
}
|
||||
if (!outside.add(current)) {
|
||||
|
@ -53,6 +53,8 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.internal.registry.AbstractFactory;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -76,6 +78,7 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
super(worldEdit, new BlocksMaskParser(worldEdit));
|
||||
|
||||
register(new ExistingMaskParser(worldEdit));
|
||||
register(new AirMaskParser(worldEdit));
|
||||
register(new SolidMaskParser(worldEdit));
|
||||
register(new LazyRegionMaskParser(worldEdit));
|
||||
register(new RegionMaskParser(worldEdit));
|
||||
@ -84,11 +87,11 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
register(new BlockStateMaskParser(worldEdit));
|
||||
register(new NegateMaskParser(worldEdit));
|
||||
register(new ExpressionMaskParser(worldEdit));
|
||||
|
||||
register(new BlockCategoryMaskParser(worldEdit));
|
||||
register(new BiomeMaskParser(worldEdit));
|
||||
// Mask Parsers from FAWE
|
||||
register(new AdjacentMaskParser(worldEdit));
|
||||
register(new AirMaskParser(worldEdit));
|
||||
register(new AngleMaskParser(worldEdit));
|
||||
register(new ExtremaMaskParser(worldEdit));
|
||||
register(new FalseMaskParser(worldEdit));
|
||||
@ -124,18 +127,23 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
continue;
|
||||
}
|
||||
|
||||
Mask match = null;
|
||||
for (InputParser<Mask> parser : getParsers()) {
|
||||
Mask match = parser.parseFromInput(component, context);
|
||||
match = parser.parseFromInput(component, context);
|
||||
|
||||
if (match != null) {
|
||||
masks.add(match);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(component)));
|
||||
}
|
||||
masks.add(match);
|
||||
}
|
||||
|
||||
switch (masks.size()) {
|
||||
case 0:
|
||||
throw new NoMatchException("No match for '" + input + "'");
|
||||
throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(input)));
|
||||
case 1:
|
||||
return masks.get(0).optimize();
|
||||
default:
|
||||
|
@ -1,10 +1,31 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.function.mask.AirMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
@ -23,7 +44,7 @@ public class AirMaskParser extends SimpleInputParser<Mask> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new AirMask(context.getExtent());
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
|
||||
return Masks.negate(new ExistingBlockMask(context.requireExtent()));
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,6 @@ public class ZAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new ZAxisMask(context.getExtent());
|
||||
return new ZAxisMask();
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
maxY = Math.min(maxY, Math.max(0, maxY));
|
||||
minY = Math.max(0, minY);
|
||||
for (int y = maxY; y >= minY; --y) {
|
||||
if (filter.test(this, MutableBlockVector3.get(x, y, z))) {
|
||||
if (filter.test(MutableBlockVector3.get(x, y, z))) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@ -276,22 +276,22 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
int clearanceAbove = maxY - y;
|
||||
int clearanceBelow = y - minY;
|
||||
int clearance = Math.min(clearanceAbove, clearanceBelow);
|
||||
boolean state = !mask.test(this, MutableBlockVector3.get(x, y, z));
|
||||
boolean state = !mask.test(MutableBlockVector3.get(x, y, z));
|
||||
int offset = state ? 0 : 1;
|
||||
for (int d = 0; d <= clearance; d++) {
|
||||
int y1 = y + d;
|
||||
if (mask.test(this, MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset;
|
||||
if (mask.test(MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset;
|
||||
int y2 = y - d;
|
||||
if (mask.test(this, MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset;
|
||||
if (mask.test(MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset;
|
||||
}
|
||||
if (clearanceAbove != clearanceBelow) {
|
||||
if (clearanceAbove < clearanceBelow) {
|
||||
for (int layer = y - clearance - 1; layer >= minY; layer--) {
|
||||
if (mask.test(this, MutableBlockVector3.get(x, layer, z)) != state) return layer + offset;
|
||||
if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer + offset;
|
||||
}
|
||||
} else {
|
||||
for (int layer = y + clearance + 1; layer <= maxY; layer++) {
|
||||
if (mask.test(this, MutableBlockVector3.get(x, layer, z)) != state) return layer - offset;
|
||||
if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer - offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -508,7 +508,7 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
* @return the number of blocks that matched the mask
|
||||
*/
|
||||
default int countBlocks(Region region, Mask searchMask) {
|
||||
RegionVisitor visitor = new RegionVisitor(region, position -> searchMask.test(this, position));
|
||||
RegionVisitor visitor = new RegionVisitor(region, position -> searchMask.test(position));
|
||||
Operations.completeBlindly(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
|
@ -79,17 +79,17 @@ public class MaskingExtent extends AbstractDelegateExtent implements IBatchProce
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
return mask.test(getExtent(), location) && super.setBlock(location, block);
|
||||
return mask.test(location) && super.setBlock(location, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(BlockVector2 position, BiomeType biome) {
|
||||
return mask.test(getExtent(), position.toBlockVector3()) && super.setBiome(position, biome);
|
||||
return mask.test(position.toBlockVector3()) && super.setBiome(position, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
return mask.test(getExtent(), BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome);
|
||||
return mask.test(BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,7 +102,7 @@ public class MaskingExtent extends AbstractDelegateExtent implements IBatchProce
|
||||
public void applyBlock(FilterBlock block) {
|
||||
//TODO: Find a way to make masking thread safe without having to synchonise the whole extent
|
||||
synchronized (this) {
|
||||
if (!mask.test(getExtent(), block)) {
|
||||
if (!mask.test(block)) {
|
||||
block.setOrdinal(0);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class ExtentBuffer extends AbstractBufferingExtent {
|
||||
|
||||
@Override
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
|
||||
if (mask.test(getExtent(), location)) {
|
||||
if (mask.test(location)) {
|
||||
buffer.put(location, block.toBaseBlock());
|
||||
return true;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
max = max.getMaximum(location);
|
||||
}
|
||||
|
||||
if (mask.test(getExtent(), location)) {
|
||||
if (mask.test( location)) {
|
||||
buffer.put(location, block.toBaseBlock());
|
||||
return true;
|
||||
} else {
|
||||
@ -131,7 +131,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
max2d = max2d.getMaximum(position);
|
||||
}
|
||||
|
||||
if (biomeMask.test(getExtent(), position)) {
|
||||
if (biomeMask.test(position)) {
|
||||
biomeBuffer.put(position, biome);
|
||||
return true;
|
||||
} else {
|
||||
@ -155,7 +155,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
max2d = max2d.getMaximum(BlockVector2.at(x,z));
|
||||
}
|
||||
|
||||
if (biomeMask.test(getExtent(), BlockVector2.at(x,z))) {
|
||||
if (biomeMask.test(BlockVector2.at(x,z))) {
|
||||
biomeBuffer.put(BlockVector2.at(x,z), biome);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.function;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -53,7 +52,7 @@ public class RegionMaskTestFunction implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
if (mask.test(NullExtent.INSTANCE, position)) {
|
||||
if (mask.test(position)) {
|
||||
return pass.apply(position);
|
||||
} else {
|
||||
return fail.apply(position);
|
||||
|
@ -54,7 +54,7 @@ public class RegionMaskingFilter implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
return mask.test(extent, position) && function.apply(position);
|
||||
return mask.test(position) && function.apply(position);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class Naturalizer implements LayerFunction {
|
||||
|
||||
@Override
|
||||
public boolean isGround(BlockVector3 position) {
|
||||
return mask.test(editSession, position);
|
||||
return mask.test(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(editSession, position)) {
|
||||
if (mask.test(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(extent, mutable.setComponents(x, y, z))) {
|
||||
if (!mask.test(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(extent, mutable))
|
||||
if (mask.test(mutable))
|
||||
pattern.apply(extent, mutable, mutable);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,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(extent, mutable)) {
|
||||
if (!mask.test(mutable)) {
|
||||
return false;
|
||||
}
|
||||
mutable.mutY(y + 1);
|
||||
|
@ -15,8 +15,8 @@ public abstract class ABlockMask extends AbstractExtentMask {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
@Override public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent));
|
||||
@Override public boolean test(BlockVector3 vector) {
|
||||
return test(getExtent().getBlock(vector));
|
||||
}
|
||||
|
||||
public abstract boolean test(BlockState state);
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -40,10 +39,6 @@ public abstract class AbstractExtentMask extends AbstractMask {
|
||||
setExtent(extent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(getExtent(), vector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extent.
|
||||
@ -64,9 +59,4 @@ public abstract class AbstractExtentMask extends AbstractMask {
|
||||
this.extent = extent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
setExtent(extent);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A base class of {@link Mask} that all masks should inherit from.
|
||||
*/
|
||||
public abstract class AbstractMask implements Mask, Serializable {
|
||||
public abstract class AbstractMask implements Mask {
|
||||
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class BiomeMask2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
public boolean test(BlockVector2 vector) {
|
||||
BiomeType biome = extent.getBiome(vector);
|
||||
return biomes.contains(biome);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class BlockCategoryMask extends AbstractExtentMask {
|
||||
|
||||
private BlockCategory category;
|
||||
private final BlockCategory category;
|
||||
|
||||
public BlockCategoryMask(Extent extent, BlockCategory category) {
|
||||
super(extent);
|
||||
@ -42,8 +42,8 @@ public class BlockCategoryMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return category.contains(vector.getBlock(extent));
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return category.contains(getExtent().getBlock(vector));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -188,8 +188,8 @@ public class BlockMask extends ABlockMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
int test = vector.getOrdinal(extent);
|
||||
public boolean test(BlockVector3 vector) {
|
||||
int test = getExtent().getBlock(vector).getOrdinal();
|
||||
return ordinals[test] || replacesAir() && test == 0;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class BlockStateMask extends AbstractExtentMask {
|
||||
|
||||
private final Map<String, String> states;
|
||||
private final boolean strict;
|
||||
private Map<BlockType, Map<Property<Object>, Object>> cache = Maps.newHashMap();
|
||||
private final Map<BlockType, Map<Property<Object>, Object>> cache = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* Creates a mask that checks if a given block has the desired properties set to the desired value.
|
||||
@ -53,8 +53,8 @@ public class BlockStateMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent));
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(getExtent().getBlock(vector));
|
||||
}
|
||||
|
||||
public boolean test(BlockState block) {
|
||||
|
@ -110,8 +110,8 @@ public class BlockTypeMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent).getBlockType());
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(getExtent().getBlock(vector).getBlockType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -48,7 +47,7 @@ public class BoundedHeightMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return vector.getY() >= minY && vector.getY() <= maxY;
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,11 @@
|
||||
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) {
|
||||
public DelegateExtentMask(Mask parent) {
|
||||
super(parent);
|
||||
this.extent = extent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return super.test(extent, vector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
return new DelegateExtentMask(extent, getMask());
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ public class ExistingBlockMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return !vector.getBlock(extent).getMaterial().isAir();
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.expression.EvaluationException;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
@ -68,7 +67,7 @@ public class ExpressionMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
try {
|
||||
if (expression.getEnvironment() instanceof WorldEditExpressionEnvironment) {
|
||||
((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector.toVector3());
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.expression.EvaluationException;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
@ -61,7 +60,7 @@ public class ExpressionMask2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
public boolean test(BlockVector2 vector) {
|
||||
try {
|
||||
if (timeout == null) {
|
||||
return expression.evaluate(vector.getX(), 0, vector.getZ()) > 0;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -13,8 +12,8 @@ public class InverseMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 pos) {
|
||||
return !mask.test(extent, pos);
|
||||
public boolean test(BlockVector3 pos) {
|
||||
return !mask.test(pos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -19,8 +19,8 @@ public class InverseSingleBlockStateMask extends ABlockMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
int test = vector.getOrdinal(extent);
|
||||
public boolean test(BlockVector3 vector) {
|
||||
int test = getExtent().getBlock(vector).getOrdinal();
|
||||
if (isAir && test == 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -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 InverseSingleBlockTypeMask extends ABlockMask {
|
||||
this.internalId = type.getInternalId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(vector.getBlock(extent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean test(BlockState state) {
|
||||
return state.getBlockType().getInternalId() != internalId;
|
||||
|
@ -22,10 +22,7 @@ package com.sk89q.worldedit.function.mask;
|
||||
import com.boydti.fawe.beta.Filter;
|
||||
import com.boydti.fawe.beta.implementation.filter.MaskFilter;
|
||||
import com.boydti.fawe.beta.implementation.filter.block.FilterBlock;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@ -41,26 +38,12 @@ public interface Mask {
|
||||
* @param vector the vector to test
|
||||
* @return true if the criteria is met
|
||||
*/
|
||||
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);
|
||||
}
|
||||
boolean test(BlockVector3 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.
|
||||
*
|
||||
@ -94,16 +77,6 @@ public interface Mask {
|
||||
return value == null ? this : value;
|
||||
}
|
||||
|
||||
default Mask and(Mask other) {
|
||||
Mask value = and(other);
|
||||
return value == null ? MaskIntersection.of(this, other) : value;
|
||||
}
|
||||
|
||||
default Mask or(Mask other) {
|
||||
Mask value = or(other);
|
||||
return value == null ? MaskUnion.of(this, other) : value;
|
||||
}
|
||||
|
||||
default Mask inverse() {
|
||||
if (this instanceof Masks.AlwaysTrue) {
|
||||
return Masks.ALWAYS_FALSE;
|
||||
@ -117,7 +90,7 @@ public interface Mask {
|
||||
return new Filter() {
|
||||
@Override
|
||||
public void applyBlock(FilterBlock block) {
|
||||
if (test(block, block)) {
|
||||
if (test(block)) {
|
||||
run.accept(block);
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,7 @@
|
||||
|
||||
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.
|
||||
@ -35,16 +32,6 @@ public interface Mask2D {
|
||||
* @param vector the vector to test
|
||||
* @return true if the criteria is met
|
||||
*/
|
||||
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);
|
||||
}
|
||||
boolean test(BlockVector2 vector);
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
@ -226,9 +225,9 @@ public class MaskIntersection extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
for (Mask mask : masksArray) {
|
||||
if (!mask.test(extent, vector)) {
|
||||
if (!mask.test( vector)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -84,13 +83,13 @@ public class MaskIntersection2D implements Mask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
public boolean test(BlockVector2 vector) {
|
||||
if (masks.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Mask2D mask : masks) {
|
||||
if (!mask.test(extent, vector)) {
|
||||
if (!mask.test(vector)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -86,11 +85,11 @@ public class MaskUnion extends MaskIntersection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
Mask[] masks = getMasksArray();
|
||||
|
||||
for (Mask mask : masks) {
|
||||
if (mask.test(extent, vector)) {
|
||||
if (mask.test(vector)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -48,11 +47,11 @@ public class MaskUnion2D extends MaskIntersection2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
public boolean test(BlockVector2 vector) {
|
||||
Collection<Mask2D> masks = getMasks();
|
||||
|
||||
for (Mask2D mask : masks) {
|
||||
if (mask.test(extent, vector)) {
|
||||
if (mask.test(vector)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -43,7 +42,7 @@ public final class Masks {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 3D mask that always returns true;
|
||||
* Return a 3D mask that always returns true.
|
||||
*
|
||||
* @return a mask
|
||||
*/
|
||||
@ -56,7 +55,7 @@ public final class Masks {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 2D mask that always returns true;
|
||||
* Return a 2D mask that always returns true.
|
||||
*
|
||||
* @return a mask
|
||||
*/
|
||||
@ -90,8 +89,8 @@ public final class Masks {
|
||||
checkNotNull(mask);
|
||||
return new AbstractMask2D() {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
return !mask.test(extent, vector);
|
||||
public boolean test(BlockVector2 vector) {
|
||||
return !mask.test(vector);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -105,8 +104,8 @@ public final class Masks {
|
||||
public static Mask asMask(final Mask2D mask) {
|
||||
return new AbstractMask() {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return mask.test(extent, vector.toBlockVector2());
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return mask.test(vector.toBlockVector2());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -119,12 +118,12 @@ public final class Masks {
|
||||
|
||||
protected static class AlwaysTrue implements Mask, Mask2D {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
public boolean test(BlockVector2 vector) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -144,20 +143,16 @@ public final class Masks {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class AlwaysFalse implements Mask, Mask2D {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
public boolean test(BlockVector2 vector) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -177,10 +172,6 @@ public final class Masks {
|
||||
return other;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
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;
|
||||
@ -87,7 +86,7 @@ public class NoiseFilter extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return noiseGenerator.noise(MutableVector3.get(vector.getX(), vector.getY(), vector.getZ())) <= density;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.noise.NoiseGenerator;
|
||||
|
||||
@ -84,7 +83,7 @@ public class NoiseFilter2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 pos) {
|
||||
public boolean test(BlockVector2 pos) {
|
||||
return noiseGenerator.noise(pos.toVector2()) <= density;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -87,12 +86,12 @@ public class OffsetMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 pos) {
|
||||
BlockVector3 testPos = pos.add(offset);
|
||||
public boolean test(BlockVector3 vector) {
|
||||
BlockVector3 testPos = vector.add(offset);
|
||||
if (testPos.getBlockY() < 0 || testPos.getBlockY() > 255) {
|
||||
return false;
|
||||
}
|
||||
return getMask().test(extent, pos.add(offset));
|
||||
return getMask().test(vector.add(offset));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector2;
|
||||
|
||||
@ -88,9 +87,9 @@ public class OffsetMask2D extends AbstractMask2D {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector2 vector) {
|
||||
public boolean test(BlockVector2 vector) {
|
||||
mutable.setComponents(vector.getX() + offset.getX(), vector.getZ() + offset.getZ());
|
||||
return getMask().test(extent, mutable);
|
||||
return getMask().test(mutable);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
@ -63,7 +62,7 @@ public class RegionMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return region.contains(vector);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ public class SingleBlockStateMask extends ABlockMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
int test = vector.getOrdinal(extent);
|
||||
public boolean test(BlockVector3 vector) {
|
||||
int test = getExtent().getBlock(vector).getOrdinal();
|
||||
return ordinal == test || isAir && test == 0;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class SnapshotRestore {
|
||||
}
|
||||
|
||||
private void checkAndAddBlock(BlockVector3 pos) {
|
||||
if (editSession.getMask() != null && !editSession.getMask().test(editSession, pos))
|
||||
if (editSession.getMask() != null && !editSession.getMask().test(pos))
|
||||
return;
|
||||
|
||||
BlockVector2 chunkPos = ChunkStore.toChunk(pos);
|
||||
|
Reference in New Issue
Block a user