mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 14:58:35 +00:00
Make masks more stateless
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user