neighbors.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. -- test ABMs with neighbor and without_neighbor
  2. local S = core.get_translator("testnodes")
  3. -- ABM required neighbor
  4. core.register_node("testabms:required_neighbor", {
  5. description = S("Node for test ABM required_neighbor.") .. "\n"
  6. .. S("Sensitive neighbor node is testnodes:normal."),
  7. drawtype = "normal",
  8. tiles = { "testabms_wait_node.png" },
  9. groups = { dig_immediate = 3 },
  10. on_construct = function (pos)
  11. local meta = core.get_meta(pos)
  12. meta:set_string("infotext",
  13. "Waiting for ABM testabms:required_neighbor "
  14. .. "(normal drawtype testnode sensitive)")
  15. end,
  16. })
  17. core.register_abm({
  18. label = "testabms:required_neighbor",
  19. nodenames = "testabms:required_neighbor",
  20. neighbors = {"testnodes:normal"},
  21. interval = 1,
  22. chance = 1,
  23. action = function (pos)
  24. core.swap_node(pos, {name="testabms:after_abm"})
  25. local meta = core.get_meta(pos)
  26. meta:set_string("infotext",
  27. "ABM testabsm:required_neighbor changed this node.")
  28. end
  29. })
  30. -- ABM missing neighbor node
  31. core.register_node("testabms:missing_neighbor", {
  32. description = S("Node for test ABM missing_neighbor.") .. "\n"
  33. .. S("Sensitive neighbor node is testnodes:normal."),
  34. drawtype = "normal",
  35. tiles = { "testabms_wait_node.png" },
  36. groups = { dig_immediate = 3 },
  37. on_construct = function (pos)
  38. local meta = core.get_meta(pos)
  39. meta:set_string("infotext",
  40. "Waiting for ABM testabms:missing_neighbor"
  41. .. " (normal drawtype testnode sensitive)")
  42. end,
  43. })
  44. core.register_abm({
  45. label = "testabms:missing_neighbor",
  46. nodenames = "testabms:missing_neighbor",
  47. without_neighbors = {"testnodes:normal"},
  48. interval = 1,
  49. chance = 1,
  50. action = function (pos)
  51. core.swap_node(pos, {name="testabms:after_abm"})
  52. local meta = core.get_meta(pos)
  53. meta:set_string("infotext",
  54. "ABM testabsm:missing_neighbor changed this node.")
  55. end
  56. })
  57. -- ABM required and missing neighbor node
  58. core.register_node("testabms:required_missing_neighbor", {
  59. description = S("Node for test ABM required_missing_neighbor.") .. "\n"
  60. .. S("Sensitive neighbor nodes are testnodes:normal and testnodes:glasslike."),
  61. drawtype = "normal",
  62. tiles = { "testabms_wait_node.png" },
  63. groups = { dig_immediate = 3 },
  64. on_construct = function (pos)
  65. local meta = core.get_meta(pos)
  66. meta:set_string("infotext",
  67. "Waiting for ABM testabms:required_missing_neighbor"
  68. .. " (wint normal drawtype testnode and no glasslike"
  69. .. " drawtype testnode sensitive)")
  70. end,
  71. })
  72. core.register_abm({
  73. label = "testabms:required_missing_neighbor",
  74. nodenames = "testabms:required_missing_neighbor",
  75. neighbors = {"testnodes:normal"},
  76. without_neighbors = {"testnodes:glasslike"},
  77. interval = 1,
  78. chance = 1,
  79. action = function (pos)
  80. core.swap_node(pos, {name="testabms:after_abm"})
  81. local meta = core.get_meta(pos)
  82. meta:set_string("infotext",
  83. "ABM testabsm:required_missing_neighbor changed this node.")
  84. end
  85. })