Pipeworks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
6.1KB

  1. local S = minetest.get_translator("pipeworks")
  2. local fs_helpers = pipeworks.fs_helpers
  3. if pipeworks.enable_mese_tube then
  4. local function update_formspec(pos)
  5. local meta = minetest.get_meta(pos)
  6. local old_formspec = meta:get_string("formspec")
  7. if string.find(old_formspec, "button1") then -- Old version
  8. local inv = meta:get_inventory()
  9. for i = 1, 6 do
  10. for _, stack in ipairs(inv:get_list("line"..i)) do
  11. minetest.add_item(pos, stack)
  12. end
  13. end
  14. end
  15. local buttons_formspec = ""
  16. for i = 0, 5 do
  17. buttons_formspec = buttons_formspec .. fs_helpers.cycling_button(meta,
  18. "image_button[7,"..(i+0.2)..";1,0.6", "l"..(i+1).."s",
  19. {
  20. pipeworks.button_off,
  21. pipeworks.button_on
  22. }
  23. )
  24. end
  25. meta:set_string("formspec",
  26. "size[8,11]"..
  27. "list[context;line1;1,0;6,1;]"..
  28. "list[context;line2;1,1;6,1;]"..
  29. "list[context;line3;1,2;6,1;]"..
  30. "list[context;line4;1,3;6,1;]"..
  31. "list[context;line5;1,4;6,1;]"..
  32. "list[context;line6;1,5;6,1;]"..
  33. "image[0,0;1,1;pipeworks_white.png]"..
  34. "image[0,1;1,1;pipeworks_black.png]"..
  35. "image[0,2;1,1;pipeworks_green.png]"..
  36. "image[0,3;1,1;pipeworks_yellow.png]"..
  37. "image[0,4;1,1;pipeworks_blue.png]"..
  38. "image[0,5;1,1;pipeworks_red.png]"..
  39. buttons_formspec..
  40. "list[current_player;main;0,7;8,4;]" ..
  41. "listring[current_player;main]" ..
  42. "listring[current_player;main]" ..
  43. "listring[context;line1]" ..
  44. "listring[current_player;main]" ..
  45. "listring[context;line2]" ..
  46. "listring[current_player;main]" ..
  47. "listring[context;line3]" ..
  48. "listring[current_player;main]" ..
  49. "listring[context;line4]" ..
  50. "listring[current_player;main]" ..
  51. "listring[context;line5]" ..
  52. "listring[current_player;main]" ..
  53. "listring[context;line6]"
  54. )
  55. end
  56. pipeworks.register_tube("pipeworks:mese_tube", {
  57. description = S("Sorting Pneumatic Tube Segment"),
  58. inventory_image = "pipeworks_mese_tube_inv.png",
  59. noctr = {"pipeworks_mese_tube_noctr_1.png", "pipeworks_mese_tube_noctr_2.png", "pipeworks_mese_tube_noctr_3.png",
  60. "pipeworks_mese_tube_noctr_4.png", "pipeworks_mese_tube_noctr_5.png", "pipeworks_mese_tube_noctr_6.png"},
  61. plain = {"pipeworks_mese_tube_plain_1.png", "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_3.png",
  62. "pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_5.png", "pipeworks_mese_tube_plain_6.png"},
  63. ends = { "pipeworks_mese_tube_end.png" },
  64. short = "pipeworks_mese_tube_short.png",
  65. no_facedir = true, -- Must use old tubes, since the textures are rotated with 6d ones
  66. node_def = {
  67. tube = {can_go = function(pos, node, velocity, stack)
  68. local tbl, tbln = {}, 0
  69. local found, foundn = {}, 0
  70. local meta = minetest.get_meta(pos)
  71. local inv = meta:get_inventory()
  72. local name = stack:get_name()
  73. for i, vect in ipairs(pipeworks.meseadjlist) do
  74. local npos = vector.add(pos, vect)
  75. local node = minetest.get_node(npos)
  76. local reg_node = minetest.registered_nodes[node.name]
  77. if meta:get_int("l"..i.."s") == 1 and reg_node then
  78. local tube_def = reg_node.tube
  79. if not tube_def or not tube_def.can_insert or
  80. tube_def.can_insert(npos, node, stack, vect) then
  81. local invname = "line"..i
  82. local is_empty = true
  83. for _, st in ipairs(inv:get_list(invname)) do
  84. if not st:is_empty() then
  85. is_empty = false
  86. if st:get_name() == name then
  87. foundn = foundn + 1
  88. found[foundn] = vect
  89. end
  90. end
  91. end
  92. if is_empty then
  93. tbln = tbln + 1
  94. tbl[tbln] = vect
  95. end
  96. end
  97. end
  98. end
  99. return (foundn > 0) and found or tbl
  100. end},
  101. on_construct = function(pos)
  102. local meta = minetest.get_meta(pos)
  103. local inv = meta:get_inventory()
  104. for i = 1, 6 do
  105. meta:set_int("l"..tostring(i).."s", 1)
  106. inv:set_size("line"..tostring(i), 6*1)
  107. end
  108. update_formspec(pos)
  109. meta:set_string("infotext", S("Sorting pneumatic tube"))
  110. end,
  111. on_punch = update_formspec,
  112. on_receive_fields = function(pos, formname, fields, sender)
  113. if not pipeworks.may_configure(pos, sender) then return end
  114. fs_helpers.on_receive_fields(pos, fields)
  115. update_formspec(pos)
  116. end,
  117. can_dig = function(pos, player)
  118. update_formspec(pos) -- so non-virtual items would be dropped for old tubes
  119. return true
  120. end,
  121. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  122. if not pipeworks.may_configure(pos, player) then return 0 end
  123. update_formspec(pos) -- For old tubes
  124. local inv = minetest.get_meta(pos):get_inventory()
  125. local stack_copy = ItemStack(stack)
  126. stack_copy:set_count(1)
  127. inv:set_stack(listname, index, stack_copy)
  128. return 0
  129. end,
  130. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  131. if not pipeworks.may_configure(pos, player) then return 0 end
  132. update_formspec(pos) -- For old tubes
  133. local inv = minetest.get_meta(pos):get_inventory()
  134. inv:set_stack(listname, index, ItemStack(""))
  135. return 0
  136. end,
  137. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  138. if not pipeworks.may_configure(pos, player) then return 0 end
  139. update_formspec(pos) -- For old tubes
  140. local inv = minetest.get_meta(pos):get_inventory()
  141. if from_list:match("line%d") and to_list:match("line%d") then
  142. return count
  143. else
  144. inv:set_stack(from_list, from_index, ItemStack(""))
  145. return 0
  146. end
  147. end,
  148. },
  149. })
  150. minetest.register_craft( {
  151. output = "pipeworks:mese_tube_000000 2",
  152. recipe = {
  153. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  154. { "", "default:mese_crystal", "" },
  155. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  156. },
  157. })
  158. minetest.register_craft( {
  159. type = "shapeless",
  160. output = "pipeworks:mese_tube_000000",
  161. recipe = {
  162. "pipeworks:tube_1",
  163. "default:mese_crystal_fragment",
  164. "default:mese_crystal_fragment",
  165. "default:mese_crystal_fragment",
  166. "default:mese_crystal_fragment"
  167. },
  168. })
  169. end