This commit is contained in:
kay27 2021-01-16 22:50:29 +04:00
parent fe33f172d4
commit 5400cdba35

View file

@ -1,23 +1,23 @@
local S = minetest.get_translator("mcl_beds") local S = minetest.get_translator("mcl_beds")
local reverse = true local function destruct_bed(pos, oldnode)
local node = oldnode or minetest.get_node(pos)
local function destruct_bed(pos, is_top) if not node then return end
local node = minetest.get_node(pos)
local other
local dir = minetest.facedir_to_dir(node.param2) local dir = minetest.facedir_to_dir(node.param2)
if is_top then local pos2, node2
other = vector.subtract(pos, dir) if string.sub(node.name, -4) == "_top" then
else pos2 = vector.subtract(pos, dir)
other = vector.add(pos, dir) node2 = minetest.get_node(pos2)
end if node2 and string.sub(node2.name, -7) == "_bottom" then
minetest.remove_node(pos2)
if reverse then end
reverse = not reverse minetest.check_for_falling(pos)
minetest.remove_node(other) elseif string.sub(node.name, -7) == "_bottom" then
minetest.check_for_falling(other) pos2 = vector.add(pos, dir)
else node2 = minetest.get_node(pos2)
reverse = not reverse if node2 and string.sub(node2.name, -4) == "_top" then
minetest.remove_node(pos2)
end
end end
end end
@ -139,10 +139,7 @@ function mcl_beds.register_bed(name, def)
return itemstack return itemstack
end, end,
on_destruct = function(pos) after_destruct = destruct_bed,
destruct_bed(pos, false)
kick_player_after_destruct(pos)
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
mcl_beds.on_rightclick(pos, clicker, false) mcl_beds.on_rightclick(pos, clicker, false)
@ -205,7 +202,7 @@ function mcl_beds.register_bed(name, def)
_mcl_hardness = 0.2, _mcl_hardness = 0.2,
_mcl_blast_resistance = 1, _mcl_blast_resistance = 1,
sounds = def.sounds or default_sounds, sounds = def.sounds or default_sounds,
drop = name .. "_bottom", drop = "",
node_box = node_box_top, node_box = node_box_top,
selection_box = selection_box_top, selection_box = selection_box_top,
collision_box = collision_box_top, collision_box = collision_box_top,
@ -214,10 +211,7 @@ function mcl_beds.register_bed(name, def)
return itemstack return itemstack
end, end,
on_rotate = false, on_rotate = false,
on_destruct = function(pos) after_destruct = destruct_bed,
destruct_bed(pos, true)
kick_player_after_destruct(pos)
end,
}) })
minetest.register_alias(name, name .. "_bottom") minetest.register_alias(name, name .. "_bottom")