From 3280e3040056b2d0735b833b1e7e4d43fac3ec43 Mon Sep 17 00:00:00 2001 From: Peter Strath <168037f38@gmail.com> Date: Fri, 25 Oct 2019 13:31:49 +0100 Subject: [PATCH] Prevent diagonal movement into blocks Fixed in Craft pull request https://github.com/fogleman/Craft/pull/216 from usernamefreaks. Bug report: https://github.com/fogleman/Craft/issues/209 --- src/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main.c b/src/main.c index 02cc1edb2..4974dc209 100644 --- a/src/main.c +++ b/src/main.c @@ -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; }