rangecheck.lua 2.2 KB

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