Add minetest.spawn_falling_node(pos) (#5339)
authorzaoqi <zaomir@outlook.com>
Sat, 4 Mar 2017 17:36:37 +0000 (01:36 +0800)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 4 Mar 2017 17:36:37 +0000 (18:36 +0100)
* Add minetest.spawn_falling_node(pos)

* lua_api.txt: Add minetest.spawn_falling_node(pos)

* Update minetest.spawn_falling_node(pos)

builtin/game/falling.lua
doc/lua_api.txt

index 5ef5289be7a1d04534ef8d566ce1c978be244b3b..7649093613351f298d25741d0e073579b76e571a 100644 (file)
@@ -118,6 +118,20 @@ local function spawn_falling_node(p, node)
        end
 end
 
+function core.spawn_falling_node(pos)
+       local node = core.get_node(pos)
+       if node.name == "air" or node.name == "ignore" then
+               return false
+       end
+       local obj = core.add_entity(pos, "__builtin:falling_node")
+       if obj then
+               obj:get_luaentity():set_node(node)
+               core.remove_node(pos)
+               return true
+       end
+       return false
+end
+
 local function drop_attached_node(p)
        local nn = core.get_node(p).name
        core.remove_node(p)
index 7b956dc74263c05c9d69f33119f9616a50f2c0c7..23aac90d9d0a2796298d14e2f50c11685ad2ca7d 100644 (file)
@@ -2219,6 +2219,9 @@ and `minetest.auth_reload` call the authetification handler.
     * Returns `true` if successful, `false` on failure (e.g. protected location)
 * `minetest.punch_node(pos)`
     * Punch node with the same effects that a player would cause
+* `minetest.spawn_falling_node(pos)`
+    * Change node into falling node
+    * Returns `true` if successful, `false` on failure
 
 * `minetest.find_nodes_with_meta(pos1, pos2)`
     * Get a table of positions of nodes that have metadata within a region {pos1, pos2}