Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-10 13:30:05 +01:00
Make masks more stateless
Dieser Commit ist enthalten in:
Ursprung
9efdd886c5
Commit
88a95221a8
@ -319,7 +319,6 @@ public final class FAWE_Spigot_v1_13_R2 extends CachedBukkitAdapter implements I
|
||||
BlockMaterial_1_13 material = (BlockMaterial_1_13) state.getMaterial();
|
||||
return material.getCraftBlockData();
|
||||
} catch (ClassCastException ignore) {
|
||||
System.out.println(state.getAsString() + " cast");
|
||||
throw ignore;
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,8 @@ public abstract class AbstractFilterBlock extends FilterBlock {
|
||||
public abstract BaseBlock getFullBlock();
|
||||
public abstract void setFullBlock(BaseBlock block);
|
||||
public abstract BlockVector3 getPosition();
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return this;
|
||||
}
|
||||
public abstract Extent getExtent();
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
|
@ -19,9 +19,7 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock {
|
||||
private final int yOffset;
|
||||
private final int width, length;
|
||||
private int x, z, index;
|
||||
private char ordinal;
|
||||
|
||||
// TODO use in CFI
|
||||
public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length,
|
||||
int yOffset) {
|
||||
super(extent);
|
||||
@ -32,18 +30,16 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock {
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
public void filter2D(Filter filter) {
|
||||
for (z = 0; z < length; z++) {
|
||||
for (x = 0; x < width; x++, index++) {
|
||||
ordinal = blocks[ordinal];
|
||||
filter.applyBlock(this);
|
||||
}
|
||||
}
|
||||
public void init(int x, int z, int index) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
return ordinal;
|
||||
return blocks[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,7 +49,7 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock {
|
||||
|
||||
@Override
|
||||
public BlockState getBlock() {
|
||||
return BlockTypesCache.states[ordinal];
|
||||
return BlockTypesCache.states[getOrdinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,4 +32,9 @@ public class ExtentFilterBlock extends AbstractFilterBlock {
|
||||
public BlockVector3 getPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.boydti.fawe.beta.implementation.filter.block;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MultiFilterBlock extends DelegateFilterBlock {
|
||||
private final FilterBlock[] blocks;
|
||||
private final int length;
|
||||
|
||||
public MultiFilterBlock(FilterBlock... blocks) {
|
||||
super(blocks[0]);
|
||||
this.blocks = blocks;
|
||||
this.length = blocks.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrdinal(int ordinal) {
|
||||
for (int i = 0; i < length; i++) blocks[i].setOrdinal(ordinal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(BlockState state) {
|
||||
for (int i = 0; i < length; i++) blocks[i].setBlock(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullBlock(BaseBlock block) {
|
||||
for (int i = 0; i < length; i++) blocks[i].setFullBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(@Nullable CompoundTag nbtData) {
|
||||
for (int i = 0; i < length; i++) blocks[i].setNbtData(nbtData);
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.boydti.fawe.beta.implementation.filter.block;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
public class VectorSingleFilterBlock extends AbstractSingleFilterBlock {
|
||||
private final BlockVector3 mutable;
|
||||
|
||||
public VectorSingleFilterBlock(BlockVector3 mutable) {
|
||||
this.mutable = mutable;
|
||||
}
|
||||
|
||||
public VectorSingleFilterBlock init(BaseBlock block) {
|
||||
super.init(block);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return mutable.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return mutable.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return mutable.getZ();
|
||||
}
|
||||
}
|
@ -456,7 +456,7 @@ public class CFICommands {
|
||||
for (int typeId : tu.getValidBlockIds()) {
|
||||
BlockType type = BlockTypes.get(typeId);
|
||||
extent.init(0, 0, 0, type.getDefaultState().toBaseBlock());
|
||||
if (mask.test(extent)) {
|
||||
if (mask.test(extent, extent)) {
|
||||
blocks.add(type);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.boydti.fawe.object.brush;
|
||||
|
||||
import com.boydti.fawe.config.Caption;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.DelegateExtentMask;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualExtent;
|
||||
import com.boydti.fawe.object.clipboard.ResizableClipboardBuilder;
|
||||
@ -64,11 +66,11 @@ public class CopyPastaBrush implements Brush, ResettableTool {
|
||||
}
|
||||
final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld());
|
||||
final int minY = position.getBlockY();
|
||||
mask = new AbstractDelegateMask(mask) {
|
||||
mask = new DelegateExtentMask(editSession, mask) {
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
if (super.test(vector) && vector.getBlockY() >= minY) {
|
||||
BaseBlock block = editSession.getFullBlock(vector);
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (super.test(extent, vector) && vector.getBlockY() >= minY) {
|
||||
BaseBlock block = vector.getFullBlock(editSession);
|
||||
if (!block.getBlockType().getMaterial().isAir()) {
|
||||
builder.add(vector, BlockTypes.AIR.getDefaultState().toBaseBlock(), block);
|
||||
return true;
|
||||
@ -78,7 +80,7 @@ public class CopyPastaBrush implements Brush, ResettableTool {
|
||||
}
|
||||
};
|
||||
// Add origin
|
||||
mask.test(position);
|
||||
mask.test(editSession, position);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size);
|
||||
visitor.visit(position);
|
||||
Operations.completeBlindly(visitor);
|
||||
|
@ -8,6 +8,7 @@ import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -86,11 +87,11 @@ public class ImageBrush implements Brush {
|
||||
float pitch = loc.getPitch();
|
||||
AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX((pitch - 90) % 360).inverse();
|
||||
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new Mask() {
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) {
|
||||
private final MutableVector3 mutable = new MutableVector3();
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
if (solid.test(vector)) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (solid.test(extent, vector)) {
|
||||
int dx = vector.getBlockX() - cx;
|
||||
int dy = vector.getBlockY() - cy;
|
||||
int dz = vector.getBlockZ() - cz;
|
||||
|
@ -6,7 +6,10 @@ import com.boydti.fawe.object.mask.RadiusMask;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SolidBlockMask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -34,12 +37,19 @@ public class LayerBrush implements Brush {
|
||||
final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockMask(editSession).add(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR));
|
||||
final SolidBlockMask solid = new SolidBlockMask(editSession);
|
||||
final RadiusMask radius = new RadiusMask(0, (int) size);
|
||||
visitor = new RecursiveVisitor(vector -> solid.test(vector) && radius.test(vector) && adjacent.test(vector), function -> true);
|
||||
visitor = new RecursiveVisitor(new Mask() {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return solid.test(extent, vector) && radius.test(extent, vector) && adjacent.test(extent, vector);
|
||||
}
|
||||
}, function -> true);
|
||||
visitor.visit(position);
|
||||
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
|
||||
Operations.completeBlindly(visitor);
|
||||
BlockVectorSet visited = visitor.getVisited();
|
||||
visitor = new RecursiveVisitor(pos -> {
|
||||
visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 pos) {
|
||||
int depth = visitor.getDepth() + 1;
|
||||
if (depth > 1) {
|
||||
boolean found = false;
|
||||
@ -61,7 +71,8 @@ public class LayerBrush implements Brush {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !adjacent.test(pos);
|
||||
return !adjacent.test(extent, pos);
|
||||
}
|
||||
}, pos -> {
|
||||
int depth = visitor.getDepth();
|
||||
BlockStateHolder currentPattern = layers[depth];
|
||||
|
@ -6,6 +6,7 @@ import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.function.block.BlockReplace;
|
||||
import com.sk89q.worldedit.function.mask.DelegateExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
@ -27,6 +28,8 @@ public class RecurseBrush implements Brush {
|
||||
Mask mask = editSession.getMask();
|
||||
if (mask == null) {
|
||||
mask = Masks.alwaysTrue();
|
||||
} else {
|
||||
mask = mask.withExtent(editSession);
|
||||
}
|
||||
final int radius = (int) size;
|
||||
BlockStateHolder block = editSession.getBlock(position);
|
||||
@ -42,7 +45,7 @@ public class RecurseBrush implements Brush {
|
||||
@Override
|
||||
public boolean isVisitable(BlockVector3 from, BlockVector3 to) {
|
||||
int y = to.getBlockY();
|
||||
return y < maxY && radMask.test(to) && super.isVisitable(from, to);
|
||||
return y < maxY && radMask.test(editSession, to) && super.isVisitable(from, to);
|
||||
}
|
||||
};
|
||||
visitor.visit(position);
|
||||
|
@ -8,7 +8,11 @@ import com.boydti.fawe.object.mask.SurfaceMask;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.DelegateExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskUnion;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -50,7 +54,7 @@ public class ScatterBrush implements Brush {
|
||||
|
||||
final int distance = Math.min((int) size, this.distance);
|
||||
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(vector -> radius.test(vector) && surface.test(vector), function -> true);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new MaskUnion(radius, surface).withExtent(editSession), function -> true);
|
||||
visitor.visit(position);
|
||||
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
|
||||
Operations.completeBlindly(visitor);
|
||||
@ -87,11 +91,11 @@ public class ScatterBrush implements Brush {
|
||||
}
|
||||
|
||||
public boolean canApply(EditSession editSession, BlockVector3 pos) {
|
||||
return mask.test(pos);
|
||||
return mask.test(editSession, pos);
|
||||
}
|
||||
|
||||
public BlockVector3 getDirection(BlockVector3 pt) {
|
||||
return surface.direction(pt);
|
||||
public BlockVector3 getDirection(Extent extent, BlockVector3 pt) {
|
||||
return surface.direction(extent, pt);
|
||||
}
|
||||
|
||||
public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pt, Pattern p, double size) throws MaxChangedBlocksException {
|
||||
|
@ -16,7 +16,7 @@ public class ScatterOverlayBrush extends ScatterBrush {
|
||||
int x = pt.getBlockX();
|
||||
int y = pt.getBlockY();
|
||||
int z = pt.getBlockZ();
|
||||
BlockVector3 dir = getDirection(pt);
|
||||
BlockVector3 dir = getDirection(editSession, pt);
|
||||
editSession.setBlock(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ(), p);
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class ShatterBrush extends ScatterBrush {
|
||||
int dSqr = (dx * dx) + (dy * dy) + (dz * dz);
|
||||
if (dSqr <= radius2) {
|
||||
BlockVector3 bv = mutable.setComponents(x2, y2, z2);
|
||||
if (surfaceTest.test(bv) && finalMask.test(bv)) {
|
||||
if (surfaceTest.test(editSession, bv) && finalMask.test(editSession, bv)) {
|
||||
// (collision) If it's visited and part of another frontier, set the block
|
||||
if (!placed.add(x2, y2, z2)) {
|
||||
if (!frontierVisited.contains(x2, y2, z2)) {
|
||||
|
@ -5,6 +5,9 @@ import com.boydti.fawe.object.mask.SurfaceMask;
|
||||
import com.boydti.fawe.object.pattern.BiomePattern;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.visitor.BreadthFirstSearch;
|
||||
@ -40,14 +43,17 @@ public class SplatterBrush extends ScatterBrush {
|
||||
final int size2 = (int) (size * size);
|
||||
SurfaceMask surface = new SurfaceMask(editSession);
|
||||
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(vector -> {
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
double dist = vector.distanceSq(position);
|
||||
if (dist < size2 && !placed.contains(vector) && ThreadLocalRandom.current().nextInt(5) < 2
|
||||
&& surface.test(vector)) {
|
||||
&& surface.test(extent, vector)) {
|
||||
placed.add(vector);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, vector -> editSession.setBlock(vector, finalPattern), recursion);
|
||||
visitor.setMaxBranch(2);
|
||||
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.boydti.fawe.object.brush;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.sk89q.worldedit.function.mask.DelegateExtentMask;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualExtent;
|
||||
import com.boydti.fawe.object.mask.IdMask;
|
||||
@ -52,6 +53,7 @@ public class SplineBrush implements Brush, ResettableTool {
|
||||
} else {
|
||||
mask = new MaskIntersection(mask, new IdMask(editSession));
|
||||
}
|
||||
mask = mask.withExtent(editSession);
|
||||
boolean visualization = editSession.getExtent() instanceof VisualExtent;
|
||||
if (visualization && positionSets.isEmpty()) {
|
||||
return;
|
||||
|
@ -5,7 +5,9 @@ import com.boydti.fawe.object.mask.AdjacentAnyMask;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.mask.SolidBlockMask;
|
||||
@ -61,10 +63,10 @@ public class StencilBrush extends HeightBrush {
|
||||
AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX(pitch - 90).inverse();
|
||||
|
||||
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new Mask() {
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) {
|
||||
private final MutableVector3 mutable = new MutableVector3();
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (solid.test(vector)) {
|
||||
int dx = vector.getBlockX() - cx;
|
||||
int dy = vector.getBlockY() - cy;
|
||||
|
@ -5,6 +5,8 @@ import com.boydti.fawe.object.mask.SurfaceMask;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.function.mask.DelegateExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.MaskUnion;
|
||||
import com.sk89q.worldedit.function.mask.SolidBlockMask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -20,7 +22,7 @@ public class SurfaceSphereBrush implements Brush {
|
||||
SurfaceMask surface = new SurfaceMask(editSession);
|
||||
final SolidBlockMask solid = new SolidBlockMask(editSession);
|
||||
final RadiusMask radius = new RadiusMask(0, (int) size);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(vector -> surface.test(vector) && radius.test(vector), vector -> editSession.setBlock(vector, pattern));
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new MaskUnion(surface, radius).withExtent(editSession), vector -> editSession.setBlock(vector, pattern));
|
||||
visitor.visit(position);
|
||||
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
|
||||
Operations.completeBlindly(visitor);
|
||||
|
@ -7,6 +7,10 @@ import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.IBlocks;
|
||||
import com.boydti.fawe.beta.IChunkGet;
|
||||
import com.boydti.fawe.beta.IChunkSet;
|
||||
import com.boydti.fawe.beta.implementation.filter.block.AbstractFilterBlock;
|
||||
import com.boydti.fawe.beta.implementation.filter.block.ArrayFilterBlock;
|
||||
import com.boydti.fawe.beta.implementation.filter.block.MultiFilterBlock;
|
||||
import com.boydti.fawe.beta.implementation.filter.block.SingleFilterBlock;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.beta.implementation.blocks.FallbackChunkGet;
|
||||
import com.boydti.fawe.jnbt.anvil.MCAChunk;
|
||||
@ -34,6 +38,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
@ -54,6 +59,7 @@ import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockID;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -552,7 +558,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
int y = heights[index] & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
if (mask.test(this, mutable)) {
|
||||
int newHeight = table.average(x, z, index);
|
||||
setLayerHeightRaw(index, newHeight);
|
||||
}
|
||||
@ -607,7 +613,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
}
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (!mask.test(mutable)) {
|
||||
if (!mask.test(this, mutable)) {
|
||||
continue;
|
||||
}
|
||||
if (placed.containsRadius(x, z, distance)) {
|
||||
@ -654,7 +660,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
}
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (!mask.test(mutable)) {
|
||||
if (!mask.test(this, mutable)) {
|
||||
continue;
|
||||
}
|
||||
if (placed.containsRadius(x, z, distance)) {
|
||||
@ -1066,7 +1072,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
if (mask != null) {
|
||||
mutable.mutX(z);
|
||||
mutable.mutY(heights.getByte(index) & 0xFF);
|
||||
if (!mask.test(mutable)) continue;
|
||||
if (!mask.test(this, mutable)) continue;
|
||||
}
|
||||
if (imgMask != null) {
|
||||
int height = imgMask.getRGB(x, z) & 0xFF;
|
||||
@ -1181,7 +1187,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(heights.getByte(index) & 0xFF);
|
||||
if (mask.test(mutable)) {
|
||||
if (mask.test(this, mutable)) {
|
||||
int color = img.getRGB(x, z);
|
||||
BlockType block = textureUtil.getNearestBlock(color);
|
||||
if (block != null) {
|
||||
@ -1254,7 +1260,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
if (mask.test(this, mutable)) {
|
||||
biomes.setByte(index, biomeByte);
|
||||
}
|
||||
}
|
||||
@ -1274,17 +1280,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
}
|
||||
|
||||
overlay.record(() -> {
|
||||
char[] overlayArr = overlay.get();
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, overlay.get(), heights.get(), getWidth(), getLength(), 1);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int height = img.getRGB(x, z) & 0xFF;
|
||||
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
|
||||
.nextInt(256) <= height) {
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(height);
|
||||
overlayArr[index] = pattern.apply(mutable).getOrdinalChar();
|
||||
filter.init(x, z, index);
|
||||
pattern.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1302,17 +1306,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
primitives.modifiedMain = true;
|
||||
|
||||
main.record(() -> {
|
||||
char[] mainArr = main.get();
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int height = img.getRGB(x, z) & 0xFF;
|
||||
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
|
||||
.nextInt(256) <= height) {
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(height);
|
||||
mainArr[index] = pattern.apply(mutable).getOrdinalChar();
|
||||
filter.init(x, z, index);
|
||||
pattern.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1328,17 +1330,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
|
||||
|
||||
floor.record(() -> {
|
||||
char[] floorArr = floor.get();
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 1);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int height = img.getRGB(x, z) & 0xFF;
|
||||
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
|
||||
.nextInt(256) <= height) {
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(height);
|
||||
floorArr[index] = pattern.apply(mutable).getOrdinalChar();
|
||||
filter.init(x, z, index);
|
||||
pattern.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1355,20 +1355,20 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
primitives.modifiedMain = true;
|
||||
|
||||
main.record(() -> floor.record(() -> {
|
||||
char[] floorArr = floor.get();
|
||||
char[] mainArr = main.get();
|
||||
ArrayFilterBlock filterFloor = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0);
|
||||
ArrayFilterBlock filterMain = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1);
|
||||
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int height = img.getRGB(x, z) & 0xFF;
|
||||
if (height == 255 || height > 0 && !white && ThreadLocalRandom.current()
|
||||
.nextInt(256) <= height) {
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(height);
|
||||
char combined = pattern.apply(mutable).getOrdinalChar();
|
||||
mainArr[index] = combined;
|
||||
floorArr[index] = combined;
|
||||
filterFloor.init(x, z, index);
|
||||
filterMain.init(x, z, index);
|
||||
|
||||
pattern.apply(this, filterFloor, filterFloor);
|
||||
pattern.apply(this, filterMain, filterMain);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1380,19 +1380,20 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
if (pattern instanceof BlockStateHolder) {
|
||||
setOverlay(mask, ((BlockStateHolder) pattern).getOrdinalChar());
|
||||
} else {
|
||||
int index = 0;
|
||||
if (overlay == null) overlay = new DifferentialArray<>(new char[getArea()]);
|
||||
overlay.record(() -> {
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, overlay.get(), heights.get(), getWidth(), getLength(), 1);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
overlay.setInt(index, pattern.apply(mutable).getOrdinalChar());
|
||||
filter.init(x, z, index);
|
||||
if (mask.test(this, filter)) {
|
||||
pattern.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1400,18 +1401,18 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
if (pattern instanceof BlockStateHolder) {
|
||||
setFloor(mask, ((BlockStateHolder) pattern).getOrdinalChar());
|
||||
} else {
|
||||
floor.record(() -> {
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
floor.setInt(index, pattern.apply(mutable).getOrdinalChar());
|
||||
filter.init(x, z, index);
|
||||
if (mask.test(this, filter)) {
|
||||
pattern.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1419,19 +1420,18 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
if (pattern instanceof BlockStateHolder) {
|
||||
setMain(mask, ((BlockStateHolder) pattern).getOrdinalChar());
|
||||
} else {
|
||||
main.record(() -> {
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1);
|
||||
primitives.modifiedMain = true;
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
main.setInt(index, pattern.apply(mutable).getOrdinalChar());
|
||||
if (mask.test(this, filter)) {
|
||||
pattern.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1439,21 +1439,25 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
if (pattern instanceof BlockStateHolder) {
|
||||
setColumn(mask, ((BlockStateHolder) pattern).getOrdinalChar());
|
||||
} else {
|
||||
floor.record(() -> main.record(() -> {
|
||||
ArrayFilterBlock floorFilter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0);
|
||||
ArrayFilterBlock mainFilter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1);
|
||||
primitives.modifiedMain = true;
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
int combined = pattern.apply(mutable).getOrdinalChar();
|
||||
floor.setInt(index, combined);
|
||||
main.setInt(index, combined);
|
||||
floorFilter.init(x, z, index);
|
||||
mainFilter.init(x, z, index);
|
||||
if (mask.test(this, mainFilter)) {
|
||||
pattern.apply(this, mainFilter, mainFilter);
|
||||
}
|
||||
if (mask.test(this, floorFilter)) {
|
||||
pattern.apply(this, floorFilter, floorFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1466,15 +1470,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
setFloor(((BlockStateHolder) value).getOrdinalChar());
|
||||
} else {
|
||||
floor.record(() -> {
|
||||
char[] floorArr = floor.get();
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
floorArr[index] = value.apply(mutable).getOrdinalChar();
|
||||
filter.init(x, z, index);
|
||||
value.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -1486,18 +1487,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
setColumn(((BlockStateHolder) value).getOrdinalChar());
|
||||
} else {
|
||||
main.record(() -> floor.record(() -> {
|
||||
char[] floorArr = floor.get();
|
||||
char[] mainArr = main.get();
|
||||
ArrayFilterBlock floorFilter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0);
|
||||
ArrayFilterBlock mainFilter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
char combined = value.apply(mutable).getOrdinalChar();
|
||||
mainArr[index] = combined;
|
||||
floorArr[index] = combined;
|
||||
floorFilter.init(x, z, index);
|
||||
mainFilter.init(x, z, index);
|
||||
value.apply(this, floorFilter, floorFilter);
|
||||
value.apply(this, mainFilter, mainFilter);
|
||||
}
|
||||
}
|
||||
}));
|
||||
@ -1509,15 +1507,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
setMain(((BlockStateHolder) value).getOrdinalChar());
|
||||
} else {
|
||||
main.record(() -> {
|
||||
char[] mainArr = main.get();
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
mainArr[index] = value.apply(mutable).getOrdinalChar();
|
||||
filter.init(x, z, index);
|
||||
value.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -1530,15 +1525,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
setOverlay(((BlockStateHolder) value).getOrdinalChar());
|
||||
} else {
|
||||
overlay.record(() -> {
|
||||
char[] overlayArr = overlay.get();
|
||||
ArrayFilterBlock filter = new ArrayFilterBlock(this, overlay.get(), heights.get(), getWidth(), getLength(), 1);
|
||||
int index = 0;
|
||||
for (int z = 0; z < getLength(); z++) {
|
||||
mutable.mutZ(z);
|
||||
for (int x = 0; x < getWidth(); x++, index++) {
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
overlayArr[index] = value.apply(mutable).getOrdinalChar();
|
||||
filter.init(x, z, index);
|
||||
value.apply(this, filter, filter);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -1758,7 +1750,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
if (mask.test(this, mutable)) {
|
||||
overlay.setInt(index, combined);
|
||||
}
|
||||
}
|
||||
@ -1773,7 +1765,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
if (mask.test(this, mutable)) {
|
||||
floor.setInt(index, combined);
|
||||
}
|
||||
}
|
||||
@ -1789,7 +1781,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
if (mask.test(this, mutable)) {
|
||||
main.setInt(index, combined);
|
||||
}
|
||||
}
|
||||
@ -1805,7 +1797,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
||||
int y = heights.getByte(index) & 0xFF;
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
if (mask.test(mutable)) {
|
||||
if (mask.test(this, mutable)) {
|
||||
floor.setInt(index, combined);
|
||||
main.setInt(index, combined);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.boydti.fawe.beta.implementation.filter.block.AbstractFilterBlock;
|
||||
import com.boydti.fawe.jnbt.streamer.IntValueReader;
|
||||
import com.google.common.collect.ForwardingIterator;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.function.visitor.Order;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -111,5 +112,10 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa
|
||||
public BlockVector3 getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return LinearClipboard.this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -294,14 +294,14 @@ public final class DifferentialArray<T> implements DifferentialCollection<T> {
|
||||
dataInts[index] = value;
|
||||
}
|
||||
|
||||
// public void setChar(int index, char value) {
|
||||
// changed = true;
|
||||
// try {
|
||||
// changesChars[index] += dataChars[index] - value;
|
||||
// } catch (NullPointerException ignore) {
|
||||
// changes = (T) (changesChars = new char[dataChars.length]);
|
||||
// changesChars[index] += dataChars[index] - value;
|
||||
// }
|
||||
// dataChars[index] = value;
|
||||
// }
|
||||
public void setChar(int index, char value) {
|
||||
changed = true;
|
||||
try {
|
||||
changesChars[index] += dataChars[index] - value;
|
||||
} catch (NullPointerException ignore) {
|
||||
changes = (T) (changesChars = new char[dataChars.length]);
|
||||
changesChars[index] += dataChars[index] - value;
|
||||
}
|
||||
dataChars[index] = value;
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,20 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
public class SourceMaskExtent extends TemporalExtent {
|
||||
private Mask mask;
|
||||
private Extent get;
|
||||
private MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
|
||||
public SourceMaskExtent(Extent extent, Mask mask) {
|
||||
this(extent, extent, mask);
|
||||
}
|
||||
|
||||
public SourceMaskExtent(Extent get, Extent set, Mask mask) {
|
||||
super(set);
|
||||
checkNotNull(get);
|
||||
checkNotNull(mask);
|
||||
this.get = get;
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mask.
|
||||
@ -33,16 +45,10 @@ public class SourceMaskExtent extends TemporalExtent {
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
public SourceMaskExtent(Extent extent, Mask mask) {
|
||||
super(extent);
|
||||
checkNotNull(mask);
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
|
||||
set(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
|
||||
return mask.test(location) && super.setBlock(location, block);
|
||||
return mask.test(get, location) && super.setBlock(location, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,6 +57,6 @@ public class SourceMaskExtent extends TemporalExtent {
|
||||
mutable.mutX(x);
|
||||
mutable.mutY(y);
|
||||
mutable.mutZ(z);
|
||||
return mask.test(mutable) && super.setBlock(x, y, z, block);
|
||||
return mask.test(get, mutable) && super.setBlock(x, y, z, block);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Mask2D;
|
||||
@ -24,9 +25,20 @@ public class AbstractDelegateMask extends AbstractMask {
|
||||
return mask.test(vector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 pos) {
|
||||
return mask.test(extent, pos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Mask2D toMask2D() {
|
||||
return mask.toMask2D();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask withExtent(Extent extent) {
|
||||
mask.withExtent(extent);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -11,7 +12,7 @@ import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
public class AdjacentAnyMask extends AbstractMask implements ResettableMask {
|
||||
|
||||
private final CachedMask mask;
|
||||
private transient MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
private final MutableBlockVector3 mutable;
|
||||
|
||||
public AdjacentAnyMask(Mask mask) {
|
||||
this.mask = CachedMask.cache(mask);
|
||||
@ -20,7 +21,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask {
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
mutable = new MutableBlockVector3();
|
||||
mutable.setComponents(0, 0, 0);
|
||||
}
|
||||
|
||||
public CachedMask getParentMask() {
|
||||
@ -28,53 +29,28 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 v) {
|
||||
int x = v.getBlockX();
|
||||
int y = v.getBlockY();
|
||||
int z = v.getBlockZ();
|
||||
if (mask.test(x + 1, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (mask.test(x - 1, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (mask.test(x, y, z + 1)) {
|
||||
return true;
|
||||
}
|
||||
if (mask.test(x, y, z - 1)) {
|
||||
return true;
|
||||
}
|
||||
if (y < 256 && mask.test(x, y + 1, z)) {
|
||||
return true;
|
||||
}
|
||||
if (y > 0 && mask.test(x, y - 1, z)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public boolean test(Extent extent, BlockVector3 v) {
|
||||
return direction(extent, v) != null;
|
||||
}
|
||||
|
||||
public BlockVector3 direction(BlockVector3 v) {
|
||||
public BlockVector3 direction(Extent extent, BlockVector3 v) {
|
||||
int x = v.getBlockX();
|
||||
int y = v.getBlockY();
|
||||
int z = v.getBlockZ();
|
||||
if (mask.test(x + 1, y, z)) {
|
||||
mutable.setComponents(1, 0, 0);
|
||||
}else
|
||||
if (mask.test(x - 1, y, z)) {
|
||||
mutable.setComponents(-1, 0, 0);
|
||||
}else
|
||||
if (mask.test(x, y, z + 1)) {
|
||||
mutable.setComponents(0, 0, 1);
|
||||
}else
|
||||
if (mask.test(x, y, z - 1)) {
|
||||
mutable.setComponents(0, 0, -1);
|
||||
}else
|
||||
if (y < 256 && mask.test(x, y + 1, z)) {
|
||||
mutable.setComponents(0, 1, 0);
|
||||
}else
|
||||
if (y > 0 && mask.test(x, y - 1, z)) {
|
||||
mutable.setComponents(0, -1, 0);
|
||||
if (mask.test(extent, x + 1, y, z)) {
|
||||
return mutable.setComponents(1, 0, 0);
|
||||
}else if (mask.test(extent, x - 1, y, z)) {
|
||||
return mutable.setComponents(-1, 0, 0);
|
||||
}else if (mask.test(extent, x, y, z + 1)) {
|
||||
return mutable.setComponents(0, 0, 1);
|
||||
}else if (mask.test(extent, x, y, z - 1)) {
|
||||
return mutable.setComponents(0, 0, -1);
|
||||
}else if (y < 256 && mask.test(extent, x, y + 1, z)) {
|
||||
return mutable.setComponents(0, 1, 0);
|
||||
}else if (y > 0 && mask.test(extent, x, y - 1, z)) {
|
||||
return mutable.setComponents(0, -1, 0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return (mutable.getX() == 0 && mutable.getY() == 0 && mutable.getZ() == 0) ? null : mutable;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -18,41 +19,41 @@ public class AdjacentMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 bv) {
|
||||
public boolean test(Extent extent, BlockVector3 bv) {
|
||||
v.setComponents(bv);
|
||||
int count = 0;
|
||||
double x = bv.getX();
|
||||
double y = bv.getY();
|
||||
double z = bv.getZ();
|
||||
v.mutX(x + 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutX(x);
|
||||
return true;
|
||||
}
|
||||
v.mutX(x - 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutX(x);
|
||||
return true;
|
||||
}
|
||||
v.mutX(x);
|
||||
v.mutY(y + 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutY(y);
|
||||
return true;
|
||||
}
|
||||
v.mutY(y - 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutY(y);
|
||||
return true;
|
||||
}
|
||||
v.mutY(y);
|
||||
v.mutZ(z + 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutZ(z);
|
||||
return true;
|
||||
}
|
||||
v.mutZ(z - 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutZ(z);
|
||||
return true;
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
|
||||
protected transient boolean foundY;
|
||||
protected transient boolean lastValue;
|
||||
|
||||
public int getHeight(int x, int y, int z) {
|
||||
// return getExtent().getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
|
||||
public int getHeight(Extent extent, int x, int y, int z) {
|
||||
// return extent.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
|
||||
try {
|
||||
int rx = x - cacheBotX + 16;
|
||||
int rz = z - cacheBotZ + 16;
|
||||
@ -80,7 +80,7 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
|
||||
}
|
||||
int result = cacheHeights[index] & 0xFF;
|
||||
if (y > result) {
|
||||
cacheHeights[index] = (byte) (result = lastY = getExtent().getNearestSurfaceTerrainBlock(x, z, lastY, 0, maxY));
|
||||
cacheHeights[index] = (byte) (result = lastY = extent.getNearestSurfaceTerrainBlock(x, z, lastY, 0, maxY));
|
||||
}
|
||||
return result;
|
||||
} catch (Throwable e) {
|
||||
@ -89,72 +89,72 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean testSlope(int x, int y, int z) {
|
||||
protected boolean testSlope(Extent extent, int x, int y, int z) {
|
||||
double slope;
|
||||
boolean aboveMin;
|
||||
lastY = y;
|
||||
slope = Math.abs(getHeight(x + distance, y, z) - getHeight(x -distance, y, z)) * ADJACENT_MOD;
|
||||
slope = Math.abs(getHeight(extent, x + distance, y, z) - getHeight(extent, x -distance, y, z)) * ADJACENT_MOD;
|
||||
if (checkFirst) {
|
||||
if (slope >= min) {
|
||||
return lastValue = true;
|
||||
}
|
||||
slope = Math.max(slope, Math.abs(getHeight(x, y, z + distance) - getHeight(x, y, z - distance)) * ADJACENT_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(x + distance, y, z + distance) - getHeight(x - distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(x - distance, y, z + distance) - getHeight(x + distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) * ADJACENT_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(extent, x + distance, y, z + distance) - getHeight(extent, x - distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(extent, x - distance, y, z + distance) - getHeight(extent, x + distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
return lastValue = (slope >= min);
|
||||
} else {
|
||||
slope = Math.max(slope, Math.abs(getHeight(x, y, z + distance) - getHeight(x, y, z - distance)) * ADJACENT_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(x + distance, y, z + distance) - getHeight(x - distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(x - distance, y, z + distance) - getHeight(x + distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) * ADJACENT_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(extent, x + distance, y, z + distance) - getHeight(extent, x - distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
slope = Math.max(slope, Math.abs(getHeight(extent, x - distance, y, z + distance) - getHeight(extent, x + distance, y, z - distance)) * DIAGONAL_MOD);
|
||||
return lastValue = (slope >= min && slope <= max);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean adjacentAir(BlockVector3 v) {
|
||||
public boolean adjacentAir(Extent extent, BlockVector3 v) {
|
||||
int x = v.getBlockX();
|
||||
int y = v.getBlockY();
|
||||
int z = v.getBlockZ();
|
||||
if (!mask.test(x + 1, y, z)) {
|
||||
if (!mask.test(extent, x + 1, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (!mask.test(x - 1, y, z)) {
|
||||
if (!mask.test(extent, x - 1, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (!mask.test(x, y, z + 1)) {
|
||||
if (!mask.test(extent, x, y, z + 1)) {
|
||||
return true;
|
||||
}
|
||||
if (!mask.test(x, y, z - 1)) {
|
||||
if (!mask.test(extent, x, y, z - 1)) {
|
||||
return true;
|
||||
}
|
||||
if (y < 255 && !mask.test(x, y + 1, z)) {
|
||||
if (y < 255 && !mask.test(extent, x, y + 1, z)) {
|
||||
return true;
|
||||
}
|
||||
if (y > 0 && !mask.test(x, y - 1, z)) {
|
||||
if (y > 0 && !mask.test(extent, x, y - 1, z)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
int x = vector.getBlockX();
|
||||
int y = vector.getBlockY();
|
||||
int z = vector.getBlockZ();
|
||||
|
||||
if ((lastX == (lastX = x) & lastZ == (lastZ = z))) {
|
||||
int height = getHeight(x, y, z);
|
||||
int height = getHeight(extent, x, y, z);
|
||||
if (y <= height) return overlay ? (lastValue && y == height) : lastValue;
|
||||
}
|
||||
|
||||
if (!mask.test(x, y, z)) {
|
||||
if (!mask.test(extent, x, y, z)) {
|
||||
return false;
|
||||
}
|
||||
if (overlay) {
|
||||
if (y < 255 && !mask.test(x, y + 1, z)) return lastValue = false;
|
||||
} else if (!adjacentAir(vector)) {
|
||||
if (y < 255 && !mask.test(extent, x, y + 1, z)) return lastValue = false;
|
||||
} else if (!adjacentAir(extent, vector)) {
|
||||
return false;
|
||||
}
|
||||
return testSlope(x, y, z);
|
||||
return testSlope(extent, x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ public class BiomeMask extends AbstractExtentMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
BlockVector2 pos = mutable.setComponents(vector.getBlockX(), vector.getBlockZ());
|
||||
return getExtent().getBiome(pos).getId() == biome.getId();
|
||||
return extent.getBiome(pos).getId() == biome.getId();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ public class BlockLightMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
Extent extent = getExtent();
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (extent instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
return light >= min && light <= max;
|
||||
|
@ -16,8 +16,7 @@ public class BrightnessMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
Extent extent = getExtent();
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (extent instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
return light >= min && light <= max;
|
||||
|
@ -2,6 +2,7 @@ package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
|
||||
import com.boydti.fawe.object.function.mask.AbstractDelegateMask;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
@ -41,21 +42,21 @@ public class CachedMask extends AbstractDelegateMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
return test(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return test(extent, vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
}
|
||||
|
||||
public boolean test(int x, int y, int z) {
|
||||
public boolean test(Extent extent, int x, int y, int z) {
|
||||
try {
|
||||
boolean check = cache_checked.add(x, y, z);
|
||||
if (!check) {
|
||||
return cache_results.contains(x, y, z);
|
||||
}
|
||||
boolean result = getMask().test(mutable.setComponents(x, y, z));
|
||||
boolean result = getMask().test(extent, mutable.setComponents(x, y, z));
|
||||
if (result) cache_results.add(x, y, z);
|
||||
return result;
|
||||
} catch (UnsupportedOperationException ignore) {
|
||||
boolean result = getMask().test(mutable.setComponents(x, y, z));
|
||||
boolean result = getMask().test(extent, mutable.setComponents(x, y, z));
|
||||
if (y < 0 || y > 255) return result;
|
||||
resetCache();
|
||||
cache_checked.setOffset(x, z);
|
||||
|
@ -13,8 +13,7 @@ public class DataMask extends AbstractExtentMask implements ResettableMask {
|
||||
private transient int data = -1;
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
Extent extent = getExtent();
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (data != -1) {
|
||||
return extent.getBlock(vector).getInternalPropertiesId() == data;
|
||||
} else {
|
||||
|
@ -8,28 +8,28 @@ public class ExtremaMask extends AngleMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testSlope(int x, int y, int z) {
|
||||
protected boolean testSlope(Extent extent, int x, int y, int z) {
|
||||
double slope, tmp;
|
||||
boolean aboveMin;
|
||||
lastY = y;
|
||||
|
||||
int base = getHeight(x, y, z);
|
||||
int base = getHeight(extent, x, y, z);
|
||||
|
||||
slope = get(base, x, y, z, 1, 0, distance) * ADJACENT_MOD;
|
||||
slope = getHeight(extent, base, x, y, z, 1, 0, distance) * ADJACENT_MOD;
|
||||
|
||||
tmp = get(base, x, y, z, 0, 1, distance) * ADJACENT_MOD;
|
||||
tmp = getHeight(extent, base, x, y, z, 0, 1, distance) * ADJACENT_MOD;
|
||||
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
|
||||
|
||||
tmp = get(base, x, y, z, 1, 1, distance) * DIAGONAL_MOD;
|
||||
tmp = getHeight(extent, base, x, y, z, 1, 1, distance) * DIAGONAL_MOD;
|
||||
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
|
||||
|
||||
tmp = get(base, x, y, z, 1, -1, distance) * DIAGONAL_MOD;
|
||||
tmp = getHeight(extent, base, x, y, z, 1, -1, distance) * DIAGONAL_MOD;
|
||||
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
|
||||
|
||||
return lastValue = (slope > min && slope < max);
|
||||
}
|
||||
|
||||
private int get(int base, int x, int y, int z, int OX, int OZ, int iterations) {
|
||||
private int getHeight(Extent extent, int base, int x, int y, int z, int OX, int OZ, int iterations) {
|
||||
int sign = 0;
|
||||
int lastHeight1 = base;
|
||||
int lastHeight2 = base;
|
||||
@ -40,8 +40,8 @@ public class ExtremaMask extends AngleMask {
|
||||
int z1 = z + coz;
|
||||
int x2 = x - cox;
|
||||
int z2 = z - coz;
|
||||
int height1 = getHeight(x1, y, z1);
|
||||
int height2 = getHeight(x2, y, z2);
|
||||
int height1 = getHeight(extent, x1, y, z1);
|
||||
int height2 = getHeight(extent, x2, y, z2);
|
||||
int diff1 = height1 - lastHeight1;
|
||||
int diff2 = height2 - lastHeight2;
|
||||
int sign1 = Integer.signum(diff1);
|
||||
|
@ -12,8 +12,7 @@ public class IdDataMask extends AbstractExtentMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
Extent extent = getExtent();
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (combined != -1) {
|
||||
return extent.getBlock(vector).getInternalId() == combined;
|
||||
} else {
|
||||
|
@ -13,8 +13,7 @@ public class IdMask extends AbstractExtentMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
Extent extent = getExtent();
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (id != -1) {
|
||||
return extent.getBlock(vector).getInternalBlockTypeId() == id;
|
||||
} else {
|
||||
|
@ -16,9 +16,9 @@ public class LightMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
if (getExtent() instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) getExtent()).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (extent instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) extent).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
return light >= min && light <= max;
|
||||
}
|
||||
return false;
|
||||
|
@ -21,7 +21,7 @@ public class MaskedTargetBlock extends TargetBlock {
|
||||
Location lastBlock = null;
|
||||
while (getNextBlock() != null) {
|
||||
Location current = getCurrentBlock();
|
||||
if (!mask.test(current.toBlockPoint())) {
|
||||
if (!mask.test(world, current.toBlockPoint())) {
|
||||
if (searchForLastBlock) {
|
||||
lastBlock = current;
|
||||
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
|
||||
|
@ -16,9 +16,9 @@ public class OpacityMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
if (getExtent() instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) getExtent()).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (extent instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) extent).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
return light >= min && light <= max;
|
||||
}
|
||||
return false;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -12,7 +13,7 @@ public class PlaneMask extends AbstractMask implements ResettableMask {
|
||||
private transient int originX = Integer.MAX_VALUE, originY = Integer.MAX_VALUE, originZ = Integer.MAX_VALUE;
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
switch (mode) {
|
||||
case -1:
|
||||
originX = vector.getBlockX();
|
||||
|
@ -9,23 +9,23 @@ public class ROCAngleMask extends AngleMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testSlope(int x, int y, int z) {
|
||||
protected boolean testSlope(Extent extent, int x, int y, int z) {
|
||||
double tmp;
|
||||
lastY = y;
|
||||
|
||||
int base = getHeight(x, y, z);
|
||||
int base = getHeight(extent, x, y, z);
|
||||
double slope =
|
||||
(getHeight(x + distance, y, z) - base - (base - getHeight(x - distance, y, z)))
|
||||
(getHeight(extent, x + distance, y, z) - base - (base - getHeight(extent, x - distance, y, z)))
|
||||
* ADJACENT_MOD;
|
||||
|
||||
tmp = (getHeight(x, y, z + distance) - base - (base - getHeight(x, y, z - distance))) * ADJACENT_MOD;
|
||||
tmp = (getHeight(extent, x, y, z + distance) - base - (base - getHeight(extent, x, y, z - distance))) * ADJACENT_MOD;
|
||||
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
|
||||
|
||||
tmp = (getHeight(x + distance, y, z + distance) - base - (base - getHeight(x - distance, y,
|
||||
tmp = (getHeight(extent, x + distance, y, z + distance) - base - (base - getHeight(extent, x - distance, y,
|
||||
z - distance))) * DIAGONAL_MOD;
|
||||
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
|
||||
|
||||
tmp = (getHeight(x - distance, y, z + distance) - base - (base - getHeight(x + distance, y,
|
||||
tmp = (getHeight(extent, x - distance, y, z + distance) - base - (base - getHeight(extent, x + distance, y,
|
||||
z - distance))) * DIAGONAL_MOD;
|
||||
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -19,7 +20,7 @@ public class RadiusMask extends AbstractMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 to) {
|
||||
public boolean test(Extent extent, BlockVector3 to) {
|
||||
if (pos == null) {
|
||||
pos = to.toImmutable();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import java.util.SplittableRandom;
|
||||
@ -14,7 +15,7 @@ public class RandomMask extends AbstractMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
return random.nextInt() <= threshold;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.boydti.fawe.object.random.SimplexNoise;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -14,7 +15,7 @@ public class SimplexMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
double value = SimplexNoise.noise(vector.getBlockX() * scale, vector.getBlockY() * scale, vector.getBlockZ() * scale);
|
||||
return value >= min && value <= max;
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ public class SkyLightMask extends AbstractExtentMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
if (getExtent() instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) getExtent())
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (extent instanceof LightingExtent) {
|
||||
int light = ((LightingExtent) extent)
|
||||
.getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
return light >= min && light <= max;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class SolidPlaneMask extends SolidBlockMask implements ResettableMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
switch (mode) {
|
||||
case -1:
|
||||
if (!super.test(vector)) {
|
||||
@ -30,7 +30,6 @@ public class SolidPlaneMask extends SolidBlockMask implements ResettableMask {
|
||||
originY = vector.getBlockY();
|
||||
originZ = vector.getBlockZ();
|
||||
mode = 0;
|
||||
Extent extent = getExtent();
|
||||
if (!extent.getBlock(mutable.setComponents(originX - 1, originY, originZ)).getMaterial().isAir() && !extent.getBlock(mutable.setComponents(originX + 1, originY, originZ)).getMaterial().isAir()) {
|
||||
mode &= 1;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class SurfaceMask extends AdjacentAnyMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 v) {
|
||||
return !getParentMask().test(v.getBlockX(), v.getBlockY(), v.getBlockZ()) && super.test(v);
|
||||
public boolean test(Extent extent, BlockVector3 v) {
|
||||
return !getParentMask().test(extent, v.getBlockX(), v.getBlockY(), v.getBlockZ()) && super.test(extent, v);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -18,30 +19,30 @@ public class WallMask extends AbstractMask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 bv) {
|
||||
public boolean test(Extent extent, BlockVector3 bv) {
|
||||
v.setComponents(bv);
|
||||
int count = 0;
|
||||
double x = v.getX();
|
||||
double y = v.getY();
|
||||
double z = v.getZ();
|
||||
v.mutX(x + 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutX(x);
|
||||
return true;
|
||||
}
|
||||
v.mutX(x - 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutX(x);
|
||||
return true;
|
||||
}
|
||||
v.mutX(x);
|
||||
v.mutZ(z + 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutZ(z);
|
||||
return true;
|
||||
}
|
||||
v.mutZ(z - 1);
|
||||
if (mask.test(v) && ++count == min && max >= 8) {
|
||||
if (mask.test(extent, v) && ++count == min && max >= 8) {
|
||||
v.mutZ(z);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -11,7 +12,7 @@ public class XAxisMask extends AbstractMask implements ResettableMask {
|
||||
private transient int layer = -1;
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (layer == -1) {
|
||||
layer = vector.getBlockX();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -11,7 +12,7 @@ public class YAxisMask extends AbstractMask implements ResettableMask {
|
||||
private transient int layer = -1;
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (layer == -1) {
|
||||
layer = vector.getBlockY();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
@ -11,7 +12,7 @@ public class ZAxisMask extends AbstractMask implements ResettableMask {
|
||||
private transient int layer = -1;
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (layer == -1) {
|
||||
layer = vector.getBlockZ();
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ public class MaskedPattern extends AbstractPattern {
|
||||
this.secondary = secondary;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
if (mask.test(position)) {
|
||||
@ -31,7 +30,7 @@ public class MaskedPattern extends AbstractPattern {
|
||||
|
||||
@Override
|
||||
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
if (mask.test(get)) {
|
||||
if (mask.test(extent, get)) {
|
||||
return primary.apply(extent, get, set);
|
||||
}
|
||||
return secondary.apply(extent, get, set);
|
||||
|
@ -5,6 +5,8 @@ import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.DelegateExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
|
||||
@ -42,7 +44,7 @@ public class FuzzyRegion extends AbstractRegion {
|
||||
}
|
||||
|
||||
public void select(int x, int y, int z) {
|
||||
RecursiveVisitor search = new RecursiveVisitor(mask, new RegionFunction() {
|
||||
RecursiveVisitor search = new RecursiveVisitor(mask.withExtent(extent), new RegionFunction() {
|
||||
@Override
|
||||
public boolean apply(BlockVector3 p) throws WorldEditException {
|
||||
setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ());
|
||||
|
@ -375,7 +375,7 @@ public class TextureUtil implements TextureHolder {
|
||||
for (int typeId : tu.getValidBlockIds()) {
|
||||
BlockType block = BlockTypes.get(typeId);
|
||||
extent.init(0, 0, 0, block.getDefaultState().toBaseBlock());
|
||||
if (mask.test(extent)) {
|
||||
if (mask.test(extent, extent)) {
|
||||
blocks.add(block);
|
||||
}
|
||||
}
|
||||
|
@ -800,7 +800,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
@Override
|
||||
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
|
||||
for (int y = maxY; y >= minY; --y) {
|
||||
if (filter.test(mutablebv.setComponents(x, y, z))) {
|
||||
if (filter.test(getExtent(), mutablebv.setComponents(x, y, z))) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@ -1079,8 +1079,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
if (direction.equals(BlockVector3.at(0, -1, 0))) {
|
||||
return fillXZ(origin, pattern, radius, depth, false);
|
||||
}
|
||||
final Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this)));
|
||||
|
||||
Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this))).withExtent(getExtent());
|
||||
// Want to replace blocks
|
||||
final BlockReplace replace = new BlockReplace(EditSession.this, pattern);
|
||||
|
||||
@ -1127,13 +1126,12 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
checkArgument(radius >= 0, "radius >= 0");
|
||||
checkArgument(depth >= 1, "depth >= 1");
|
||||
|
||||
MaskIntersection mask = new MaskIntersection(
|
||||
Mask mask = new MaskIntersection(
|
||||
new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
|
||||
new BoundedHeightMask(
|
||||
Math.max(origin.getBlockY() - depth + 1, getMinimumPoint().getBlockY()),
|
||||
Math.min(getMaxY(), origin.getBlockY())),
|
||||
Masks.negate(new ExistingBlockMask(this)));
|
||||
|
||||
Masks.negate(new ExistingBlockMask(this))).withExtent(getExtent());
|
||||
// Want to replace blocks
|
||||
BlockReplace replace = new BlockReplace(this, pattern);
|
||||
|
||||
@ -1341,7 +1339,9 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
if (region instanceof CuboidRegion) {
|
||||
return makeCuboidWalls(region, pattern);
|
||||
} else {
|
||||
replaceBlocks(region, position -> {
|
||||
replaceBlocks(region, new Mask() {
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 position) {
|
||||
int x = position.getBlockX();
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ();
|
||||
@ -1350,6 +1350,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}, pattern);
|
||||
}
|
||||
return changes;
|
||||
@ -1571,10 +1572,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
// } else {
|
||||
// }
|
||||
liquidMask = new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER);
|
||||
MaskIntersection mask = new MaskIntersection(
|
||||
Mask mask = new MaskIntersection(
|
||||
new BoundedHeightMask(0, getWorld().getMaxY()),
|
||||
new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))),
|
||||
liquidMask);
|
||||
liquidMask).withExtent(getExtent());
|
||||
BlockReplace replace;
|
||||
if (waterlogged) {
|
||||
replace = new BlockReplace(this, new WaterloggedRemover(this));
|
||||
@ -1585,7 +1586,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(position)) {
|
||||
if (mask.test(getExtent(), position)) {
|
||||
visitor.visit(position);
|
||||
}
|
||||
}
|
||||
@ -1619,14 +1620,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(position)) {
|
||||
if (liquidMask.test(getExtent(), position)) {
|
||||
visitor.visit(position);
|
||||
}
|
||||
}
|
||||
@ -2712,7 +2712,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
while (iter.hasNext()) {
|
||||
final BlockVector3 current = iter.next();
|
||||
iter.remove();
|
||||
if (mask.test(current)) {
|
||||
if (mask.test(getExtent(), current)) {
|
||||
continue;
|
||||
}
|
||||
if (!outside.add(current)) {
|
||||
|
@ -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(MutableBlockVector3.get(x, y, z))) {
|
||||
if (filter.test(this, 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(MutableBlockVector3.get(x, y, z));
|
||||
boolean state = !mask.test(this, MutableBlockVector3.get(x, y, z));
|
||||
int offset = state ? 0 : 1;
|
||||
for (int d = 0; d <= clearance; d++) {
|
||||
int y1 = y + d;
|
||||
if (mask.test(MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset;
|
||||
if (mask.test(this, MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset;
|
||||
int y2 = y - d;
|
||||
if (mask.test(MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset;
|
||||
if (mask.test(this, 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(MutableBlockVector3.get(x, layer, z)) != state) return layer + offset;
|
||||
if (mask.test(this, MutableBlockVector3.get(x, layer, z)) != state) return layer + offset;
|
||||
}
|
||||
} else {
|
||||
for (int layer = y + clearance + 1; layer <= maxY; layer++) {
|
||||
if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer - offset;
|
||||
if (mask.test(this, 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, searchMask::test);
|
||||
RegionVisitor visitor = new RegionVisitor(region, position -> searchMask.test(this, position));
|
||||
Operations.completeBlindly(visitor);
|
||||
return visitor.getAffected();
|
||||
}
|
||||
@ -606,7 +606,7 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
checkNotNull(pattern);
|
||||
|
||||
BlockReplace replace = new BlockReplace(this, pattern);
|
||||
RegionMaskingFilter filter = new RegionMaskingFilter(mask, replace);
|
||||
RegionMaskingFilter filter = new RegionMaskingFilter(this, mask, replace);
|
||||
RegionVisitor visitor = new RegionVisitor(region, filter);
|
||||
Operations.completeLegacy(visitor);
|
||||
return visitor.getAffected();
|
||||
|
@ -86,17 +86,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(location) && super.setBlock(location, block);
|
||||
return mask.test(getExtent(), location) && super.setBlock(location, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(BlockVector2 position, BiomeType biome) {
|
||||
return mask.test(position.toBlockVector3()) && super.setBiome(position, biome);
|
||||
return mask.test(getExtent(), position.toBlockVector3()) && super.setBiome(position, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||
return mask.test(BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome);
|
||||
return mask.test(getExtent(), BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,7 +108,7 @@ public class MaskingExtent extends AbstractDelegateExtent implements IBatchProce
|
||||
@Override
|
||||
public void applyBlock(FilterBlock block) {
|
||||
int ordinal = block.getOrdinal();
|
||||
if (ordinal != 0 && !mask.test(block)) {
|
||||
if (ordinal != 0 && !mask.test(getExtent(), block)) {
|
||||
block.setOrdinal(0);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import javax.annotation.Nullable;
|
||||
* pass on any changes.
|
||||
*/
|
||||
public class NullExtent implements Extent {
|
||||
public static final NullExtent INSTANCE = new NullExtent();
|
||||
|
||||
@Override
|
||||
public BlockVector3 getMinimumPoint() {
|
||||
|
@ -67,7 +67,7 @@ public class ExtentBuffer extends AbstractBufferingExtent {
|
||||
|
||||
@Override
|
||||
protected Optional<BaseBlock> getBufferedBlock(BlockVector3 position) {
|
||||
if (mask.test(position)) {
|
||||
if (mask.test(getExtent(), position)) {
|
||||
return Optional.of(buffer.computeIfAbsent(position, (pos -> getExtent().getFullBlock(pos))));
|
||||
}
|
||||
return Optional.empty();
|
||||
@ -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(location)) {
|
||||
if (mask.test(getExtent(), location)) {
|
||||
buffer.put(location, block.toBaseBlock());
|
||||
return true;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
max = max.getMaximum(location);
|
||||
}
|
||||
|
||||
if (mask.test(location)) {
|
||||
if (mask.test(getExtent(), location)) {
|
||||
buffer.put(location, block.toBaseBlock());
|
||||
return true;
|
||||
} else {
|
||||
@ -130,7 +130,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
max2d = max2d.getMaximum(position);
|
||||
}
|
||||
|
||||
if (biomeMask.test(position)) {
|
||||
if (biomeMask.test(getExtent(), position)) {
|
||||
biomeBuffer.put(position, biome);
|
||||
return true;
|
||||
} else {
|
||||
@ -154,7 +154,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
max2d = max2d.getMaximum(BlockVector2.at(x,z));
|
||||
}
|
||||
|
||||
if (biomeMask.test(BlockVector2.at(x,z))) {
|
||||
if (biomeMask.test(getExtent(), BlockVector2.at(x,z))) {
|
||||
biomeBuffer.put(BlockVector2.at(x,z), biome);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -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));
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SolidBlockMask;
|
||||
@ -38,7 +39,7 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class TargetBlock {
|
||||
|
||||
private final World world;
|
||||
private final Extent world;
|
||||
|
||||
private int maxDistance;
|
||||
private double checkDistance, curDistance;
|
||||
@ -58,11 +59,7 @@ public class TargetBlock {
|
||||
* @param player player to work with
|
||||
*/
|
||||
public TargetBlock(Player player) {
|
||||
this.world = player.getWorld();
|
||||
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(),
|
||||
300, 1.65, 0.2);
|
||||
this.stopMask = new ExistingBlockMask(world);
|
||||
this.solidMask = new SolidBlockMask(world);
|
||||
this(player, 300, 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,6 +70,10 @@ public class TargetBlock {
|
||||
* @param checkDistance how often to check for blocks, the smaller the more precise
|
||||
*/
|
||||
public TargetBlock(Player player, int maxDistance, double checkDistance) {
|
||||
this(player, player.getWorld(), maxDistance, checkDistance);
|
||||
}
|
||||
|
||||
public TargetBlock(Player player, Extent extent, int maxDistance, double checkDistance) {
|
||||
this.world = player.getWorld();
|
||||
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance);
|
||||
this.stopMask = new ExistingBlockMask(world);
|
||||
@ -145,7 +146,7 @@ public class TargetBlock {
|
||||
boolean searchForLastBlock = true;
|
||||
Location lastBlock = null;
|
||||
while (getNextBlock() != null) {
|
||||
if (stopMask.test(targetPos)) {
|
||||
if (stopMask.test(world, targetPos)) {
|
||||
break;
|
||||
} else {
|
||||
if (searchForLastBlock) {
|
||||
@ -168,7 +169,7 @@ public class TargetBlock {
|
||||
*/
|
||||
public Location getTargetBlock() {
|
||||
//noinspection StatementWithEmptyBody
|
||||
while (getNextBlock() != null && !stopMask.test(targetPos)) ;
|
||||
while (getNextBlock() != null && !stopMask.test(world, targetPos)) ;
|
||||
return getCurrentBlock();
|
||||
}
|
||||
|
||||
@ -180,7 +181,7 @@ public class TargetBlock {
|
||||
*/
|
||||
public Location getSolidTargetBlock() {
|
||||
//noinspection StatementWithEmptyBody
|
||||
while (getNextBlock() != null && !solidMask.test(targetPos)) ;
|
||||
while (getNextBlock() != null && !solidMask.test(world, targetPos)) ;
|
||||
return getCurrentBlock();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,10 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.extent.OutputExtent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
|
||||
import com.sk89q.worldedit.function.pattern.FawePattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
@ -227,6 +230,10 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
|
||||
return this.toBaseBlock();
|
||||
}
|
||||
|
||||
public Mask toMask() {
|
||||
return new SingleBlockStateMask(new NullExtent(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTileEntity(OutputExtent output, int x, int y, int z) {
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class SnapshotRestore {
|
||||
}
|
||||
|
||||
private void checkAndAddBlock(BlockVector3 pos) {
|
||||
if (editSession.getMask() != null && !editSession.getMask().test(pos))
|
||||
if (editSession.getMask() != null && !editSession.getMask().test(editSession, pos))
|
||||
return;
|
||||
|
||||
BlockVector2 chunkPos = ChunkStore.toChunk(pos);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren