chances.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. -- test ABMs with different chances
  2. local S = core.get_translator("testnodes")
  3. -- ABM chance 5 node
  4. core.register_node("testabms:chance_5", {
  5. description = S("Node for test ABM chance_5"),
  6. drawtype = "normal",
  7. tiles = { "testabms_wait_node.png" },
  8. groups = { dig_immediate = 3 },
  9. on_construct = function (pos)
  10. local meta = core.get_meta(pos)
  11. meta:set_string("infotext", "Waiting for ABM testabms:chance_5")
  12. end,
  13. })
  14. core.register_abm({
  15. label = "testabms:chance_5",
  16. nodenames = "testabms:chance_5",
  17. interval = 10,
  18. chance = 5,
  19. action = function (pos)
  20. core.swap_node(pos, {name="testabms:after_abm"})
  21. local meta = core.get_meta(pos)
  22. meta:set_string("infotext", "ABM testabsm:chance_5 changed this node.")
  23. end
  24. })
  25. -- ABM chance 20 node
  26. core.register_node("testabms:chance_20", {
  27. description = S("Node for test ABM chance_20"),
  28. drawtype = "normal",
  29. tiles = { "testabms_wait_node.png" },
  30. groups = { dig_immediate = 3 },
  31. on_construct = function (pos)
  32. local meta = core.get_meta(pos)
  33. meta:set_string("infotext", "Waiting for ABM testabms:chance_20")
  34. end,
  35. })
  36. core.register_abm({
  37. label = "testabms:chance_20",
  38. nodenames = "testabms:chance_20",
  39. interval = 10,
  40. chance = 20,
  41. action = function (pos)
  42. core.swap_node(pos, {name="testabms:after_abm"})
  43. local meta = core.get_meta(pos)
  44. meta:set_string("infotext", "ABM testabsm:chance_20 changed this node.")
  45. end
  46. })