2022-10-09 14:22:42 +02:00
|
|
|
local function print_to_everything(msg)
|
2024-10-28 15:57:54 +01:00
|
|
|
core.log("action", "[callbacks] " .. msg)
|
|
|
|
core.chat_send_all(msg)
|
2022-10-09 14:22:42 +02:00
|
|
|
end
|
|
|
|
|
2024-10-28 15:57:54 +01:00
|
|
|
core.register_node("callbacks:callback_node", {
|
2022-10-09 14:22:42 +02:00
|
|
|
description = "Callback Test Node (construct/destruct/timer)".."\n"..
|
|
|
|
"Tests callbacks: on_construct, after_place_node, on_destruct, after_destruct, after_dig_node, on_timer",
|
|
|
|
tiles = {"callbacks_callback_node.png"},
|
2022-10-08 18:58:02 +02:00
|
|
|
groups = {callback_test=1, dig_immediate=3},
|
2024-10-28 15:57:54 +01:00
|
|
|
-- This was known to cause a bug in core.item_place_node() when used
|
|
|
|
-- via core.place_node(), causing a placer with no position
|
2022-10-09 14:22:42 +02:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
drop = "",
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
2024-10-28 15:57:54 +01:00
|
|
|
print_to_everything("callbacks:callback_node:on_construct("..core.pos_to_string(pos)..")")
|
|
|
|
local meta = core.get_meta(pos)
|
2022-10-09 14:22:42 +02:00
|
|
|
meta:set_string("mine", "test")
|
2024-10-28 15:57:54 +01:00
|
|
|
local timer = core.get_node_timer(pos)
|
2022-10-09 14:22:42 +02:00
|
|
|
timer:start(4, 3)
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
2024-10-28 15:57:54 +01:00
|
|
|
print_to_everything("callbacks:callback_node:after_place_node("..core.pos_to_string(pos)..")")
|
|
|
|
local meta = core.get_meta(pos)
|
2022-10-09 14:22:42 +02:00
|
|
|
if meta:get_string("mine") == "test" then
|
|
|
|
print_to_everything("correct metadata found")
|
|
|
|
else
|
|
|
|
print_to_everything("incorrect metadata found")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_destruct = function(pos)
|
2024-10-28 15:57:54 +01:00
|
|
|
print_to_everything("callbacks:callback_node:on_destruct("..core.pos_to_string(pos)..")")
|
2022-10-09 14:22:42 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
after_destruct = function(pos)
|
2024-10-28 15:57:54 +01:00
|
|
|
print_to_everything("callbacks:callback_node:after_destruct("..core.pos_to_string(pos)..")")
|
2022-10-09 14:22:42 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2024-10-28 15:57:54 +01:00
|
|
|
print_to_everything("callbacks:callback_node:after_dig_node("..core.pos_to_string(pos)..")")
|
2022-10-09 14:22:42 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_timer = function(pos, elapsed)
|
|
|
|
print_to_everything("callbacks:callback_node:on_timer(): elapsed="..dump(elapsed))
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|