Add additional bed placing attempts

This commit is contained in:
teknomunk 2024-04-20 11:03:06 +00:00
parent 84d6b593b2
commit 0839f35a12
1 changed files with 30 additions and 18 deletions

View File

@ -133,6 +133,26 @@ if minetest.get_modpath("mcl_sounds") then
}) })
end end
local function place_bed(name, placer, pos, dir)
local botpos = vector_add(pos, minetest_facedir_to_dir(dir))
if minetest.is_protected(botpos, placer:get_player_name()) and
not minetest.check_player_privs(placer, "protection_bypass") then
minetest.record_protection_violation(botpos, placer:get_player_name())
return false
end
local botdef = minetest.registered_nodes[minetest_get_node(botpos).name]
if not botdef or not botdef.buildable_to then
return false
end
minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
return true
end
function mcl_beds.register_bed(name, def) function mcl_beds.register_bed(name, def)
local common_box = { local common_box = {
type = "fixed", type = "fixed",
@ -197,26 +217,18 @@ function mcl_beds.register_bed(name, def)
return itemstack return itemstack
end end
-- Try to place in three directions: inline with the view and rotated to
-- the right and left
local dir = minetest.dir_to_facedir(placer:get_look_dir()) local dir = minetest.dir_to_facedir(placer:get_look_dir())
local botpos = vector_add(pos, minetest_facedir_to_dir(dir)) if place_bed(name, placer, pos, dir) or
place_bed(name, placer, pos, (dir+1)%4) or
if minetest.is_protected(botpos, placer:get_player_name()) and place_bed(name, placer, pos, (dir+3)%4) or
not minetest.check_player_privs(placer, "protection_bypass") then place_bed(name, placer, pos, (dir+2)%4) then
minetest.record_protection_violation(botpos, placer:get_player_name()) -- Bed was places
return itemstack
end
local botdef = minetest.registered_nodes[minetest_get_node(botpos).name]
if not botdef or not botdef.buildable_to then
return itemstack
end
minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
if not minetest.is_creative_enabled(placer:get_player_name()) then if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item() itemstack:take_item()
end end
end
return itemstack return itemstack
end, end,