animations.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local function top_face(pointed_thing)
  2. if not pointed_thing then return end
  3. return pointed_thing.above.y > pointed_thing.under.y
  4. end
  5. -- Note: sit code is not used, due to being incompatible with other parts of the game code.
  6. function xdecor.sit(pos, node, clicker, pointed_thing)
  7. if not top_face(pointed_thing) then return end
  8. local player_name = clicker:get_player_name()
  9. local objs = minetest.get_objects_inside_radius(pos, 0.1)
  10. local vel = clicker:get_player_velocity()
  11. local ctrl = clicker:get_player_control()
  12. for _, obj in pairs(objs) do
  13. if obj:is_player() and obj:get_player_name() ~= player_name then
  14. return
  15. end
  16. end
  17. if default.player_attached[player_name] then
  18. pos.y = pos.y - 0.5
  19. clicker:set_pos(pos)
  20. clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
  21. clicker:set_physics_override(1, 1, 1)
  22. default.player_attached[player_name] = false
  23. default.player_set_animation(clicker, "stand", 30)
  24. elseif not default.player_attached[player_name] and node.param2 <= 3 and
  25. not ctrl.sneak and vector.equals(vel, {x=0,y=0,z=0}) then
  26. clicker:set_eye_offset({x=0, y=-7, z=2}, {x=0, y=0, z=0})
  27. clicker:set_physics_override(0, 0, 0)
  28. clicker:set_pos(pos)
  29. default.player_attached[player_name] = true
  30. default.player_set_animation(clicker, "sit", 30)
  31. if node.param2 == 0 then clicker:set_look_yaw(3.15)
  32. elseif node.param2 == 1 then clicker:set_look_yaw(7.9)
  33. elseif node.param2 == 2 then clicker:set_look_yaw(6.28)
  34. elseif node.param2 == 3 then clicker:set_look_yaw(4.75) end
  35. end
  36. end
  37. function xdecor.sit_dig(pos, digger)
  38. for _, player in pairs(minetest.get_objects_inside_radius(pos, 0.1)) do
  39. if player:is_player() and
  40. default.player_attached[player:get_player_name()] then
  41. return false
  42. end
  43. end
  44. return true
  45. end