Logikraft/blocks/circuit.lua

39 lines
1.3 KiB
Lua

local _contexts = {}
function circuits.setNameFormspec(targetType, defaultName)
local text = "Please enter the name of this " .. targetType
local formspec = {
"formspec_version[4]",
"size[6,3.476]",
"label[0.375,0.5;", minetest.formspec_escape(text), "]",
"field[0.375,1.25;5.25,0.8;name;".. minetest.formspec_escape(targetType) .. " name;"..(defaultName or "").."]",
"button[1.5,2.3;3,0.8;commit;OK]"
}
-- table.concat is faster than string concatenation - `..`
return table.concat(formspec, "")
end
function circuits.showSetNameFormspec(playerName, targetName)
minetest.show_formspec(playerName, "circuits:setNameFormSpec", circuits.setNameFormspec(targetName))
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "circuits:setNameFormSpec" then return end
if fields.commit then
local pname = player:get_player_name()
minetest.chat_send_all(pname .. " guessed " .. fields.name)
end
end)
minetest.register_node("circuits:circuitBlock", {
description = "Circuit Block",
tiles = {"circuit_block.png"},
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
circuits.discoverBlocks(pos)
end,
groups = {circuitry = 1,dig_immediate = 3}
})