animations.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. function xdecor.sit(pos, node, clicker, pointed_thing)
  6. if not top_face(pointed_thing) then return end
  7. local player_name = clicker:get_player_name()
  8. local objs = minetest.get_objects_inside_radius(pos, 0.1)
  9. local vel = clicker:get_player_velocity()
  10. local ctrl = clicker:get_player_control()
  11. for _, obj in pairs(objs) do
  12. if obj:is_player() and obj:get_player_name() ~= player_name then
  13. return
  14. end
  15. end
  16. if default.player_attached[player_name] then
  17. pos.y = pos.y - 0.5
  18. clicker:set_pos(pos)
  19. clicker:set_eye_offset(vector.new(), vector.new())
  20. clicker:set_physics_override({speed = 1, jump = 1, gravity = 1})
  21. default.player_attached[player_name] = false
  22. default.player_set_animation(clicker, "stand", 30)
  23. elseif not default.player_attached[player_name] and node.param2 <= 3 and
  24. not ctrl.sneak and vector.equals(vel, vector.new()) then
  25. clicker:set_eye_offset({x = 0, y = -7, z = 2}, vector.new())
  26. clicker:set_physics_override({speed = 0, jump = 0, gravity = 1})
  27. clicker:set_pos(pos)
  28. default.player_attached[player_name] = true
  29. default.player_set_animation(clicker, "sit", 30)
  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. function xdecor.sit_dig(pos, digger)
  42. for _, player in pairs(minetest.get_objects_inside_radius(pos, 0.1)) do
  43. if player:is_player() and
  44. default.player_attached[player:get_player_name()] then
  45. return false
  46. end
  47. end
  48. return true
  49. end