tool.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. return function(plg)
  2. minetest.register_tool("mesecons_fpga:programmer", {
  3. description = "FPGA Programmer",
  4. inventory_image = "jeija_fpga_programmer.png",
  5. stack_max = 1,
  6. on_place = function(itemstack, placer, pointed_thing)
  7. if pointed_thing.type ~= "node" then
  8. return itemstack
  9. end
  10. local pos = pointed_thing.under
  11. if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then
  12. return itemstack
  13. end
  14. local meta = minetest.get_meta(pos)
  15. if meta:get_string("instr") == "//////////////" then
  16. minetest.chat_send_player(placer:get_player_name(), "This FPGA is unprogrammed.")
  17. return itemstack
  18. end
  19. itemstack:set_metadata(meta:get_string("instr"))
  20. minetest.chat_send_player(placer:get_player_name(), "FPGA gate configuration was successfully copied!")
  21. return itemstack
  22. end,
  23. on_use = function(itemstack, user, pointed_thing)
  24. if pointed_thing.type ~= "node" then
  25. return itemstack
  26. end
  27. local pos = pointed_thing.under
  28. if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then
  29. return itemstack
  30. end
  31. local imeta = itemstack:get_metadata()
  32. if imeta == "" then
  33. minetest.chat_send_player(user:get_player_name(), "Use shift+right-click to copy a gate configuration first.")
  34. return itemstack
  35. end
  36. local meta = minetest.get_meta(pos)
  37. meta:set_string("instr", imeta)
  38. plg.update_formspec(pos, imeta)
  39. minetest.chat_send_player(user:get_player_name(), "Gate configuration was successfully written to FPGA!")
  40. return itemstack
  41. end
  42. })
  43. minetest.register_craft({
  44. output = "mesecons_fpga:programmer",
  45. recipe = {
  46. {'group:mesecon_conductor_craftable'},
  47. {'mesecons_materials:silicon'},
  48. }
  49. })
  50. end