From f7052943ec8ef4ddbde3e1bcf6b50487bd3cfa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Sat, 1 May 2021 15:37:14 +0200 Subject: [PATCH] Fix rays not being cast in a specific direction A bug was introduced in 679e2b1b which caused explosions to not cast rays for environment destruction in the (+X, +Y, +Z) direction. This commit fixes that. --- mods/CORE/mcl_explosions/init.lua | 76 +++++++++++++++---------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index e59e3ea12..d3fb882ce 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -66,46 +66,44 @@ local function compute_sphere_rays(radius) local rays = {} local sphere = {} - for i=1, 2 do + local function add_ray(pos) + sphere[hash_node_position(pos)] = pos + end + + for y = -radius, radius do + for z = -radius, radius do + for x = -radius, 0 do + local d = x * x + y * y + z * z + if d <= radius * radius then + add_ray(vector.new(x, y, z)) + add_ray(vector.new(-x, y, z)) + break + end + end + end + end + + for x = -radius, radius do + for z = -radius, radius do + for y = -radius, 0 do + local d = x * x + y * y + z * z + if d <= radius * radius then + add_ray(vector.new(x, y, z)) + add_ray(vector.new(x, -y, z)) + break + end + end + end + end + + for x = -radius, radius do for y = -radius, radius do - for z = -radius, radius do - for x = -radius, 0, 1 do - local d = x * x + y * y + z * z - if d <= radius * radius then - local pos = { x = x, y = y, z = z } - sphere[hash_node_position(pos)] = pos - break - end - end - end - end - end - - for i=1,2 do - for x = -radius, radius do - for z = -radius, radius do - for y = -radius, 0, 1 do - local d = x * x + y * y + z * z - if d <= radius * radius then - local pos = { x = x, y = y, z = z } - sphere[hash_node_position(pos)] = pos - break - end - end - end - end - end - - for i=1,2 do - for x = -radius, radius do - for y = -radius, radius do - for z = -radius, 0, 1 do - local d = x * x + y * y + z * z - if d <= radius * radius then - local pos = { x = x, y = y, z = z } - sphere[hash_node_position(pos)] = pos - break - end + for z = -radius, 0 do + local d = x * x + y * y + z * z + if d <= radius * radius then + add_ray(vector.new(x, y, z)) + add_ray(vector.new(x, y, -z)) + break end end end