Skip to content

Commit

Permalink
Deobfuscate and document purpose of misunderstood code in traverseBlo…
Browse files Browse the repository at this point in the history
…cks()
  • Loading branch information
Axionize committed Sep 17, 2024
1 parent e2f3722 commit 8ffeaf7
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,27 @@ public static HitData traverseBlocks(GrimPlayer player, double[] start, double[]
double posYInverse = ySign == 0 ? Double.MAX_VALUE : ySign / yDiff;
double posZInverse = zSign == 0 ? Double.MAX_VALUE : zSign / zDiff;

double d12 = posXInverse * (xSign > 0 ? 1.0D - GrimMath.frac(startX) : GrimMath.frac(startX));
double d13 = posYInverse * (ySign > 0 ? 1.0D - GrimMath.frac(startY) : GrimMath.frac(startY));
double d14 = posZInverse * (zSign > 0 ? 1.0D - GrimMath.frac(startZ) : GrimMath.frac(startZ));

// Can't figure out what this code does currently
while (d12 <= 1.0D || d13 <= 1.0D || d14 <= 1.0D) {
if (d12 < d13) {
if (d12 < d14) {
double tMaxX = posXInverse * (xSign > 0 ? 1.0D - GrimMath.frac(startX) : GrimMath.frac(startX));
double tMaxY = posYInverse * (ySign > 0 ? 1.0D - GrimMath.frac(startY) : GrimMath.frac(startY));
double tMaxZ = posZInverse * (zSign > 0 ? 1.0D - GrimMath.frac(startZ) : GrimMath.frac(startZ));

// tMax represents the maximum distance along each axis before crossing a block boundary
// The loop continues until the ray has crossed a block boundary along all axes
while (tMaxX <= 1.0D || tMaxY <= 1.0D || tMaxZ <= 1.0D) {
if (tMaxX < tMaxY) {
if (tMaxX < tMaxZ) {
floorStartX += xSign;
d12 += posXInverse;
tMaxX += posXInverse;
} else {
floorStartZ += zSign;
d14 += posZInverse;
tMaxZ += posZInverse;
}
} else if (d13 < d14) {
} else if (tMaxY < tMaxZ) {
floorStartY += ySign;
d13 += posYInverse;
tMaxY += posYInverse;
} else {
floorStartZ += zSign;
d14 += posZInverse;
tMaxZ += posZInverse;
}

state = player.compensatedWorld.getWrappedBlockStateAt(floorStartX, floorStartY, floorStartZ);
Expand Down Expand Up @@ -851,8 +852,6 @@ public static HitData getNearestReachHitResult(GrimPlayer player, double[] eyePo
eyePos[2] + lookVec[2] * maxDistance
};

StateType heldItem = null;

return traverseBlocks(player, eyePos, endPos, (block, vector3i) -> {
ClientVersion clientVersion = player.getClientVersion();
CollisionBox data = HitboxData.getBlockHitbox(player, null, clientVersion, block, vector3i.getX(), vector3i.getY(), vector3i.getZ());
Expand Down

0 comments on commit 8ffeaf7

Please sign in to comment.