]> git.lizzy.rs Git - xdecor.git/blob - sitting.lua
Work Table : use pixel nodeboxes
[xdecor.git] / sitting.lua
1 local function sit(pos, node, clicker)
2         local player = clicker:get_player_name()
3         local objs = minetest.get_objects_inside_radius(pos, 0.1)
4
5         for _, p in pairs(objs) do
6                 if p:get_player_name() ~= clicker:get_player_name() then
7                         return
8                 end
9         end
10
11         if default.player_attached[player] == true then
12                 pos.y = pos.y - 0.5
13                 clicker:setpos(pos)
14                 clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
15                 clicker:set_physics_override(1, 1, 1)
16                 default.player_attached[player] = false
17                 default.player_set_animation(clicker, "stand", 30)
18
19         elseif default.player_attached[player] ~= true and node.param2 <= 3 and
20                         clicker:get_player_velocity().x == 0 and
21                         clicker:get_player_velocity().y == 0 and
22                         clicker:get_player_velocity().z == 0 then
23
24                 clicker:set_eye_offset({x=0, y=-7, z=2}, {x=0, y=0, z=0})
25                 clicker:set_physics_override(0, 0, 0)
26                 clicker:setpos(pos)
27                 default.player_attached[player] = true
28                 default.player_set_animation(clicker, "sit", 30)
29
30                 if node.param2 == 0 then
31                         clicker:set_look_yaw(3.15)
32                 elseif node.param2 == 1 then
33                         clicker:set_look_yaw(7.9)
34                 elseif node.param2 == 2 then
35                         clicker:set_look_yaw(6.28)
36                 elseif node.param2 == 3 then
37                         clicker:set_look_yaw(4.75)
38                 end
39         end
40 end
41
42 local function dig(pos, player)
43         local pname = player:get_player_name()
44         local objs = minetest.get_objects_inside_radius(pos, 0.1)
45
46         for _, p in pairs(objs) do
47                 if not player or not player:is_player() or p:get_player_name() ~= nil or
48                                 default.player_attached[pname] == true then
49                         return false
50                 end
51         end
52
53         return true
54 end
55
56 xdecor.register("chair", {
57         description = "Chair",
58         tiles = {"xdecor_wood.png"},
59         sounds = default.node_sound_wood_defaults(),
60         groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
61         on_rotate = screwdriver.rotate_simple,
62         node_box = {
63                 type = "fixed",
64                 fixed = {{-0.3125, -0.5, 0.1875, -0.1875, 0.5, 0.3125},
65                         {0.1875, -0.5, 0.1875, 0.3125, 0.5, 0.3125},
66                         {-0.1875, 0.025, 0.22, 0.1875, 0.45, 0.28},
67                         {-0.3125, -0.5, -0.3125, -0.1875, -0.125, -0.1875},
68                         {0.1875, -0.5, -0.3125, 0.3125, -0.125, -0.1875},
69                         {-0.3125, -0.125, -0.3125, 0.3125, 0, 0.1875}}
70         },
71         can_dig = dig,
72         on_rightclick = function(pos, node, clicker)
73                 pos.y = pos.y + 0  -- Sitting position.
74                 sit(pos, node, clicker)
75         end
76 })
77
78 xdecor.register("cushion", {
79         description = "Cushion",
80         tiles = {"xdecor_cushion.png"},
81         groups = {snappy=3, flammable=3, fall_damage_add_percent=-50},
82         on_place = minetest.rotate_node,
83         node_box = xdecor.nodebox.slab_y(-0.5, 0.5),
84         can_dig = dig,
85         on_rightclick = function(pos, node, clicker)
86                 pos.y = pos.y + 0
87                 sit(pos, node, clicker)
88         end
89 })
90