nodes.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local function print_to_everything(msg)
  2. core.log("action", "[callbacks] " .. msg)
  3. core.chat_send_all(msg)
  4. end
  5. core.register_node("callbacks:callback_node", {
  6. description = "Callback Test Node (construct/destruct/timer)".."\n"..
  7. "Tests callbacks: on_construct, after_place_node, on_destruct, after_destruct, after_dig_node, on_timer",
  8. tiles = {"callbacks_callback_node.png"},
  9. groups = {callback_test=1, dig_immediate=3},
  10. -- This was known to cause a bug in core.item_place_node() when used
  11. -- via core.place_node(), causing a placer with no position
  12. paramtype2 = "facedir",
  13. drop = "",
  14. on_construct = function(pos)
  15. print_to_everything("callbacks:callback_node:on_construct("..core.pos_to_string(pos)..")")
  16. local meta = core.get_meta(pos)
  17. meta:set_string("mine", "test")
  18. local timer = core.get_node_timer(pos)
  19. timer:start(4, 3)
  20. end,
  21. after_place_node = function(pos, placer)
  22. print_to_everything("callbacks:callback_node:after_place_node("..core.pos_to_string(pos)..")")
  23. local meta = core.get_meta(pos)
  24. if meta:get_string("mine") == "test" then
  25. print_to_everything("correct metadata found")
  26. else
  27. print_to_everything("incorrect metadata found")
  28. end
  29. end,
  30. on_destruct = function(pos)
  31. print_to_everything("callbacks:callback_node:on_destruct("..core.pos_to_string(pos)..")")
  32. end,
  33. after_destruct = function(pos)
  34. print_to_everything("callbacks:callback_node:after_destruct("..core.pos_to_string(pos)..")")
  35. end,
  36. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  37. print_to_everything("callbacks:callback_node:after_dig_node("..core.pos_to_string(pos)..")")
  38. end,
  39. on_timer = function(pos, elapsed)
  40. print_to_everything("callbacks:callback_node:on_timer(): elapsed="..dump(elapsed))
  41. return true
  42. end,
  43. })