e1103a07e4
modify the builtin `falling_node` entity to make it possible for mods to register callbacks to be called when they land and turn into a node. also register such a callback that checks if the landed node has an entry `after_landing`, and if so calls that.
27 lines
824 B
Lua
27 lines
824 B
Lua
local entity = minetest.registered_entities["__builtin:falling_node"]
|
|
local original_try_place = entity.try_place
|
|
|
|
local after_land_callbacks = {}
|
|
|
|
entity.try_place = function (self, bcp, bcn)
|
|
local result = original_try_place(self, bcp, bcn)
|
|
-- `result` will be true if the falling node landed successfully (afaict from reading `/builtin/game/falling.lua` in the minetest source).
|
|
if result then
|
|
for _, callback in pairs(after_land_callbacks) do
|
|
callback(bcp, bcn)
|
|
end
|
|
end
|
|
return result
|
|
end
|
|
|
|
function blockgame.register_after_falling_node_lands (callback)
|
|
table.insert(after_land_callbacks, callback)
|
|
end
|
|
|
|
blockgame.register_after_falling_node_lands(function (pos, node)
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
if type(def.after_landing) == "function" then
|
|
def.after_landing(pos, node)
|
|
end
|
|
end)
|