From 649448a2a91fbf3e944b2f2e739f4e2292af1df0 Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 12 Nov 2016 10:55:26 +0100 Subject: [PATCH] Rename nodeupdate and nodeupdate_single and make them part of the official API Now, the renamed forms of nodeupdate and nodeupdate_single are part of the official API. As nodeupdate has been used by Minetest Game and in mods despite of not being part of the official API, we ease the transition by still supporting it for the 0.4.15 release. After the release, the two functions can be removed. The removal will not violate the stability promise, as that promise only includes the official and documented API. Also, make some formerly global functions local. They most likely haven't been used by mods, therefore they won't get stubs with deprecation warnings, hard erroring directly. --- builtin/game/falling.lua | 46 +++++++++++++++++++++++++++------------- doc/lua_api.txt | 9 ++++++++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 1932b170a..ece08b325 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -98,7 +98,7 @@ core.register_entity(":__builtin:falling_node", { core.add_node(np, self.node) end self.object:remove() - nodeupdate(np) + core.check_for_falling(np) return end local vel = self.object:getvelocity() @@ -109,12 +109,12 @@ core.register_entity(":__builtin:falling_node", { end }) -function spawn_falling_node(p, node) +local function spawn_falling_node(p, node) local obj = core.add_entity(p, "__builtin:falling_node") obj:get_luaentity():set_node(node) end -function drop_attached_node(p) +local function drop_attached_node(p) local nn = core.get_node(p).name core.remove_node(p) for _, item in pairs(core.get_node_drops(nn, "")) do @@ -127,7 +127,7 @@ function drop_attached_node(p) end end -function check_attached_node(p, n) +local function check_attached_node(p, n) local def = core.registered_nodes[n.name] local d = {x = 0, y = 0, z = 0} if def.paramtype2 == "wallmounted" then @@ -152,7 +152,7 @@ end -- Some common functions -- -function nodeupdate_single(p) +function core.check_single_for_falling(p) local n = core.get_node(p) if core.get_item_group(n.name, "falling_node") ~= 0 then local p_bottom = {x = p.x, y = p.y - 1, z = p.z} @@ -190,7 +190,7 @@ end -- We don't walk diagonals, only our direct neighbors, and self. -- Down first as likely case, but always before self. The same with sides. -- Up must come last, so that things above self will also fall all at once. -local nodeupdate_neighbors = { +local check_for_falling_neighbors = { {x = -1, y = -1, z = 0}, {x = 1, y = -1, z = 0}, {x = 0, y = -1, z = -1}, @@ -204,7 +204,7 @@ local nodeupdate_neighbors = { {x = 0, y = 1, z = 0}, } -function nodeupdate(p) +function core.check_for_falling(p) -- Round p to prevent falling entities to get stuck. p = vector.round(p) @@ -223,10 +223,10 @@ function nodeupdate(p) n = n + 1 s[n] = {p = p, v = v} -- Select next node from neighbor list. - p = vector.add(p, nodeupdate_neighbors[v]) + p = vector.add(p, check_for_falling_neighbors[v]) -- Now we check out the node. If it is in need of an update, -- it will let us know in the return value (true = updated). - if not nodeupdate_single(p) then + if not core.check_single_for_falling(p) then -- If we don't need to "recurse" (walk) to it then pop -- our previous pos off the stack and continue from there, -- with the v value we were at when we last were at that @@ -258,17 +258,33 @@ end -- Global callbacks -- -function on_placenode(p, node) - nodeupdate(p) +local function on_placenode(p, node) + core.check_for_falling(p) end core.register_on_placenode(on_placenode) -function on_dignode(p, node) - nodeupdate(p) +local function on_dignode(p, node) + core.check_for_falling(p) end core.register_on_dignode(on_dignode) -function on_punchnode(p, node) - nodeupdate(p) +local function on_punchnode(p, node) + core.check_for_falling(p) end core.register_on_punchnode(on_punchnode) + +-- +-- Globally exported functions +-- + +-- TODO remove this function after the 0.4.15 release +function nodeupdate(p) + core.log("deprecated", "nodeupdate: deprecated, please use core.check_for_falling instead") + core.check_for_falling(p) +end + +-- TODO remove this function after the 0.4.15 release +function nodeupdate_single(p) + core.log("deprecated", "nodeupdate_single: deprecated, please use core.check_single_for_falling instead") + core.check_single_for_falling(p) +end diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b9208dbad..7d552c980 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2286,6 +2286,15 @@ and `minetest.auth_reload` call the authetification handler. * increase level of leveled node by level, default `level` equals `1` * if `totallevel > maxlevel`, returns rest (`total-max`) * can be negative for decreasing +* `core.check_single_for_falling(pos)` + * causes an unsupported `group:falling_node` node to fall and causes an + unattached `group:attached_node` node to fall. + * does not spread these updates to neighbours. +* `core.check_for_falling(pos)` + * causes an unsupported `group:falling_node` node to fall and causes an + unattached `group:attached_node` node to fall. + * spread these updates to neighbours and can cause a cascade + of nodes to fall. ### Inventory `minetest.get_inventory(location)`: returns an `InvRef` -- 2.25.1