Skip to content

Commit 1449067

Browse files
authored
Merge pull request #414 from Phoenix616/pr/fix-npe
Fix possible NPE and clean up more edge interaction checks (Fixes #409)
2 parents 25b9d27 + 127fbf7 commit 1449067

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/collision/CollisionUtil.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -713,14 +713,20 @@ public static boolean canPassThrough(InteractAxisTracing rayTracing, BlockCache
713713
double maxX = nextBlockBB[3];
714714
double maxY = nextBlockBB[4];
715715
double maxZ = nextBlockBB[5];
716-
double lastMinX = lastBlockBB[0];
717-
double lastMinY = lastBlockBB[1];
718-
double lastMinZ = lastBlockBB[2];
719-
double lastMaxX = lastBlockBB[3];
720-
double lastMaxY = lastBlockBB[4];
721-
double lastMaxZ = lastBlockBB[5];
716+
double lastMinX = -1;
717+
double lastMinY = -1;
718+
double lastMinZ = -1;
719+
double lastMaxX = -1;
720+
double lastMaxY = -1;
721+
double lastMaxZ = -1;
722722
// Slab/door/trap door fix(3/3): Bypass : Can't interact through other side of block from one side
723723
if (lastBlockBB != null) {
724+
lastMinX = lastBlockBB[0];
725+
lastMinY = lastBlockBB[1];
726+
lastMinZ = lastBlockBB[2];
727+
lastMaxX = lastBlockBB[3];
728+
lastMaxY = lastBlockBB[4];
729+
lastMaxZ = lastBlockBB[5];
724730
if (axisData != null) {
725731
// If there's any y distance...
726732
if (dy != 0.0) {
@@ -857,36 +863,36 @@ public static boolean canPassThrough(InteractAxisTracing rayTracing, BlockCache
857863
}
858864
// X
859865
if (dx != 0.0) {
860-
if (nextBlockBB[1] == 0.0 && nextBlockBB[4] == 1.0 && nextBlockBB[2] == 0.0 && nextBlockBB[5] == 1.0) {
861-
if (axisData != null && (dx > 0 ? nextBlockBB[0] != 0.0 : nextBlockBB[3] != 1.0)) {
866+
if (minY == 0.0 && maxY == 1.0 && minZ == 0.0 && maxZ == 1.0) {
867+
if (axisData != null && (dx > 0 ? minX != 0.0 : maxX != 1.0)) {
862868
axisData.dirExclusion = dx > 0 ? Direction.X_POS : Direction.X_NEG;
863869
return true;
864870
}
865871
return rayTracing.getCollidingAxis() != Axis.X_AXIS;
866872
}
867-
if (!mightEdgeInteraction && lastBlockBB != null && (dx > 0 ? lastBlockBB[3] == 1.0 && nextBlockBB[0] == 0.0 : lastBlockBB[0] == 0.0 && nextBlockBB[3]==1.0)
873+
if (!mightEdgeInteraction && lastBlockBB != null && (dx > 0 ? lastMaxX == 1.0 && minX == 0.0 : lastMinX == 0.0 && maxX==1.0)
868874
&& (
869-
nextBlockBB[1] == 0.0 && lastBlockBB[1] == 0.0 && nextBlockBB[4] == 1.0 && lastBlockBB[4] == 1.0
870-
&& MathUtil.equal(MathUtil.getCoveredSpace(lastBlockBB[2], lastBlockBB[5], nextBlockBB[2], nextBlockBB[5]), 1.0, 0.001)
871-
|| nextBlockBB[2] == 0.0 && lastBlockBB[2] == 0.0 && nextBlockBB[5] == 1.0 && lastBlockBB[5] == 1.0
872-
&& MathUtil.equal(MathUtil.getCoveredSpace(lastBlockBB[1], lastBlockBB[4], nextBlockBB[1], nextBlockBB[4]), 1.0, 0.001)
875+
minY == 0.0 && lastMinY == 0.0 && maxY == 1.0 && lastMaxY == 1.0
876+
&& MathUtil.equal(MathUtil.getCoveredSpace(lastMinZ, lastMaxZ, minZ, maxZ), 1.0, 0.001)
877+
|| minZ == 0.0 && lastMinZ == 0.0 && maxZ == 1.0 && lastMaxZ == 1.0
878+
&& MathUtil.equal(MathUtil.getCoveredSpace(lastMinY, lastMaxY, minY, maxY), 1.0, 0.001)
873879
)) {
874880
return false;
875881
}
876882
return true;
877883
}
878884
// Z
879885
if (dz != 0) {
880-
if (nextBlockBB[0] == 0.0 && nextBlockBB[3] == 1.0 && nextBlockBB[1] == 0.0 && nextBlockBB[4] == 1.0) {
881-
if (axisData != null && (dz > 0 ? nextBlockBB[2] != 0.0 : nextBlockBB[5] != 1.0)) {
886+
if (minX == 0.0 && maxX == 1.0 && minY == 0.0 && maxY == 1.0) {
887+
if (axisData != null && (dz > 0 ? minZ != 0.0 : maxZ != 1.0)) {
882888
axisData.dirExclusion = dz > 0 ? Direction.Z_POS : Direction.Z_NEG;
883889
return true;
884890
}
885891
return rayTracing.getCollidingAxis() != Axis.Z_AXIS;
886892
}
887-
if (!mightEdgeInteraction && lastBlockBB != null && (dz > 0 ? lastBlockBB[5] == 1.0 && nextBlockBB[2] == 0.0 : lastBlockBB[2] == 0.0 && nextBlockBB[5]==1.0)
888-
&& (nextBlockBB[1] == 0.0 && lastBlockBB[1] == 0.0 && nextBlockBB[4] == 1.0 && lastBlockBB[4] == 1.0 && MathUtil.equal(MathUtil.getCoveredSpace(lastBlockBB[0], lastBlockBB[3], nextBlockBB[0], nextBlockBB[3]), 1.0, 0.001)
889-
|| nextBlockBB[0] == 0.0 && lastBlockBB[0] == 0.0 && nextBlockBB[3] == 1.0 && lastBlockBB[3] == 1.0 && MathUtil.equal(MathUtil.getCoveredSpace(lastBlockBB[1], lastBlockBB[4], nextBlockBB[1], nextBlockBB[4]), 1.0, 0.001))) return false;
893+
if (!mightEdgeInteraction && lastBlockBB != null && (dz > 0 ? lastMaxZ == 1.0 && minZ == 0.0 : lastMinZ == 0.0 && maxZ==1.0)
894+
&& (minY == 0.0 && lastMinY == 0.0 && maxY == 1.0 && lastMaxY == 1.0 && MathUtil.equal(MathUtil.getCoveredSpace(lastMinX, lastMaxX, minX, maxX), 1.0, 0.001)
895+
|| minX == 0.0 && lastMinX == 0.0 && maxX == 1.0 && lastMaxX == 1.0 && MathUtil.equal(MathUtil.getCoveredSpace(lastMinY, lastMaxY, minY, maxY), 1.0, 0.001))) return false;
890896
return true;
891897
}
892898
return false;

0 commit comments

Comments
 (0)