2023-10-18 21:30:00 +00:00
|
|
|
local entity = minetest.registered_entities["__builtin:falling_node"]
|
|
|
|
|
2023-10-19 09:19:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
local original_try_place = entity.try_place
|
2023-10-18 21:30:00 +00:00
|
|
|
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
|
2023-10-19 09:19:32 +00:00
|
|
|
callback(bcp, bcn, self)
|
2023-10-18 21:30:00 +00:00
|
|
|
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)
|