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.

174 lines
6.1KB

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