SurfaceMask should be copied properly.

#1331
This commit is contained in:
dordsor21 2021-09-30 13:17:15 +01:00
parent 7a6a0f68fe
commit f886320c44
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
2 changed files with 16 additions and 5 deletions

View File

@ -12,8 +12,8 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask {
private final CachedMask mask; private final CachedMask mask;
private final MutableBlockVector3 mutable; private final MutableBlockVector3 mutable;
private final int minY; final int minY;
private final int maxY; final int maxY;
public AdjacentAnyMask(Mask mask, int minY, int maxY) { public AdjacentAnyMask(Mask mask, int minY, int maxY) {
this.mask = CachedMask.cache(mask); this.mask = CachedMask.cache(mask);
@ -22,6 +22,13 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask {
this.maxY = maxY; this.maxY = maxY;
} }
AdjacentAnyMask(CachedMask mask, int minY, int maxY) {
this.mask = CachedMask.cache(mask);
mutable = new MutableBlockVector3();
this.minY = minY;
this.maxY = maxY;
}
@Override @Override
public void reset() { public void reset() {
mutable.setComponents(0, 0, 0); mutable.setComponents(0, 0, 0);
@ -59,7 +66,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask {
@Override @Override
public Mask copy() { public Mask copy() {
return new AdjacentAnyMask(mask.copy(), minY, maxY); return new AdjacentAnyMask((CachedMask) mask.copy(), minY, maxY);
} }
} }

View File

@ -12,6 +12,10 @@ public class SurfaceMask extends AdjacentAnyMask {
super(getMask(extent), extent.getMinY(), extent.getMaxY()); super(getMask(extent), extent.getMinY(), extent.getMaxY());
} }
private SurfaceMask(CachedMask mask, int minY, int maxY) {
super(mask, minY, maxY);
}
public static AbstractExtentMask getMask(Extent extent) { public static AbstractExtentMask getMask(Extent extent) {
return new BlockMaskBuilder() return new BlockMaskBuilder()
.addTypes(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR) .addTypes(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR)
@ -26,8 +30,8 @@ public class SurfaceMask extends AdjacentAnyMask {
@Override @Override
public Mask copy() { public Mask copy() {
// The mask is not mutable. There is no need to clone it. // CachedMask (super getParentMask) should not be used from multiple threads.
return this; return new SurfaceMask(getParentMask(), minY, maxY);
} }
} }