Use minetest.swap_node instead of hacky_swap_node 227/head
authorNovatux <nathanael.courant@laposte.net>
Sun, 8 Dec 2013 17:12:44 +0000 (18:12 +0100)
committerNovatux <nathanael.courant@laposte.net>
Sun, 8 Dec 2013 17:12:44 +0000 (18:12 +0100)
mods/default/nodes.lua
mods/doors/init.lua
mods/screwdriver/init.lua

index c9b50818c27166a803ecb1f6b15b67df61e82207..3dee2257d8f1c6e222cdd762f9515735a6c6ba03 100644 (file)
@@ -960,18 +960,13 @@ minetest.register_node("default:furnace_active", {
        end,
 })
 
-function hacky_swap_node(pos,name)
+local function swap_node(pos,name)
        local node = minetest.get_node(pos)
-       local meta = minetest.get_meta(pos)
-       local meta0 = meta:to_table()
        if node.name == name then
                return
        end
        node.name = name
-       local meta0 = meta:to_table()
-       minetest.set_node(pos,node)
-       meta = minetest.get_meta(pos)
-       meta:from_table(meta0)
+       minetest.swap_node(pos,node)
 end
 
 minetest.register_abm({
@@ -1025,7 +1020,7 @@ minetest.register_abm({
                        local percent = math.floor(meta:get_float("fuel_time") /
                                        meta:get_float("fuel_totaltime") * 100)
                        meta:set_string("infotext","Furnace active: "..percent.."%")
-                       hacky_swap_node(pos,"default:furnace_active")
+                       swap_node(pos,"default:furnace_active")
                        meta:set_string("formspec",default.get_furnace_active_formspec(pos, percent))
                        return
                end
@@ -1045,7 +1040,7 @@ minetest.register_abm({
 
                if fuel.time <= 0 then
                        meta:set_string("infotext","Furnace out of fuel")
-                       hacky_swap_node(pos,"default:furnace")
+                       swap_node(pos,"default:furnace")
                        meta:set_string("formspec", default.furnace_inactive_formspec)
                        return
                end
@@ -1053,7 +1048,7 @@ minetest.register_abm({
                if cooked.item:is_empty() then
                        if was_active then
                                meta:set_string("infotext","Furnace is empty")
-                               hacky_swap_node(pos,"default:furnace")
+                               swap_node(pos,"default:furnace")
                                meta:set_string("formspec", default.furnace_inactive_formspec)
                        end
                        return
index 409389946b7e50e4edec0b05b02004d139683155..46ab539b748561cc729219c17325e8c4430be8b3 100644 (file)
@@ -113,14 +113,10 @@ function doors:register_door(name, def)
                local p2 = minetest.get_node(pos).param2
                p2 = params[p2+1]
                
-               local meta = minetest.get_meta(pos):to_table()
-               minetest.set_node(pos, {name=replace_dir, param2=p2})
-               minetest.get_meta(pos):from_table(meta)
+               minetest.swap_node(pos, {name=replace_dir, param2=p2})
                
                pos.y = pos.y-dir
-               meta = minetest.get_meta(pos):to_table()
-               minetest.set_node(pos, {name=replace, param2=p2})
-               minetest.get_meta(pos):from_table(meta)
+               minetest.swap_node(pos, {name=replace, param2=p2})
        end
        
        local function check_player_priv(pos, player)
index af40d0935af36e687dc0d6f38db92de403500698..fbbcea59e0bbb9cc7c05e1aaa5dac3ca437b6661 100644 (file)
@@ -113,12 +113,8 @@ function screwdriver_handler (itemstack,user,pointed_thing)
                                end
                        end
                        --print (dump(axisdir..", "..rotation))
-                       local meta = minetest.get_meta(pos)
-                       local meta0 = meta:to_table()
                        node.param2 = n
-                       minetest.set_node(pos,node)
-                       meta = minetest.get_meta(pos)
-                       meta:from_table(meta0)
+                       minetest.swap_node(pos,node)
                        local item=itemstack:to_table()
                        local item_wear=tonumber((item["wear"]))
                        item_wear=item_wear+327