0c9f6a7119
create `bg_api_fall` mod, and move files `falling_node.lua` and `loose_node.lua` to there from `bg_api`. update dependencies in other mods to account for this change.
50 lines
1.3 KiB
Lua
50 lines
1.3 KiB
Lua
local fall_api = load_file("falling_node")
|
|
local attempt_collapse_at = fall_api.attempt_collapse_at
|
|
|
|
|
|
|
|
local function attempt_settle_at (pos)
|
|
local below = pos + blockgame.vector.dirs.down
|
|
if minetest.get_node(below).name == "air" then return end
|
|
|
|
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
|
minetest.set_node(pos, {name = def.stable_version})
|
|
end
|
|
|
|
-- settle nodes that are still (in the future, it will take some time for loose nodes that are still to settle).
|
|
blockgame.register_abm({
|
|
label = "settle loose nodes",
|
|
nodenames = {"group:loose"},
|
|
interval = 30,
|
|
chance = 10,
|
|
action = attempt_settle_at,
|
|
})
|
|
|
|
local function place_loose_node (itemstack, placer, pointed)
|
|
local result = minetest.item_place(itemstack, placer, pointed)
|
|
attempt_collapse_at(pointed.above)
|
|
return result
|
|
end
|
|
|
|
|
|
|
|
function blockgame.register_loose_version (name)
|
|
local def = minetest.registered_nodes[name]
|
|
if not def then return false end
|
|
|
|
local groups = {}
|
|
for key, value in pairs(def.groups) do
|
|
groups[key] = value
|
|
end
|
|
groups.loose = 1
|
|
groups.can_fall = 1
|
|
|
|
blockgame.register_node(name .. "_loose", {
|
|
description = "Loose " .. def.description,
|
|
tiles = def.tiles, -- temporary
|
|
groups = groups,
|
|
on_place = place_loose_node,
|
|
stable_version = name,
|
|
})
|
|
return true
|
|
end
|