Skip to content

Commit

Permalink
Prevent diagonal movement into blocks
Browse files Browse the repository at this point in the history
Fixed in Craft pull request fogleman#216
from usernamefreaks.

Bug report: fogleman#209
  • Loading branch information
pspiworld authored and tsee committed May 29, 2023
1 parent a45b161 commit 3280e30
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,36 @@ int collide(int height, float *x, float *y, float *z) {
if (pz > pad && is_obstacle(map_get(map, nx, ny - dy, nz + 1))) {
*z = nz + pad;
}

// check the 4 diagonally neighboring blocks for obstacle as well
if (px < -pad && pz > pad && is_obstacle(map_get(map, nx - 1, ny - dy, nz + 1))) {
if(ABS(px) < ABS(pz)) {
*x = nx - pad;
} else {
*z = nz + pad;
}
}
if (px > pad && pz > pad && is_obstacle(map_get(map, nx + 1, ny - dy, nz + 1))) {
if(ABS(px) < ABS(pz)) {
*x = nx + pad;
} else {
*z = nz + pad;
}
}
if (px < -pad && pz < -pad && is_obstacle(map_get(map, nx - 1, ny - dy, nz - 1))) {
if(ABS(px) < ABS(pz)) {
*x = nx - pad;
} else {
*z = nz - pad;
}
}
if (px > pad && pz < -pad && is_obstacle(map_get(map, nx + 1, ny - dy, nz - 1))) {
if(ABS(px) < ABS(pz)) {
*x = nx + pad;
} else {
*z = nz - pad;
}
}
}
return result;
}
Expand Down

0 comments on commit 3280e30

Please sign in to comment.