2016-03-12 08:21:56 +01:00
|
|
|
|
|
|
|
local reverse = true
|
|
|
|
|
|
|
|
local function destruct_bed(pos, n)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local other
|
|
|
|
|
|
|
|
if n == 2 then
|
|
|
|
local dir = minetest.facedir_to_dir(node.param2)
|
|
|
|
other = vector.subtract(pos, dir)
|
|
|
|
elseif n == 1 then
|
|
|
|
local dir = minetest.facedir_to_dir(node.param2)
|
|
|
|
other = vector.add(pos, dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
if reverse then
|
|
|
|
reverse = not reverse
|
|
|
|
minetest.remove_node(other)
|
2016-11-22 05:45:31 +01:00
|
|
|
minetest.check_for_falling(other)
|
2020-01-26 18:59:44 +01:00
|
|
|
beds.remove_spawns_at(pos)
|
|
|
|
beds.remove_spawns_at(other)
|
2016-03-12 08:21:56 +01:00
|
|
|
else
|
|
|
|
reverse = not reverse
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-24 11:59:15 +01:00
|
|
|
function beds.register_bed(name, def)
|
|
|
|
minetest.register_node(name .. "_bottom", {
|
|
|
|
description = def.description,
|
|
|
|
inventory_image = def.inventory_image,
|
|
|
|
wield_image = def.wield_image,
|
|
|
|
drawtype = "nodebox",
|
|
|
|
tiles = def.tiles.bottom,
|
2021-02-06 15:40:26 +01:00
|
|
|
use_texture_alpha = "clip",
|
2015-02-24 11:59:15 +01:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2015-06-14 05:58:54 +02:00
|
|
|
is_ground_content = false,
|
2015-02-24 11:59:15 +01:00
|
|
|
stack_max = 1,
|
2016-12-04 07:55:32 +01:00
|
|
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 1},
|
2017-01-12 18:45:59 +01:00
|
|
|
sounds = def.sounds or default.node_sound_wood_defaults(),
|
2015-02-24 11:59:15 +01:00
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
2015-11-14 06:10:38 +01:00
|
|
|
fixed = def.nodebox.bottom,
|
2015-02-24 11:59:15 +01:00
|
|
|
},
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2015-11-14 06:10:38 +01:00
|
|
|
fixed = def.selectionbox,
|
2015-02-24 11:59:15 +01:00
|
|
|
},
|
2016-03-08 04:14:29 +01:00
|
|
|
|
2016-03-19 02:55:56 +01:00
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
local under = pointed_thing.under
|
2017-02-12 01:23:43 +01:00
|
|
|
local node = minetest.get_node(under)
|
|
|
|
local udef = minetest.registered_nodes[node.name]
|
|
|
|
if udef and udef.on_rightclick and
|
2017-10-01 15:41:58 +02:00
|
|
|
not (placer and placer:is_player() and
|
|
|
|
placer:get_player_control().sneak) then
|
2017-02-12 01:23:43 +01:00
|
|
|
return udef.on_rightclick(under, node, placer, itemstack,
|
|
|
|
pointed_thing) or itemstack
|
|
|
|
end
|
|
|
|
|
2016-03-19 02:55:56 +01:00
|
|
|
local pos
|
2017-08-10 09:52:53 +02:00
|
|
|
if udef and udef.buildable_to then
|
2016-03-19 02:55:56 +01:00
|
|
|
pos = under
|
|
|
|
else
|
|
|
|
pos = pointed_thing.above
|
2015-02-24 11:59:15 +01:00
|
|
|
end
|
2016-03-19 02:55:56 +01:00
|
|
|
|
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
|
|
|
|
minetest.record_protection_violation(pos, player_name)
|
2016-03-19 02:55:56 +01:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2016-06-26 14:46:15 +02:00
|
|
|
local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
|
|
|
|
if not node_def or not node_def.buildable_to then
|
2016-03-31 16:21:40 +02:00
|
|
|
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
|
2016-03-19 02:55:56 +01:00
|
|
|
local botpos = vector.add(pos, minetest.facedir_to_dir(dir))
|
|
|
|
|
2017-10-01 15:41:58 +02:00
|
|
|
if minetest.is_protected(botpos, player_name) and
|
|
|
|
not minetest.check_player_privs(player_name, "protection_bypass") then
|
|
|
|
minetest.record_protection_violation(botpos, player_name)
|
2016-03-19 02:55:56 +01:00
|
|
|
return itemstack
|
2015-02-24 11:59:15 +01:00
|
|
|
end
|
2016-03-19 02:55:56 +01:00
|
|
|
|
2016-03-31 16:21:40 +02:00
|
|
|
local botdef = minetest.registered_nodes[minetest.get_node(botpos).name]
|
|
|
|
if not botdef or not botdef.buildable_to then
|
2016-03-19 02:55:56 +01:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
|
|
|
|
minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
|
|
|
|
|
2020-12-13 18:59:19 +01:00
|
|
|
if not minetest.is_creative_enabled(player_name) then
|
2016-03-19 02:55:56 +01:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
2016-03-08 04:14:29 +01:00
|
|
|
|
2015-02-24 11:59:15 +01:00
|
|
|
on_destruct = function(pos)
|
2016-03-12 08:21:56 +01:00
|
|
|
destruct_bed(pos, 1)
|
2015-02-24 11:59:15 +01:00
|
|
|
end,
|
2016-03-08 04:14:29 +01:00
|
|
|
|
2016-07-01 22:43:02 +02:00
|
|
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
2015-02-24 11:59:15 +01:00
|
|
|
beds.on_rightclick(pos, clicker)
|
2016-07-01 22:43:02 +02:00
|
|
|
return itemstack
|
2015-02-24 11:59:15 +01:00
|
|
|
end,
|
2016-03-08 04:14:29 +01:00
|
|
|
|
2019-02-08 02:53:55 +01:00
|
|
|
on_rotate = function(pos, node, user, _, new_param2)
|
2015-05-13 11:49:11 +02:00
|
|
|
local dir = minetest.facedir_to_dir(node.param2)
|
|
|
|
local p = vector.add(pos, dir)
|
|
|
|
local node2 = minetest.get_node_or_nil(p)
|
2023-05-20 12:17:43 +02:00
|
|
|
if not node2 or minetest.get_item_group(node2.name, "bed") ~= 2 or
|
|
|
|
node.param2 ~= node2.param2 then
|
2015-05-13 11:49:11 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
if minetest.is_protected(p, user:get_player_name()) then
|
|
|
|
minetest.record_protection_violation(p, user:get_player_name())
|
|
|
|
return false
|
|
|
|
end
|
2019-02-08 02:53:55 +01:00
|
|
|
if new_param2 % 32 > 3 then
|
2015-05-13 11:49:11 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
local newp = vector.add(pos, minetest.facedir_to_dir(new_param2))
|
|
|
|
local node3 = minetest.get_node_or_nil(newp)
|
2016-06-26 14:46:15 +02:00
|
|
|
local node_def = node3 and minetest.registered_nodes[node3.name]
|
|
|
|
if not node_def or not node_def.buildable_to then
|
2015-05-13 11:49:11 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
if minetest.is_protected(newp, user:get_player_name()) then
|
|
|
|
minetest.record_protection_violation(newp, user:get_player_name())
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
node.param2 = new_param2
|
2016-03-19 02:55:56 +01:00
|
|
|
-- do not remove_node here - it will trigger destroy_bed()
|
|
|
|
minetest.set_node(p, {name = "air"})
|
|
|
|
minetest.set_node(pos, node)
|
|
|
|
minetest.set_node(newp, {name = name .. "_top", param2 = new_param2})
|
2015-05-13 11:49:11 +02:00
|
|
|
return true
|
|
|
|
end,
|
2018-06-19 23:07:01 +02:00
|
|
|
can_dig = function(pos, player)
|
|
|
|
return beds.can_dig(pos)
|
|
|
|
end,
|
2015-02-24 11:59:15 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node(name .. "_top", {
|
|
|
|
drawtype = "nodebox",
|
|
|
|
tiles = def.tiles.top,
|
2021-02-06 15:40:26 +01:00
|
|
|
use_texture_alpha = "clip",
|
2015-02-24 11:59:15 +01:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2015-06-14 05:58:54 +02:00
|
|
|
is_ground_content = false,
|
2015-11-11 08:49:12 +01:00
|
|
|
pointable = false,
|
2020-11-11 16:29:43 +01:00
|
|
|
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 2,
|
|
|
|
not_in_creative_inventory = 1},
|
2017-01-12 18:45:59 +01:00
|
|
|
sounds = def.sounds or default.node_sound_wood_defaults(),
|
2016-03-12 08:21:56 +01:00
|
|
|
drop = name .. "_bottom",
|
2015-02-24 11:59:15 +01:00
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = def.nodebox.top,
|
2015-11-14 06:10:38 +01:00
|
|
|
},
|
2016-03-12 08:21:56 +01:00
|
|
|
on_destruct = function(pos)
|
|
|
|
destruct_bed(pos, 2)
|
|
|
|
end,
|
2018-06-19 23:07:01 +02:00
|
|
|
can_dig = function(pos, player)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local dir = minetest.facedir_to_dir(node.param2)
|
|
|
|
local p = vector.add(pos, dir)
|
|
|
|
return beds.can_dig(p)
|
|
|
|
end,
|
2015-02-24 11:59:15 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_alias(name, name .. "_bottom")
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = name,
|
|
|
|
recipe = def.recipe
|
|
|
|
})
|
|
|
|
end
|