2015-03-03 21:01:25 +01:00
|
|
|
function beds.register_bed(name, def)
|
2015-04-11 23:12:27 +02:00
|
|
|
minetest.register_node(name, {
|
2015-03-03 21:01:25 +01:00
|
|
|
description = def.description,
|
|
|
|
inventory_image = def.inventory_image,
|
|
|
|
wield_image = def.wield_image,
|
2015-04-11 23:12:27 +02:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = def.mesh,
|
|
|
|
tiles = def.tiles,
|
2015-03-03 21:01:25 +01:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
stack_max = 1,
|
2015-04-11 23:12:27 +02:00
|
|
|
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,bed=1},
|
2015-03-03 21:01:25 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = def.selectionbox,
|
2015-04-11 23:12:27 +02:00
|
|
|
},
|
|
|
|
collision_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = def.collisionbox,
|
2015-03-03 21:01:25 +01:00
|
|
|
},
|
|
|
|
after_place_node = function(pos, placer, itemstack)
|
|
|
|
local n = minetest.get_node_or_nil(pos)
|
|
|
|
if not n or not n.param2 then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
local dir = minetest.facedir_to_dir(n.param2)
|
|
|
|
local p = {x=pos.x+dir.x,y=pos.y,z=pos.z+dir.z}
|
|
|
|
local n2 = minetest.get_node_or_nil(p)
|
|
|
|
local def = minetest.registered_items[n2.name] or nil
|
|
|
|
if not n2 or not def or not def.buildable_to then
|
|
|
|
minetest.remove_node(pos)
|
2015-04-11 23:12:27 +02:00
|
|
|
minetest.chat_send_player(placer:get_player_name(), "No room to place the bed!")
|
2015-03-03 21:01:25 +01:00
|
|
|
return true
|
|
|
|
end
|
2015-04-11 23:12:27 +02:00
|
|
|
minetest.set_node(pos, {name = n.name, param2 = n.param2})
|
2015-03-03 21:01:25 +01:00
|
|
|
return false
|
|
|
|
end,
|
|
|
|
on_rightclick = function(pos, node, clicker)
|
|
|
|
beds.on_rightclick(pos, clicker)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2015-04-11 23:12:27 +02:00
|
|
|
minetest.register_alias(name .. "_bottom", name)
|
|
|
|
minetest.register_alias(name .. "_top", "air")
|
2015-03-03 21:01:25 +01:00
|
|
|
|
|
|
|
-- register recipe
|
|
|
|
minetest.register_craft({
|
|
|
|
output = name,
|
|
|
|
recipe = def.recipe
|
|
|
|
})
|
|
|
|
end
|