local formspec = function(pos)
local meta = minetest.env:get_meta(pos)
local target = meta:get_string("target")
return "field[0,0;target;" .. target .. "]"
end
local on_rightclick = function(pos, node, player, itemstack, pointed_thing)
minetest.show_formspec(player:get_player_name(), "target", formspec(pos))
end
local on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos)
print("receive")
print(minetest.serialize(fields))
if(fields.target and fields.target ~= "") then
meta:set_string("target", fields.target)
end
end
local on_punch = function (pos, node)
local meta = minetest.env:get_meta(pos)
local target = meta:get_string("target")
if(target and target ~= "") then
local destination = minetest.string_to_pos(target)
diginet:send({source=pos, destination=destination, method="button"})
end
end
minetest.register_node("diginet:button", {
drawtype = "nodebox",
TODO tiles = {
"jeija_wall_button_sides.png",
"jeija_wall_button_sides.png",
"jeija_wall_button_sides.png",
"jeija_wall_button_sides.png",
"jeija_wall_button_sides.png",
"jeija_wall_button_off.png"
},
paramtype = "light",
paramtype2 = "facedir",
legacy_wallmounted = true,
walkable = false,
sunlight_propagates = true,
selection_box = {
type = "fixed",
fixed = { -6/16, -6/16, 5/16, 6/16, 6/16, 8/16 }
},
node_box = {
type = "fixed",
fixed = {
{ -6/16, -6/16, 6/16, 6/16, 6/16, 8/16 },
{ -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 }
}
},
groups = {dig_immediate=2},
description = "Button",
on_punch = on_punch,
on_rightclick = on_rightclick,
on_receive_fields = on_receive_fields,
sounds = default.node_sound_stone_defaults(),
})