2022-03-19 02:58:29 +03:00
|
|
|
-- Overrides the builtin minetest.check_single_for_falling.
|
|
|
|
-- We need to do this in order to handle nodes in mineclone specific groups
|
|
|
|
-- "supported_node" and "attached_node_facedir".
|
|
|
|
--
|
|
|
|
-- Nodes in group "supported_node" can be placed on any node that does not
|
|
|
|
-- have the "airlike" drawtype. Carpets are an example of this type.
|
|
|
|
|
2022-10-15 16:21:01 +03:00
|
|
|
local pairs = pairs
|
|
|
|
local math = math
|
2021-05-25 13:52:25 +03:00
|
|
|
local vector = vector
|
|
|
|
|
|
|
|
local facedir_to_dir = minetest.facedir_to_dir
|
|
|
|
local get_item_group = minetest.get_item_group
|
|
|
|
local remove_node = minetest.remove_node
|
|
|
|
local get_node = minetest.get_node
|
2022-03-19 02:58:29 +03:00
|
|
|
local get_meta = minetest.get_meta
|
|
|
|
local registered_nodes = minetest.registered_nodes
|
|
|
|
local get_node_drops = minetest.get_node_drops
|
|
|
|
local add_item = minetest.add_item
|
|
|
|
|
|
|
|
-- drop_attached_node(p)
|
|
|
|
--
|
|
|
|
-- This function is copied verbatim from minetest/builtin/game/falling.lua
|
|
|
|
-- We need this to do the exact same dropping node handling in our override
|
|
|
|
-- minetest.check_single_for_falling() function as in the builtin function.
|
|
|
|
--
|
2022-10-15 16:21:01 +03:00
|
|
|
---@param p Vector
|
2022-03-19 02:58:29 +03:00
|
|
|
local function drop_attached_node(p)
|
|
|
|
local n = get_node(p)
|
|
|
|
local drops = get_node_drops(n, "")
|
|
|
|
local def = registered_nodes[n.name]
|
2022-10-15 16:21:01 +03:00
|
|
|
|
2022-03-19 02:58:29 +03:00
|
|
|
if def and def.preserve_metadata then
|
|
|
|
local oldmeta = get_meta(p):to_table().fields
|
|
|
|
-- Copy pos and node because the callback can modify them.
|
2022-10-15 16:21:01 +03:00
|
|
|
local pos_copy = vector.copy(p)
|
|
|
|
local node_copy = { name = n.name, param1 = n.param1, param2 = n.param2 }
|
2022-03-19 02:58:29 +03:00
|
|
|
local drop_stacks = {}
|
|
|
|
for k, v in pairs(drops) do
|
|
|
|
drop_stacks[k] = ItemStack(v)
|
|
|
|
end
|
|
|
|
drops = drop_stacks
|
|
|
|
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
|
|
|
|
end
|
2022-10-15 16:21:01 +03:00
|
|
|
|
2022-03-19 02:58:29 +03:00
|
|
|
if def and def.sounds and def.sounds.fall then
|
2022-10-15 16:21:01 +03:00
|
|
|
minetest.sound_play(def.sounds.fall, { pos = p }, true)
|
2022-03-19 02:58:29 +03:00
|
|
|
end
|
2022-10-15 16:21:01 +03:00
|
|
|
|
2022-03-19 02:58:29 +03:00
|
|
|
remove_node(p)
|
|
|
|
for _, item in pairs(drops) do
|
2022-10-15 16:21:01 +03:00
|
|
|
local pos = vector.offset(p,
|
|
|
|
math.random() / 2 - 0.25,
|
|
|
|
math.random() / 2 - 0.25,
|
|
|
|
math.random() / 2 - 0.25
|
|
|
|
)
|
2022-03-19 02:58:29 +03:00
|
|
|
add_item(pos, item)
|
|
|
|
end
|
|
|
|
end
|
2021-05-25 13:52:25 +03:00
|
|
|
|
2022-03-19 02:58:29 +03:00
|
|
|
-- minetest.check_single_for_falling(pos)
|
|
|
|
--
|
|
|
|
-- * causes an unsupported `group:falling_node` node to fall and causes an
|
|
|
|
-- unattached `group:attached_node` or `group:attached_node_facedir` node
|
2022-03-19 05:16:15 +03:00
|
|
|
-- or unsupported `group:supported_node` node to drop.
|
2022-03-19 02:58:29 +03:00
|
|
|
-- * does not spread these updates to neighbours.
|
|
|
|
--
|
|
|
|
-- Returns true if the node at <pos> has spawned a falling node or has been
|
|
|
|
-- dropped as item(s).
|
|
|
|
--
|
2018-01-08 22:10:44 +03:00
|
|
|
local original_function = minetest.check_single_for_falling
|
|
|
|
|
2021-05-25 13:52:25 +03:00
|
|
|
function minetest.check_single_for_falling(pos)
|
2022-03-19 02:58:29 +03:00
|
|
|
if original_function(pos) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local node = get_node(pos)
|
2021-05-25 13:52:25 +03:00
|
|
|
if get_item_group(node.name, "attached_node_facedir") ~= 0 then
|
|
|
|
local dir = facedir_to_dir(node.param2)
|
2020-02-23 22:37:42 +03:00
|
|
|
if dir then
|
2021-05-25 13:52:25 +03:00
|
|
|
if get_item_group(get_node(vector.add(pos, dir)).name, "solid") == 0 then
|
2022-03-19 02:58:29 +03:00
|
|
|
drop_attached_node(pos)
|
|
|
|
return true
|
2018-01-08 22:10:44 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-03-19 02:58:29 +03:00
|
|
|
|
|
|
|
if get_item_group(node.name, "supported_node") ~= 0 then
|
|
|
|
local def = registered_nodes[get_node(vector.offset(pos, 0, -1, 0)).name]
|
|
|
|
if def and def.drawtype == "airlike" then
|
|
|
|
drop_attached_node(pos)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
2018-01-08 22:10:44 +03:00
|
|
|
end
|