predicates.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. bt.register_action("IsDaytime", {
  2. tick = function(node, data)
  3. local tod = minetest.get_timeofday() * 24000
  4. if tod > 6000 and tod < 18000 then
  5. return "success"
  6. end
  7. return "failed"
  8. end,
  9. })
  10. bt.register_action("HealthAbove", {
  11. tick = function(node, data)
  12. local hp = data.mob.entity:get_hp()
  13. if hp >= node.n then
  14. return "success"
  15. end
  16. return "failed"
  17. end,
  18. ctor = function(n)
  19. return {
  20. n = n
  21. }
  22. end,
  23. })
  24. bt.register_action("HealthBelow", {
  25. tick = function(node, data)
  26. local hp = data.mob.object:get_hp()
  27. if hp < node.n then
  28. return "success"
  29. end
  30. return "failed"
  31. end,
  32. ctor = function(n)
  33. return {
  34. n = n
  35. }
  36. end,
  37. })
  38. bt.register_action("LightAbove", {
  39. tick = function(node, data)
  40. local l = minetest.get_node_light(data.pos, nil)
  41. if l >= node.n then
  42. return "success"
  43. end
  44. return "failed"
  45. end,
  46. ctor = function(n)
  47. return {
  48. n = n
  49. }
  50. end,
  51. })
  52. bt.register_action("LightBelow", {
  53. tick = function(node, data)
  54. local l = minetest.get_node_light(data.pos, nil)
  55. if l < node.n then
  56. return "success"
  57. end
  58. return "failed"
  59. end,
  60. ctor = function(n)
  61. return {
  62. n = n
  63. }
  64. end,
  65. })
  66. bt.register_action("CarryingItems", {
  67. tick = function(node, data)
  68. if data.inv:contains("main", node.items) then
  69. return "success"
  70. end
  71. return "failed"
  72. end,
  73. ctor = function(items, minCnt)
  74. return {
  75. items=items,
  76. }
  77. end,
  78. })
  79. bt.register_action("NodeIsFull", {
  80. tick = function(node, data)
  81. if data.targetPos == nil then
  82. return "success"
  83. end
  84. local inv = minetest.get_inventory({type="node", pos=data.targetPos})
  85. if inv == nil then
  86. return "success"
  87. end
  88. local sz = inv:get_size("main")
  89. local list = inv:get_list("main")
  90. if table.getn(list) < sz then
  91. return "failed"
  92. end
  93. return "success"
  94. end,
  95. })