More work on masks (#607)

* Add a #air mask, the opposite of #existing (#1511)

(cherry picked from commit 84fa2bbbc63de7bece01f41c0d5cb7d85cf129e6)

* Remove unused methods in Mask.java

* Remove `test(Extent, BlockVector3)` from Masks.

This was a poorly planned idea. This should save some memory too.

Authored-by: Matthew Miller <mnmiller1@me.com>
This commit is contained in:
Matt
2020-09-11 15:13:31 -04:00
committed by GitHub
parent 1fa0777d3b
commit de199a0e59
78 changed files with 232 additions and 331 deletions

View File

@@ -206,7 +206,7 @@ public interface Extent extends InputExtent, OutputExtent {
maxY = Math.min(maxY, Math.max(0, maxY));
minY = Math.max(0, minY);
for (int y = maxY; y >= minY; --y) {
if (filter.test(this, MutableBlockVector3.get(x, y, z))) {
if (filter.test(MutableBlockVector3.get(x, y, z))) {
return y;
}
}
@@ -276,22 +276,22 @@ public interface Extent extends InputExtent, OutputExtent {
int clearanceAbove = maxY - y;
int clearanceBelow = y - minY;
int clearance = Math.min(clearanceAbove, clearanceBelow);
boolean state = !mask.test(this, MutableBlockVector3.get(x, y, z));
boolean state = !mask.test(MutableBlockVector3.get(x, y, z));
int offset = state ? 0 : 1;
for (int d = 0; d <= clearance; d++) {
int y1 = y + d;
if (mask.test(this, MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset;
if (mask.test(MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset;
int y2 = y - d;
if (mask.test(this, MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset;
if (mask.test(MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset;
}
if (clearanceAbove != clearanceBelow) {
if (clearanceAbove < clearanceBelow) {
for (int layer = y - clearance - 1; layer >= minY; layer--) {
if (mask.test(this, MutableBlockVector3.get(x, layer, z)) != state) return layer + offset;
if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer + offset;
}
} else {
for (int layer = y + clearance + 1; layer <= maxY; layer++) {
if (mask.test(this, MutableBlockVector3.get(x, layer, z)) != state) return layer - offset;
if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer - offset;
}
}
}
@@ -508,7 +508,7 @@ public interface Extent extends InputExtent, OutputExtent {
* @return the number of blocks that matched the mask
*/
default int countBlocks(Region region, Mask searchMask) {
RegionVisitor visitor = new RegionVisitor(region, position -> searchMask.test(this, position));
RegionVisitor visitor = new RegionVisitor(region, position -> searchMask.test(position));
Operations.completeBlindly(visitor);
return visitor.getAffected();
}