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 committed Oct 25, 2019
1 parent 34de1dc commit 47daa08
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 @@ -897,6 +897,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 47daa08

Please sign in to comment.