Fix chainsaw placing drops and playing sounds at tops of trees
authorShadowNinja <shadowninja@minetest.net>
Fri, 22 Aug 2014 23:59:57 +0000 (19:59 -0400)
committerShadowNinja <shadowninja@minetest.net>
Sat, 23 Aug 2014 00:01:15 +0000 (20:01 -0400)
technic/tools/chainsaw.lua

index eaa33bf92c16370ef8dc25756e03d5b51dadecb7..36422d9ae9c9e93673f90224ee6487957eb07999 100644 (file)
@@ -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