Don't call `partOfMask` out of bounds

This commit is contained in:
ZacSharp 2023-06-20 02:00:08 +02:00
parent 6c8f2698d6
commit d87d1ab9b5
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
1 changed files with 14 additions and 6 deletions

View File

@ -33,7 +33,7 @@ public final class BinaryOperatorMask extends AbstractMask {
private final BooleanBinaryOperator operator;
public BinaryOperatorMask(Mask a, Mask b, BooleanBinaryOperator operator) {
super(a.widthX(), a.heightY(), a.lengthZ());
super(Math.max(a.widthX(), b.widthX()), Math.max(a.heightY(), b.heightY()), Math.max(a.lengthZ(), b.lengthZ()));
this.a = a;
this.b = b;
this.operator = operator;
@ -42,11 +42,15 @@ public final class BinaryOperatorMask extends AbstractMask {
@Override
public boolean partOfMask(int x, int y, int z, IBlockState currentState) {
return this.operator.applyAsBoolean(
this.a.partOfMask(x, y, z, currentState),
this.b.partOfMask(x, y, z, currentState)
partOfMask(a, x, y, z, currentState),
partOfMask(b, x, y, z, currentState)
);
}
private static boolean partOfMask(Mask mask, int x, int y, int z, IBlockState currentState) {
return x < mask.widthX() && y < mask.heightY() && z < mask.lengthZ() && mask.partOfMask(x, y, z, currentState);
}
public static final class Static extends AbstractMask implements StaticMask {
private final StaticMask a;
@ -54,7 +58,7 @@ public final class BinaryOperatorMask extends AbstractMask {
private final BooleanBinaryOperator operator;
public Static(StaticMask a, StaticMask b, BooleanBinaryOperator operator) {
super(a.widthX(), a.heightY(), a.lengthZ());
super(Math.max(a.widthX(), b.widthX()), Math.max(a.heightY(), b.heightY()), Math.max(a.lengthZ(), b.lengthZ()));
this.a = a;
this.b = b;
this.operator = operator;
@ -63,9 +67,13 @@ public final class BinaryOperatorMask extends AbstractMask {
@Override
public boolean partOfMask(int x, int y, int z) {
return this.operator.applyAsBoolean(
this.a.partOfMask(x, y, z),
this.b.partOfMask(x, y, z)
partOfMask(a, x, y, z),
partOfMask(b, x, y, z)
);
}
private static boolean partOfMask(StaticMask mask, int x, int y, int z) {
return x < mask.widthX() && y < mask.heightY() && z < mask.lengthZ() && mask.partOfMask(x, y, z);
}
}
}