Skip to content

Commit 649448a

Browse files
committedNov 14, 2016
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.
1 parent 6707d62 commit 649448a

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed
 

‎builtin/game/falling.lua

+31-15
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ core.register_entity(":__builtin:falling_node", {
9898
core.add_node(np, self.node)
9999
end
100100
self.object:remove()
101-
nodeupdate(np)
101+
core.check_for_falling(np)
102102
return
103103
end
104104
local vel = self.object:getvelocity()
@@ -109,12 +109,12 @@ core.register_entity(":__builtin:falling_node", {
109109
end
110110
})
111111

112-
function spawn_falling_node(p, node)
112+
local function spawn_falling_node(p, node)
113113
local obj = core.add_entity(p, "__builtin:falling_node")
114114
obj:get_luaentity():set_node(node)
115115
end
116116

117-
function drop_attached_node(p)
117+
local function drop_attached_node(p)
118118
local nn = core.get_node(p).name
119119
core.remove_node(p)
120120
for _, item in pairs(core.get_node_drops(nn, "")) do
@@ -127,7 +127,7 @@ function drop_attached_node(p)
127127
end
128128
end
129129

130-
function check_attached_node(p, n)
130+
local function check_attached_node(p, n)
131131
local def = core.registered_nodes[n.name]
132132
local d = {x = 0, y = 0, z = 0}
133133
if def.paramtype2 == "wallmounted" then
@@ -152,7 +152,7 @@ end
152152
-- Some common functions
153153
--
154154

155-
function nodeupdate_single(p)
155+
function core.check_single_for_falling(p)
156156
local n = core.get_node(p)
157157
if core.get_item_group(n.name, "falling_node") ~= 0 then
158158
local p_bottom = {x = p.x, y = p.y - 1, z = p.z}
@@ -190,7 +190,7 @@ end
190190
-- We don't walk diagonals, only our direct neighbors, and self.
191191
-- Down first as likely case, but always before self. The same with sides.
192192
-- Up must come last, so that things above self will also fall all at once.
193-
local nodeupdate_neighbors = {
193+
local check_for_falling_neighbors = {
194194
{x = -1, y = -1, z = 0},
195195
{x = 1, y = -1, z = 0},
196196
{x = 0, y = -1, z = -1},
@@ -204,7 +204,7 @@ local nodeupdate_neighbors = {
204204
{x = 0, y = 1, z = 0},
205205
}
206206

207-
function nodeupdate(p)
207+
function core.check_for_falling(p)
208208
-- Round p to prevent falling entities to get stuck.
209209
p = vector.round(p)
210210

@@ -223,10 +223,10 @@ function nodeupdate(p)
223223
n = n + 1
224224
s[n] = {p = p, v = v}
225225
-- Select next node from neighbor list.
226-
p = vector.add(p, nodeupdate_neighbors[v])
226+
p = vector.add(p, check_for_falling_neighbors[v])
227227
-- Now we check out the node. If it is in need of an update,
228228
-- it will let us know in the return value (true = updated).
229-
if not nodeupdate_single(p) then
229+
if not core.check_single_for_falling(p) then
230230
-- If we don't need to "recurse" (walk) to it then pop
231231
-- our previous pos off the stack and continue from there,
232232
-- with the v value we were at when we last were at that
@@ -258,17 +258,33 @@ end
258258
-- Global callbacks
259259
--
260260

261-
function on_placenode(p, node)
262-
nodeupdate(p)
261+
local function on_placenode(p, node)
262+
core.check_for_falling(p)
263263
end
264264
core.register_on_placenode(on_placenode)
265265

266-
function on_dignode(p, node)
267-
nodeupdate(p)
266+
local function on_dignode(p, node)
267+
core.check_for_falling(p)
268268
end
269269
core.register_on_dignode(on_dignode)
270270

271-
function on_punchnode(p, node)
272-
nodeupdate(p)
271+
local function on_punchnode(p, node)
272+
core.check_for_falling(p)
273273
end
274274
core.register_on_punchnode(on_punchnode)
275+
276+
--
277+
-- Globally exported functions
278+
--
279+
280+
-- TODO remove this function after the 0.4.15 release
281+
function nodeupdate(p)
282+
core.log("deprecated", "nodeupdate: deprecated, please use core.check_for_falling instead")
283+
core.check_for_falling(p)
284+
end
285+
286+
-- TODO remove this function after the 0.4.15 release
287+
function nodeupdate_single(p)
288+
core.log("deprecated", "nodeupdate_single: deprecated, please use core.check_single_for_falling instead")
289+
core.check_single_for_falling(p)
290+
end

‎doc/lua_api.txt

+9
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,15 @@ and `minetest.auth_reload` call the authetification handler.
22862286
* increase level of leveled node by level, default `level` equals `1`
22872287
* if `totallevel > maxlevel`, returns rest (`total-max`)
22882288
* can be negative for decreasing
2289+
* `core.check_single_for_falling(pos)`
2290+
* causes an unsupported `group:falling_node` node to fall and causes an
2291+
unattached `group:attached_node` node to fall.
2292+
* does not spread these updates to neighbours.
2293+
* `core.check_for_falling(pos)`
2294+
* causes an unsupported `group:falling_node` node to fall and causes an
2295+
unattached `group:attached_node` node to fall.
2296+
* spread these updates to neighbours and can cause a cascade
2297+
of nodes to fall.
22892298

22902299
### Inventory
22912300
`minetest.get_inventory(location)`: returns an `InvRef`

0 commit comments

Comments
 (0)
Please sign in to comment.