1
0
mirror of https://github.com/Sokomine/cottages.git synced 2024-11-05 01:50:20 +01:00

right-clicking on a bench makes the player sit there

This commit is contained in:
Sokomine 2015-07-31 20:59:21 +02:00
parent 5ef4dc9794
commit e52dbe1d4b

View File

@ -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
})