init.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. if not minetest.global_exists("configurator") then configurator = {} end
  2. configurator.modpath = minetest.get_modpath("configurator")
  3. local SHORT_DESCRIPTION = "WR Config Device (Unconfigured)\n\nPunch node to set primary target.\nShift-punch node to set secondary target.\nRightclick node to set tertiary target."
  4. configurator.update_description =
  5. function(stack)
  6. local meta = stack:get_meta()
  7. local p1 = minetest.string_to_pos(meta:get_string("p1"))
  8. local p2 = minetest.string_to_pos(meta:get_string("p2"))
  9. local p3 = minetest.string_to_pos(meta:get_string("p3"))
  10. local s1, s2, s3 = "N/A", "N/A", "N/A"
  11. if p1 then
  12. s1 = rc.pos_to_namestr(p1)
  13. end
  14. if p2 then
  15. s2 = rc.pos_to_namestr(p2)
  16. end
  17. if p3 then
  18. s3 = rc.pos_to_namestr(p3)
  19. end
  20. local desc = "WR Config Device\n\nPrimary: " .. s1 .. "\nSecondary: " .. s2 .. "\nTertiary: " .. s3 .. ""
  21. meta:set_string("description", desc)
  22. end
  23. configurator.on_use =
  24. function(stack, user, pt)
  25. if not user or not user:is_player() then return end
  26. local meta = stack:get_meta()
  27. local pname = user:get_player_name()
  28. if pt.type == "node" then
  29. local ctrl = user:get_player_control()
  30. if ctrl.sneak then
  31. local p2 = pt.under
  32. local s2 = minetest.pos_to_string(p2)
  33. meta:set_string("p2", s2)
  34. minetest.chat_send_player(pname, "# Server: WR-Config set secondary target! " .. rc.pos_to_name(p2) .. ": " .. rc.pos_to_string(p2) .. ".")
  35. else
  36. local p1 = pt.under
  37. local s1 = minetest.pos_to_string(p1)
  38. meta:set_string("p1", s1)
  39. minetest.chat_send_player(pname, "# Server: WR-Config set primary target! " .. rc.pos_to_name(p1) .. ": " .. rc.pos_to_string(p1) .. ".")
  40. end
  41. else
  42. minetest.chat_send_player(pname, "# Server: Set device configuration by punching a node. Also try holding shift or right-clicking.")
  43. end
  44. configurator.update_description(stack)
  45. return stack
  46. end
  47. configurator.on_place =
  48. function(stack, user, pt)
  49. if not user or not user:is_player() then return end
  50. local meta = stack:get_meta()
  51. local pname = user:get_player_name()
  52. if pt.type == "node" then
  53. local p3 = pt.under
  54. local s3 = minetest.pos_to_string(p3)
  55. meta:set_string("p3", s3)
  56. minetest.chat_send_player(pname, "# Server: WR-Config set tertiary target! " .. rc.pos_to_name(p3) .. ": " .. rc.pos_to_string(p3) .. ".")
  57. end
  58. configurator.update_description(stack)
  59. return stack
  60. end
  61. configurator.on_secondary_use =
  62. function(stack, user, pt)
  63. if not user or not user:is_player() then return end
  64. local pname = user:get_player_name()
  65. minetest.chat_send_player(pname, "# Server: Set device configuration by punching a node. Also try holding shift or right-clicking.")
  66. return stack
  67. end
  68. if not configurator.run_once then
  69. minetest.register_craftitem(":cfg:dev", {
  70. description = SHORT_DESCRIPTION,
  71. inventory_image = "configurator_configurator.png",
  72. stack_max = 1, -- Stores meta, so stacks limited to 1. Also used as upgrade item.
  73. on_use = function(...) return configurator.on_use(...) end,
  74. on_place = function(...) return configurator.on_place(...) end,
  75. on_secondary_use = function(...) return configurator.on_secondary_use(...) end,
  76. })
  77. minetest.register_alias("configurator:configurator", "cfg:dev")
  78. minetest.register_craft({
  79. output = "cfg:dev",
  80. recipe = {
  81. {'', 'fine_wire:silver', ''},
  82. {'', 'techcrafts:control_logic_unit', ''},
  83. {'', 'techcrafts:copper_coil', ''},
  84. },
  85. })
  86. local c = "configurator:core"
  87. local f = configurator.modpath .. "/init.lua"
  88. reload.register_file(c, f, false)
  89. configurator.run_once = true
  90. end