2016-01-26 02:07:42 +03:00
|
|
|
local function pointed_face(pointed_thing)
|
|
|
|
return pointed_thing.above.y > pointed_thing.under.y -- Top face pointed.
|
2016-01-25 23:01:16 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function sit(pos, node, clicker, pointed_thing)
|
2016-01-26 02:07:42 +03:00
|
|
|
if not pointed_face(pointed_thing) then return end
|
2015-12-04 13:38:18 +03:00
|
|
|
local player = clicker:get_player_name()
|
2015-12-23 14:53:22 +03:00
|
|
|
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
|
|
|
|
|
|
|
for _, p in pairs(objs) do
|
|
|
|
if p:get_player_name() ~= clicker:get_player_name() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-04 13:38:18 +03:00
|
|
|
if default.player_attached[player] == true then
|
|
|
|
pos.y = pos.y - 0.5
|
|
|
|
clicker:setpos(pos)
|
|
|
|
clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
|
|
|
|
clicker:set_physics_override(1, 1, 1)
|
|
|
|
default.player_attached[player] = false
|
|
|
|
default.player_set_animation(clicker, "stand", 30)
|
2016-01-06 02:08:58 +03:00
|
|
|
|
2015-12-04 13:38:18 +03:00
|
|
|
elseif default.player_attached[player] ~= true and node.param2 <= 3 and
|
2016-01-16 19:25:00 +03:00
|
|
|
clicker:get_player_control().sneak == false and
|
2015-12-04 13:38:18 +03:00
|
|
|
clicker:get_player_velocity().x == 0 and
|
|
|
|
clicker:get_player_velocity().y == 0 and
|
|
|
|
clicker:get_player_velocity().z == 0 then
|
|
|
|
|
|
|
|
clicker:set_eye_offset({x=0, y=-7, z=2}, {x=0, y=0, z=0})
|
|
|
|
clicker:set_physics_override(0, 0, 0)
|
|
|
|
clicker:setpos(pos)
|
|
|
|
default.player_attached[player] = true
|
|
|
|
default.player_set_animation(clicker, "sit", 30)
|
|
|
|
|
|
|
|
if node.param2 == 0 then
|
|
|
|
clicker:set_look_yaw(3.15)
|
|
|
|
elseif node.param2 == 1 then
|
|
|
|
clicker:set_look_yaw(7.9)
|
|
|
|
elseif node.param2 == 2 then
|
|
|
|
clicker:set_look_yaw(6.28)
|
|
|
|
elseif node.param2 == 3 then
|
|
|
|
clicker:set_look_yaw(4.75)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-23 14:53:22 +03:00
|
|
|
local function dig(pos, player)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
|
|
|
|
|
|
|
for _, p in pairs(objs) do
|
|
|
|
if not player or not player:is_player() or p:get_player_name() ~= nil or
|
|
|
|
default.player_attached[pname] == true then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-12-04 13:38:18 +03:00
|
|
|
xdecor.register("chair", {
|
|
|
|
description = "Chair",
|
|
|
|
tiles = {"xdecor_wood.png"},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
|
|
|
|
on_rotate = screwdriver.rotate_simple,
|
2016-02-04 18:02:28 +03:00
|
|
|
node_box = xdecor.pixelbox(16, {
|
2016-01-16 23:25:10 +03:00
|
|
|
{3, 0, 11, 2, 16, 2},
|
|
|
|
{11, 0, 11, 2, 16, 2},
|
|
|
|
{5, 9, 11.5, 6, 6, 1},
|
|
|
|
{3, 0, 3, 2, 6, 2},
|
|
|
|
{11, 0, 3, 2, 6, 2},
|
|
|
|
{3, 6, 3, 10, 2, 8}
|
2016-01-16 19:25:00 +03:00
|
|
|
}),
|
2015-12-23 14:53:22 +03:00
|
|
|
can_dig = dig,
|
2016-01-25 23:01:16 +03:00
|
|
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
2015-12-04 13:38:18 +03:00
|
|
|
pos.y = pos.y + 0 -- Sitting position.
|
2016-01-25 23:01:16 +03:00
|
|
|
sit(pos, node, clicker, pointed_thing)
|
2015-12-04 13:38:18 +03:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
xdecor.register("cushion", {
|
|
|
|
description = "Cushion",
|
|
|
|
tiles = {"xdecor_cushion.png"},
|
|
|
|
groups = {snappy=3, flammable=3, fall_damage_add_percent=-50},
|
|
|
|
on_place = minetest.rotate_node,
|
2016-01-16 19:25:00 +03:00
|
|
|
node_box = xdecor.nodebox.slab_y(0.5),
|
2015-12-23 14:53:22 +03:00
|
|
|
can_dig = dig,
|
2016-01-25 15:03:20 +03:00
|
|
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
2016-01-06 02:08:58 +03:00
|
|
|
pos.y = pos.y + 0
|
2016-01-25 23:01:16 +03:00
|
|
|
sit(pos, node, clicker, pointed_thing)
|
2016-01-25 15:03:20 +03:00
|
|
|
|
|
|
|
local wield_item = clicker:get_wielded_item():get_name()
|
|
|
|
if wield_item == "xdecor:cushion" and clicker:get_player_control().sneak then
|
|
|
|
local player_name = clicker:get_player_name()
|
|
|
|
if minetest.is_protected(pos, player_name) then
|
|
|
|
minetest.record_protection_violation(pos, player_name)
|
|
|
|
return
|
|
|
|
end
|
2016-01-25 23:01:16 +03:00
|
|
|
|
2016-01-26 02:07:42 +03:00
|
|
|
if pointed_face(pointed_thing) then
|
|
|
|
minetest.set_node(pos, {name="xdecor:cushion_block", param2=node.param2})
|
2016-01-25 23:01:16 +03:00
|
|
|
end
|
|
|
|
|
2016-01-25 15:03:20 +03:00
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
itemstack:take_item()
|
|
|
|
end
|
2016-01-26 02:07:42 +03:00
|
|
|
|
|
|
|
return itemstack
|
2016-01-25 15:03:20 +03:00
|
|
|
end
|
2015-12-04 13:38:18 +03:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|