Use tube.on_repair

This commit is contained in:
SX 2022-06-21 23:39:39 +03:00 committed by GitHub
parent 1e10718a07
commit 64fb579dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -84,8 +84,9 @@ pipeworks.register_tube("pipeworks:broken_tube", {
return
end
pipeworks.logger(log_msg.." with "..wieldname.." to repair it.")
if minetest.registered_nodes[was_node.name].on_repair then
minetest.registered_nodes[was_node.name].on_repair(pos, was_node, puncher)
local nodedef = minetest.registered_nodes[was_node.name]
if nodedef and nodedef.tube and nodedef.tube.on_repair then
nodedef.tube.on_repair(pos, was_node)
else
minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 })
pipeworks.scan_for_tube_objects(pos)

View File

@ -184,6 +184,18 @@ pipeworks.register_tube("pipeworks:teleport_tube", {
pos.y = target[d].y
pos.z = target[d].z
return pipeworks.meseadjlist
end,
on_repair = function(pos, node)
local meta = minetest.get_meta(pos)
local channel = meta:get_string("channel")
minetest.swap_node(pos, { name = node.name, param2 = node.param2 })
pipeworks.scan_for_tube_objects(pos)
if channel ~= "" then
local can_receive = meta:get_int("can_receive")
set_tube(pos, channel, can_receive)
local cr_description = (can_receive == 1) and "sending and receiving" or "sending"
meta:set_string("infotext", S("Teleportation Tube @1 on '@2'", cr_description, channel))
end
end
},
on_construct = function(pos)
@ -259,18 +271,6 @@ pipeworks.register_tube("pipeworks:teleport_tube", {
end,
on_destruct = function(pos)
remove_tube(pos)
end,
on_repair = function(pos, node)
local meta = minetest.get_meta(pos)
local channel = meta:get_string("channel")
minetest.swap_node(pos, { name = node.name, param2 = node.param2 })
pipeworks.scan_for_tube_objects(pos)
if channel ~= "" then
local can_receive = meta:get_int("can_receive")
set_tube(pos, channel, can_receive)
local cr_description = (can_receive == 1) and "sending and receiving" or "sending"
meta:set_string("infotext", S("Teleportation Tube @1 on '@2'", cr_description, channel))
end
end
},
})