diff options
author | sfan5 <sfan5@live.de> | 2017-01-28 11:33:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-28 11:33:13 +0100 |
commit | 07d074075c82dd762fa9d6d3b1b5a466a77f177b (patch) | |
tree | 24888b630f12b5ae616ce3636ed14504c6ca5072 /mesecons_fpga/tool.lua | |
parent | 518885301494805f92e29fcab299c2d277d4fb46 (diff) |
FPGAs (#315)
Diffstat (limited to 'mesecons_fpga/tool.lua')
-rw-r--r-- | mesecons_fpga/tool.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/mesecons_fpga/tool.lua b/mesecons_fpga/tool.lua new file mode 100644 index 0000000..26ab49e --- /dev/null +++ b/mesecons_fpga/tool.lua @@ -0,0 +1,62 @@ +return function(plg) + + +minetest.register_tool("mesecons_fpga:programmer", { + description = "FPGA Programmer", + inventory_image = "jeija_fpga_programmer.png", + stack_max = 1, + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + local pos = pointed_thing.under + if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then + return itemstack + end + + local meta = minetest.get_meta(pos) + if meta:get_string("instr") == "//////////////" then + minetest.chat_send_player(placer:get_player_name(), "This FPGA is unprogrammed.") + return itemstack + end + itemstack:set_metadata(meta:get_string("instr")) + minetest.chat_send_player(placer:get_player_name(), "FPGA gate configuration was successfully copied!") + + return itemstack + end, + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + local pos = pointed_thing.under + if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then + return itemstack + end + + local imeta = itemstack:get_metadata() + if imeta == "" then + minetest.chat_send_player(user:get_player_name(), "Use shift+right-click to copy a gate configuration first.") + return itemstack + end + + local meta = minetest.get_meta(pos) + meta:set_string("instr", imeta) + plg.update_formspec(pos, imeta) + minetest.chat_send_player(user:get_player_name(), "Gate configuration was successfully written to FPGA!") + + return itemstack + end +}) + +minetest.register_craft({ + output = "mesecons_fpga:programmer", + recipe = { + {'group:mesecon_conductor_craftable'}, + {'mesecons_materials:silicon'}, + } +}) + + +end |