From 16302cffce1e127ba3527dc2163094aec9a1630c Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 22 Aug 2014 19:59:57 -0400 Subject: [PATCH] Fix chainsaw placing drops and playing sounds at tops of trees --- technic/tools/chainsaw.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/technic/tools/chainsaw.lua b/technic/tools/chainsaw.lua index eaa33bf..36422d9 100644 --- a/technic/tools/chainsaw.lua +++ b/technic/tools/chainsaw.lua @@ -150,8 +150,10 @@ end --- Iterator over positions to try to saw around a sawed node. -- This returns nodes in a 3x2x3 area. It does not return lower (y) positions -- to prevent the chainsaw from cutting down nodes below the cutting position. --- @param pos Reference to sawing position. Note that this is overridden. +-- @param pos Sawing position. local function iterSawTries(pos) + -- Copy position to prevent mangling it + local pos = vector.new(pos) -- Shift the position down on the x and z axes pos.x, pos.z = pos.x - 1, pos.z - 1 -- Save our starting position for reseting it later @@ -199,12 +201,12 @@ local function recursive_dig(pos, remaining_charge) remaining_charge = remaining_charge - chainsaw_charge_per_node -- Check surroundings and run recursively if any charge left - for pos in iterSawTries(pos) do + for npos in iterSawTries(pos) do if remaining_charge < chainsaw_charge_per_node then break end - if timber_nodenames[minetest.get_node(pos).name] then - remaining_charge = recursive_dig(pos, remaining_charge) + if timber_nodenames[minetest.get_node(npos).name] then + remaining_charge = recursive_dig(npos, remaining_charge) end end return remaining_charge -- 2.30.2