mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-06-06 13:54:25 -04:00
Turned beds' on_destruct callback as a public function
- All calls to beds' `on_destruct` now use `beds.destruct_beds(pos, reverse)` with pos the part's position and reverse a boolean to signify to the function which bedgroup to look for and which vector method to use - Improved drop of beds (top parts now drop bottom parts, aka. beds) - Bed bottoms are made unreachable, but also insensitive to fire
This commit is contained in:
parent
bc119f4eb0
commit
c79bfeef33
2 changed files with 16 additions and 22 deletions
|
@ -1,6 +1,3 @@
|
||||||
-- Variable used to stop recursive destruction
|
|
||||||
local do_not_destruct = false
|
|
||||||
|
|
||||||
function beds.register_bed(name, def)
|
function beds.register_bed(name, def)
|
||||||
minetest.register_node(name .. "_bottom", {
|
minetest.register_node(name .. "_bottom", {
|
||||||
description = def.description,
|
description = def.description,
|
||||||
|
@ -40,14 +37,7 @@ function beds.register_bed(name, def)
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local n = minetest.get_node_or_nil(pos)
|
beds.destroy_bed(pos, false)
|
||||||
if not n then return end
|
|
||||||
local dir = minetest.facedir_to_dir(n.param2)
|
|
||||||
local p = vector.add(pos, dir)
|
|
||||||
local n2 = minetest.get_node(p)
|
|
||||||
if minetest.get_item_group(n2.name, "bed") == 2 and n.param2 == n2.param2 and not do_not_destruct then
|
|
||||||
minetest.remove_node(p)
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
beds.on_rightclick(pos, clicker)
|
beds.on_rightclick(pos, clicker)
|
||||||
|
@ -92,7 +82,7 @@ function beds.register_bed(name, def)
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
pointable = false,
|
pointable = false,
|
||||||
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 2},
|
groups = {bed = 2},
|
||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
|
@ -103,17 +93,9 @@ function beds.register_bed(name, def)
|
||||||
fixed = {0, 0, 0, 0, 0, 0},
|
fixed = {0, 0, 0, 0, 0, 0},
|
||||||
},
|
},
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local n = minetest.get_node_or_nil(pos)
|
beds.destroy_bed(pos, true)
|
||||||
if not n then return end
|
|
||||||
local dir = minetest.facedir_to_dir(n.param2)
|
|
||||||
local p = vector.subtract(pos,dir)
|
|
||||||
local n2 = minetest.get_node(p)
|
|
||||||
if minetest.get_item_group(n2.name, "bed") == 1 and n.param2 == n2.param2 then
|
|
||||||
do_not_destruct = true
|
|
||||||
minetest.remove_node(p)
|
|
||||||
do_not_destruct = false
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
drop = name .. "_bottom",
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_alias(name, name .. "_bottom")
|
minetest.register_alias(name, name .. "_bottom")
|
||||||
|
|
|
@ -7,6 +7,7 @@ if enable_respawn == nil then
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- helper functions
|
-- helper functions
|
||||||
|
|
||||||
local function get_look_yaw(pos)
|
local function get_look_yaw(pos)
|
||||||
|
@ -174,6 +175,17 @@ function beds.on_rightclick(pos, player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function beds.destroy_bed(pos, reverse)
|
||||||
|
local n = minetest.get_node_or_nil(pos)
|
||||||
|
if not n then return end
|
||||||
|
local dir = minetest.facedir_to_dir(n.param2)
|
||||||
|
local p = vector.add(pos, dir)
|
||||||
|
local n2 = minetest.get_node(p)
|
||||||
|
if minetest.get_item_group(n2.name, "bed") == 2 then
|
||||||
|
minetest.remove_node(p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- callbacks
|
-- callbacks
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue