60 lines
2.3 KiB
Lua
60 lines
2.3 KiB
Lua
minetest.register_craftitem("circuits:rotator", {
|
|
description = "The rotator",
|
|
inventory_image = "rotator.png",
|
|
on_place = function(itemstack, user, pointed_thing)
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
if not string.startsWith(node.name,"circuits:cable_")
|
|
then return itemstack
|
|
end
|
|
|
|
local new = circuits.rotateCable(string.without(node.name,"circuits:cable_"),1)
|
|
minetest.swap_node(pointed_thing.under, {name = "circuits:cable_" .. new})
|
|
return itemstack
|
|
end
|
|
})
|
|
minetest.register_craftitem("circuits:linker", {
|
|
description = "The linker",
|
|
inventory_image = "linker.png",
|
|
on_place = function(itemstack, user, pointed_thing)
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
if not string.startsWith(node.name,"circuits:cable_")
|
|
then return itemstack
|
|
end
|
|
|
|
local index = circuits.lookingAtNbIndex(user,pointed_thing.under)
|
|
|
|
-- We check if we clicked the last selected node
|
|
local meta = minetest.get_meta(pointed_thing.under)
|
|
if meta:get_int("circuits:last_selected_nb") ~= 0
|
|
then
|
|
-- We connect
|
|
local firsti = meta:get_int("circuits:last_selected_nb")
|
|
local new = circuits.connectInCable(string.without(node.name,"circuits:cable_"),firsti,index)
|
|
minetest.swap_node(pointed_thing.under, {name = "circuits:cable_" .. new})
|
|
|
|
-- We destroy the saved selected nb
|
|
meta:set_int("circuits:last_selected_nb",0)
|
|
else
|
|
-- We save the selected nb
|
|
meta:set_int("circuits:last_selected_nb",index)
|
|
end
|
|
return itemstack
|
|
end
|
|
})
|
|
minetest.register_craftitem("circuits:unlinker", {
|
|
description = "The unlinker",
|
|
inventory_image = "unlinker.png",
|
|
on_place = function(itemstack, user, pointed_thing)
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
if not string.startsWith(node.name,"circuits:cable_")
|
|
then return itemstack
|
|
end
|
|
|
|
local index = circuits.lookingAtNbIndex(user,pointed_thing.under)
|
|
|
|
local new = circuits.disconnectInCable(string.without(node.name,"circuits:cable_"),index)
|
|
minetest.swap_node(pointed_thing.under, {name = "circuits:cable_" .. new})
|
|
|
|
return itemstack
|
|
end
|
|
}) |