Use on_repair when repairing tube (#37)
* Use on_repair when repairing tube * Use tube.on_repair * Verify was_node registration
This commit is contained in:
parent
7b15bdbd1f
commit
75894355d4
@ -64,28 +64,39 @@ pipeworks.register_tube("pipeworks:broken_tube", {
|
||||
local itemstack = puncher:get_wielded_item()
|
||||
local wieldname = itemstack:get_name()
|
||||
local playername = puncher:get_player_name()
|
||||
local log_msg = playername.." struck a broken tube at "..minetest.pos_to_string(pos).."\n"
|
||||
local log_msg = playername.." struck a broken tube at "..minetest.pos_to_string(pos).."\n "
|
||||
local meta = minetest.get_meta(pos)
|
||||
local was_node = minetest.deserialize(meta:get_string("the_tube_was"))
|
||||
if not was_node then
|
||||
pipeworks.logger(log_msg.." but it can't be repaired.")
|
||||
pipeworks.logger(log_msg.."but it can't be repaired.")
|
||||
return
|
||||
end
|
||||
if not pipeworks.check_and_wear_hammer(puncher) then
|
||||
if wieldname == "" then
|
||||
pipeworks.logger(log_msg.." by hand. It's not very effective.")
|
||||
pipeworks.logger(log_msg.."by hand. It's not very effective.")
|
||||
if minetest.settings:get_bool("enable_damage") then
|
||||
minetest.chat_send_player(playername,S("Broken tubes may be a bit sharp. Perhaps try with a hammer?"))
|
||||
puncher:set_hp(puncher:get_hp()-1)
|
||||
end
|
||||
else
|
||||
pipeworks.logger(log_msg.." with "..wieldname.." but that tool is too weak.")
|
||||
pipeworks.logger(log_msg.."with "..wieldname.." but that tool is too weak.")
|
||||
end
|
||||
return
|
||||
end
|
||||
pipeworks.logger(log_msg.." with "..wieldname.." to repair it.")
|
||||
minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 })
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
log_msg = log_msg.."with "..wieldname.." to repair it"
|
||||
local nodedef = minetest.registered_nodes[was_node.name]
|
||||
if nodedef then
|
||||
pipeworks.logger(log_msg..".")
|
||||
if 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)
|
||||
end
|
||||
else
|
||||
pipeworks.logger(log_msg.." but original node "..was_node.name.." is not registered anymore.")
|
||||
minetest.chat_send_player(playername, S("This tube cannot be repaired."))
|
||||
end
|
||||
end
|
||||
}
|
||||
})
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user