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.master
parent
6707d622bb
commit
649448a2a9
|
@ -98,7 +98,7 @@ core.register_entity(":__builtin:falling_node", {
|
||||||
core.add_node(np, self.node)
|
core.add_node(np, self.node)
|
||||||
end
|
end
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
nodeupdate(np)
|
core.check_for_falling(np)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local vel = self.object:getvelocity()
|
local vel = self.object:getvelocity()
|
||||||
|
@ -109,12 +109,12 @@ core.register_entity(":__builtin:falling_node", {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
function spawn_falling_node(p, node)
|
local function spawn_falling_node(p, node)
|
||||||
local obj = core.add_entity(p, "__builtin:falling_node")
|
local obj = core.add_entity(p, "__builtin:falling_node")
|
||||||
obj:get_luaentity():set_node(node)
|
obj:get_luaentity():set_node(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drop_attached_node(p)
|
local function drop_attached_node(p)
|
||||||
local nn = core.get_node(p).name
|
local nn = core.get_node(p).name
|
||||||
core.remove_node(p)
|
core.remove_node(p)
|
||||||
for _, item in pairs(core.get_node_drops(nn, "")) do
|
for _, item in pairs(core.get_node_drops(nn, "")) do
|
||||||
|
@ -127,7 +127,7 @@ function drop_attached_node(p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function check_attached_node(p, n)
|
local function check_attached_node(p, n)
|
||||||
local def = core.registered_nodes[n.name]
|
local def = core.registered_nodes[n.name]
|
||||||
local d = {x = 0, y = 0, z = 0}
|
local d = {x = 0, y = 0, z = 0}
|
||||||
if def.paramtype2 == "wallmounted" then
|
if def.paramtype2 == "wallmounted" then
|
||||||
|
@ -152,7 +152,7 @@ end
|
||||||
-- Some common functions
|
-- Some common functions
|
||||||
--
|
--
|
||||||
|
|
||||||
function nodeupdate_single(p)
|
function core.check_single_for_falling(p)
|
||||||
local n = core.get_node(p)
|
local n = core.get_node(p)
|
||||||
if core.get_item_group(n.name, "falling_node") ~= 0 then
|
if core.get_item_group(n.name, "falling_node") ~= 0 then
|
||||||
local p_bottom = {x = p.x, y = p.y - 1, z = p.z}
|
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.
|
-- We don't walk diagonals, only our direct neighbors, and self.
|
||||||
-- Down first as likely case, but always before self. The same with sides.
|
-- 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.
|
-- 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 = 1, y = -1, z = 0},
|
{x = 1, y = -1, z = 0},
|
||||||
{x = 0, y = -1, z = -1},
|
{x = 0, y = -1, z = -1},
|
||||||
|
@ -204,7 +204,7 @@ local nodeupdate_neighbors = {
|
||||||
{x = 0, y = 1, z = 0},
|
{x = 0, y = 1, z = 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
function nodeupdate(p)
|
function core.check_for_falling(p)
|
||||||
-- Round p to prevent falling entities to get stuck.
|
-- Round p to prevent falling entities to get stuck.
|
||||||
p = vector.round(p)
|
p = vector.round(p)
|
||||||
|
|
||||||
|
@ -223,10 +223,10 @@ function nodeupdate(p)
|
||||||
n = n + 1
|
n = n + 1
|
||||||
s[n] = {p = p, v = v}
|
s[n] = {p = p, v = v}
|
||||||
-- Select next node from neighbor list.
|
-- 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,
|
-- 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).
|
-- 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
|
-- If we don't need to "recurse" (walk) to it then pop
|
||||||
-- our previous pos off the stack and continue from there,
|
-- our previous pos off the stack and continue from there,
|
||||||
-- with the v value we were at when we last were at that
|
-- with the v value we were at when we last were at that
|
||||||
|
@ -258,17 +258,33 @@ end
|
||||||
-- Global callbacks
|
-- Global callbacks
|
||||||
--
|
--
|
||||||
|
|
||||||
function on_placenode(p, node)
|
local function on_placenode(p, node)
|
||||||
nodeupdate(p)
|
core.check_for_falling(p)
|
||||||
end
|
end
|
||||||
core.register_on_placenode(on_placenode)
|
core.register_on_placenode(on_placenode)
|
||||||
|
|
||||||
function on_dignode(p, node)
|
local function on_dignode(p, node)
|
||||||
nodeupdate(p)
|
core.check_for_falling(p)
|
||||||
end
|
end
|
||||||
core.register_on_dignode(on_dignode)
|
core.register_on_dignode(on_dignode)
|
||||||
|
|
||||||
function on_punchnode(p, node)
|
local function on_punchnode(p, node)
|
||||||
nodeupdate(p)
|
core.check_for_falling(p)
|
||||||
end
|
end
|
||||||
core.register_on_punchnode(on_punchnode)
|
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
|
||||||
|
|
|
@ -2286,6 +2286,15 @@ and `minetest.auth_reload` call the authetification handler.
|
||||||
* increase level of leveled node by level, default `level` equals `1`
|
* increase level of leveled node by level, default `level` equals `1`
|
||||||
* if `totallevel > maxlevel`, returns rest (`total-max`)
|
* if `totallevel > maxlevel`, returns rest (`total-max`)
|
||||||
* can be negative for decreasing
|
* 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
|
### Inventory
|
||||||
`minetest.get_inventory(location)`: returns an `InvRef`
|
`minetest.get_inventory(location)`: returns an `InvRef`
|
||||||
|
|
Loading…
Reference in New Issue