rangecheck.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. local DIST = vector.distance
  2. local RANGE = 6 + DIST({x=0,y=0,z=0},{x=.5,y=.5,z=.5})
  3. local OFFSET = function(v, y) return {x = v.x, y = v.y + y, z = v.z} end
  4. function falldamage.apply_range_checks(def)
  5. if def.allow_metadata_inventory_move then
  6. local func = def.allow_metadata_inventory_move
  7. function def.allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
  8. if DIST(pos, OFFSET(player:get_pos(), player:get_properties().eye_height)) > RANGE then
  9. return 0
  10. end
  11. afk_removal.reset_timeout(player:get_player_name())
  12. return func(pos, from_list, from_index, to_list, to_index, count, player)
  13. end
  14. elseif def.on_metadata_inventory_move then
  15. -- If no `allow' function defined, then define a default func.
  16. function def.allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
  17. if DIST(pos, OFFSET(player:get_pos(), player:get_properties().eye_height)) > RANGE then
  18. return 0
  19. end
  20. afk_removal.reset_timeout(player:get_player_name())
  21. return count
  22. end
  23. end
  24. if def.allow_metadata_inventory_put then
  25. local func = def.allow_metadata_inventory_put
  26. function def.allow_metadata_inventory_put(pos, listname, index, stack, player)
  27. if DIST(pos, OFFSET(player:get_pos(), player:get_properties().eye_height)) > RANGE then
  28. return 0
  29. end
  30. afk_removal.reset_timeout(player:get_player_name())
  31. return func(pos, listname, index, stack, player)
  32. end
  33. elseif def.on_metadata_inventory_put then
  34. -- If no `allow' function defined, then define a default func.
  35. function def.allow_metadata_inventory_put(pos, listname, index, stack, player)
  36. if DIST(pos, OFFSET(player:get_pos(), player:get_properties().eye_height)) > RANGE then
  37. return 0
  38. end
  39. afk_removal.reset_timeout(player:get_player_name())
  40. return stack:get_count()
  41. end
  42. end
  43. if def.allow_metadata_inventory_take then
  44. local func = def.allow_metadata_inventory_take
  45. function def.allow_metadata_inventory_take(pos, listname, index, stack, player)
  46. if DIST(pos, OFFSET(player:get_pos(), player:get_properties().eye_height)) > RANGE then
  47. return 0
  48. end
  49. afk_removal.reset_timeout(player:get_player_name())
  50. return func(pos, listname, index, stack, player)
  51. end
  52. elseif def.on_metadata_inventory_take then
  53. -- If no `allow' function defined, then define a default func.
  54. function def.allow_metadata_inventory_take(pos, listname, index, stack, player)
  55. if DIST(pos, OFFSET(player:get_pos(), player:get_properties().eye_height)) > RANGE then
  56. return 0
  57. end
  58. afk_removal.reset_timeout(player:get_player_name())
  59. return stack:get_count()
  60. end
  61. end
  62. end