diff options
author | Sokomine <wegwerf@anarres.dyndns.org> | 2015-07-31 20:59:21 +0200 |
---|---|---|
committer | Sokomine <wegwerf@anarres.dyndns.org> | 2015-07-31 20:59:21 +0200 |
commit | e52dbe1d4b38c4084ba33bae9be562946ab67099 (patch) | |
tree | 4651da90cec551eebf252edeefaab7cbb3a3cd15 | |
parent | 5ef4dc9794e58b81ef205b6ec40fe9a2f88e12c1 (diff) |
right-clicking on a bench makes the player sit there
-rw-r--r-- | nodes_furniture.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/nodes_furniture.lua b/nodes_furniture.lua index 2c03b10..781e6bf 100644 --- a/nodes_furniture.lua +++ b/nodes_furniture.lua @@ -141,6 +141,41 @@ minetest.register_node("cottages:bench", { } }, is_ground_content = false, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if( not( clicker ) or not( default.player_get_animation )) then + return; + end + + local animation = default.player_get_animation( clicker ); + local pname = clicker:get_player_name(); + + if( animation and animation.animation=="sit") then + default.player_attached[pname] = false + clicker:setpos({x=pos.x,y=pos.y-0.5,z=pos.z}) + 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_set_animation(clicker, "stand", 30) + else + -- the bench is not centered; prevent the player from sitting on air + local p2 = {x=pos.x, y=pos.y, z=pos.z}; + local node = minetest.get_node( pos ); + if not( node ) or node.param2 == 0 then + p2.z = p2.z+0.3; + elseif node.param2 == 1 then + p2.x = p2.x+0.3; + elseif node.param2 == 2 then + p2.z = p2.z-0.3; + elseif node.param2 == 3 then + p2.x = p2.x-0.3; + end + + clicker:set_eye_offset({x=0,y=-7,z=2}, {x=0,y=0,z=0}) + clicker:setpos( p2 ) + default.player_set_animation(clicker, "sit", 30) + clicker:set_physics_override(0, 0, 0) + default.player_attached[pname] = true + end + end }) |