From ef7370550f69e8f3834604aa02dddf63653c7f6c Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 8 Feb 2022 01:45:54 +0100 Subject: [PATCH] Make fire spread direction truly random This patch initializes the random number generator used in mcl_fire with the current Unix timestamp. It also corrects two biases in fire spread that were caused by nodes being iterated over in a predictable way. --- mods/ITEMS/mcl_fire/init.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_fire/init.lua b/mods/ITEMS/mcl_fire/init.lua index 05091554..8e2383da 100644 --- a/mods/ITEMS/mcl_fire/init.lua +++ b/mods/ITEMS/mcl_fire/init.lua @@ -36,12 +36,14 @@ local adjacents = { { x = 0, y = 0, z = 1 }, } -local function shuffle_adjacents() - for i = #adjacents, 1, -1 do +math.randomseed(os.time()) +local function shuffle_table(t) + for i = #t, 1, -1 do local r = math.random(i) - adjacents[i], adjacents[r] = adjacents[r], adjacents[i] + t[i], t[r] = t[r], t[i] end end +shuffle_table(adjacents) local function has_flammable(pos) for k,v in pairs(adjacents) do @@ -368,6 +370,7 @@ minetest.register_abm({ local function check_aircube(p1,p2) local nds=minetest.find_nodes_in_area(p1,p2,{"air"}) + shuffle_table(nds) for k,v in pairs(nds) do if has_flammable(v) then return v end end @@ -409,7 +412,7 @@ else -- Fire enabled local p = get_ignitable(pos) if p then spawn_fire(p) - shuffle_adjacents() + shuffle_table(adjacents) end end })