blockgame/mods/bg_api/fall_fix.lua

30 lines
832 B
Lua
Raw Normal View History

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, self)
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)