131 lines
3.1 KiB
Lua
Raw Normal View History

function beds.register_bed(name, def)
local new_tiles
local new_mesh = "beds_simple_bed.obj"
-- old api texture check
if def.tiles and def.tiles.bottom then
new_tiles = "beds_simple_bed.png" -- default
-- check for fancy bed
if def.nodebox and def.nodebox.bottom and #def.nodebox.bottom > 3 then
new_tiles = "beds_fancy_bed.png"
new_mesh = "beds_fancy_bed.obj"
end
end
-- register bed node
minetest.register_node(name, {
2015-02-24 11:59:15 +01:00
description = def.description,
inventory_image = def.inventory_image,
wield_image = def.wield_image,
drawtype = "mesh",
mesh = def.mesh or new_mesh,
tiles = new_tiles or def.tiles,
2015-02-24 11:59:15 +01:00
paramtype = "light",
paramtype2 = "facedir",
stack_max = 1,
groups = {
choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 1,
fall_damage_add_percent = -40, bouncy = 85
2015-02-24 11:59:15 +01:00
},
sounds = default.node_sound_wood_defaults(),
2015-02-24 11:59:15 +01:00
selection_box = {
type = "fixed",
fixed = def.selectionbox
},
collision_box = {
type = "fixed",
fixed = def.collisionbox
2015-02-24 11:59:15 +01:00
},
2016-03-08 03:14:29 +00:00
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local udef = minetest.registered_nodes[node.name]
if udef and udef.on_rightclick
and not (placer and placer:is_player()
and placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end
local pos
if udef and udef.buildable_to then
pos = under
else
pos = pointed_thing.above
2015-02-24 11:59:15 +01:00
end
2017-10-01 15:41:58 +02:00
local player_name = placer and placer:get_player_name() or ""
if minetest.is_protected(pos, player_name)
and not minetest.check_player_privs(player_name, "protection_bypass") then
2017-10-01 15:41:58 +02:00
minetest.record_protection_violation(pos, player_name)
return itemstack
end
local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if not node_def or not node_def.buildable_to then
return itemstack
end
2017-10-01 15:41:58 +02:00
local dir = placer and placer:get_look_dir() and
minetest.dir_to_facedir(placer:get_look_dir()) or 0
local botpos = vector.add(pos, minetest.facedir_to_dir(dir))
if minetest.is_protected(botpos, player_name)
and not minetest.check_player_privs(player_name, "protection_bypass") then
2017-10-01 15:41:58 +02:00
minetest.record_protection_violation(botpos, player_name)
return itemstack
2015-02-24 11:59:15 +01:00
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, param2 = dir})
if not beds.is_creative(player_name) then
itemstack:take_item()
end
2016-03-08 03:14:29 +00:00
return itemstack
2015-02-24 11:59:15 +01:00
end,
2016-03-08 03:14:29 +00:00
on_rightclick = function(pos, node, clicker)
beds.on_rightclick(pos, clicker)
end,
2015-02-24 11:59:15 +01:00
on_destruct = function(pos)
beds.remove_spawns_at(pos)
end,
can_dig = function(pos, player)
return beds.can_dig(pos)
end
2015-02-24 11:59:15 +01:00
})
minetest.register_alias(name .. "_bottom", name)
minetest.register_alias(name .. "_top", "air")
2015-02-24 11:59:15 +01:00
-- register recipe
2015-02-24 11:59:15 +01:00
minetest.register_craft({
output = name,
recipe = def.recipe
})
end