routing_tubes.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. local S = minetest.get_translator("pipeworks")
  2. -- the default tube and default textures
  3. pipeworks.register_tube("pipeworks:tube", S("Pneumatic tube segment"))
  4. minetest.register_craft( {
  5. output = "pipeworks:tube_1 6",
  6. recipe = {
  7. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  8. { "", "", "" },
  9. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  10. },
  11. })
  12. local nodecolor = 0xffff3030
  13. pipeworks.register_tube("pipeworks:broken_tube", {
  14. description = S("Broken Tube"),
  15. plain = { { name = "pipeworks_broken_tube_plain.png", backface_culling = false, color = nodecolor } },
  16. noctr = { { name = "pipeworks_broken_tube_plain.png", backface_culling = false, color = nodecolor } },
  17. ends = { { name = "pipeworks_broken_tube_end.png", color = nodecolor } },
  18. short = { name = "pipeworks_broken_tube_short.png", color = nodecolor },
  19. node_def = {
  20. drop = "pipeworks:tube_1",
  21. groups = {not_in_creative_inventory = 1, tubedevice_receiver = 1},
  22. tube = {
  23. insert_object = function(pos, node, stack, direction)
  24. minetest.item_drop(stack, nil, pos)
  25. return ItemStack("")
  26. end,
  27. can_insert = function(pos,node,stack,direction)
  28. return true
  29. end,
  30. priority = 50,
  31. },
  32. on_punch = function(pos, node, puncher, pointed_thing)
  33. local itemstack = puncher:get_wielded_item()
  34. local wieldname = itemstack:get_name()
  35. local playername = puncher:get_player_name()
  36. local log_msg = playername.." struck a broken tube at "..minetest.pos_to_string(pos).."\n"
  37. if wieldname == "anvil:hammer"
  38. or wieldname == "cottages:hammer"
  39. or wieldname == "glooptest:hammer_steel"
  40. or wieldname == "glooptest:hammer_bronze"
  41. or wieldname == "glooptest:hammer_diamond"
  42. or wieldname == "glooptest:hammer_mese"
  43. or wieldname == "glooptest:hammer_alatro"
  44. or wieldname == "glooptest:hammer_arol" then
  45. local meta = minetest.get_meta(pos)
  46. local was_node = minetest.deserialize(meta:get_string("the_tube_was"))
  47. if was_node and was_node ~= "" then
  48. pipeworks.logger(log_msg.." with "..wieldname.." to repair it.")
  49. minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 })
  50. pipeworks.scan_for_tube_objects(pos)
  51. itemstack:add_wear(1000)
  52. puncher:set_wielded_item(itemstack)
  53. return itemstack
  54. else
  55. pipeworks.logger(log_msg.." but it can't be repaired.")
  56. end
  57. else
  58. pipeworks.logger(log_msg.." with "..wieldname.." but that tool is too weak.")
  59. end
  60. end
  61. }
  62. })
  63. -- the high priority tube is a low-cpu replacement for sorting tubes in situations
  64. -- where players would use them for simple routing (turning off paths)
  65. -- without doing actual sorting, like at outputs of tubedevices that might both accept and eject items
  66. if pipeworks.enable_priority_tube then
  67. local color = "#ff3030:128"
  68. pipeworks.register_tube("pipeworks:priority_tube", {
  69. description = S("High Priority Tube Segment"),
  70. inventory_image = "pipeworks_tube_inv.png^[colorize:" .. color,
  71. plain = { { name = "pipeworks_tube_plain.png", color = nodecolor } },
  72. noctr = { { name = "pipeworks_tube_noctr.png", color = nodecolor } },
  73. ends = { { name = "pipeworks_tube_end.png", color = nodecolor } },
  74. short = { name = "pipeworks_tube_short.png", color = nodecolor },
  75. node_def = {
  76. tube = { priority = 150 } -- higher than tubedevices (100)
  77. },
  78. })
  79. minetest.register_craft( {
  80. output = "pipeworks:priority_tube_1 6",
  81. recipe = {
  82. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  83. { "default:gold_ingot", "", "default:gold_ingot" },
  84. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  85. },
  86. })
  87. end
  88. if pipeworks.enable_accelerator_tube then
  89. pipeworks.register_tube("pipeworks:accelerator_tube", {
  90. description = S("Accelerating Pneumatic Tube Segment"),
  91. inventory_image = "pipeworks_accelerator_tube_inv.png",
  92. plain = { "pipeworks_accelerator_tube_plain.png" },
  93. noctr = { "pipeworks_accelerator_tube_noctr.png" },
  94. ends = { "pipeworks_accelerator_tube_end.png" },
  95. short = "pipeworks_accelerator_tube_short.png",
  96. node_def = {
  97. tube = {can_go = function(pos, node, velocity, stack)
  98. velocity.speed = velocity.speed+1
  99. return pipeworks.notvel(pipeworks.meseadjlist, velocity)
  100. end}
  101. },
  102. })
  103. minetest.register_craft( {
  104. output = "pipeworks:accelerator_tube_1 2",
  105. recipe = {
  106. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  107. { "default:mese_crystal_fragment", "default:steel_ingot", "default:mese_crystal_fragment" },
  108. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  109. },
  110. })
  111. end
  112. if pipeworks.enable_crossing_tube then
  113. pipeworks.register_tube("pipeworks:crossing_tube", {
  114. description = S("Crossing Pneumatic Tube Segment"),
  115. inventory_image = "pipeworks_crossing_tube_inv.png",
  116. plain = { "pipeworks_crossing_tube_plain.png" },
  117. noctr = { "pipeworks_crossing_tube_noctr.png" },
  118. ends = { "pipeworks_crossing_tube_end.png" },
  119. short = "pipeworks_crossing_tube_short.png",
  120. node_def = {
  121. tube = {can_go = function(pos, node, velocity, stack) return {velocity} end }
  122. },
  123. })
  124. minetest.register_craft( {
  125. output = "pipeworks:crossing_tube_1 5",
  126. recipe = {
  127. { "", "pipeworks:tube_1", "" },
  128. { "pipeworks:tube_1", "pipeworks:tube_1", "pipeworks:tube_1" },
  129. { "", "pipeworks:tube_1", "" }
  130. },
  131. })
  132. end
  133. if pipeworks.enable_one_way_tube then
  134. minetest.register_node("pipeworks:one_way_tube", {
  135. description = S("One way tube"),
  136. tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png",
  137. "pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"},
  138. paramtype2 = "facedir",
  139. drawtype = "nodebox",
  140. paramtype = "light",
  141. node_box = {type = "fixed",
  142. fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}},
  143. groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1},
  144. sounds = default.node_sound_wood_defaults(),
  145. tube = {
  146. connect_sides = {left = 1, right = 1},
  147. can_go = function(pos, node, velocity, stack)
  148. return {velocity}
  149. end,
  150. can_insert = function(pos, node, stack, direction)
  151. local dir = pipeworks.facedir_to_right_dir(node.param2)
  152. return vector.equals(dir, direction)
  153. end,
  154. priority = 75 -- Higher than normal tubes, but lower than receivers
  155. },
  156. after_place_node = pipeworks.after_place,
  157. after_dig_node = pipeworks.after_dig,
  158. on_rotate = pipeworks.on_rotate,
  159. check_for_pole = pipeworks.check_for_vert_tube,
  160. check_for_horiz_pole = pipeworks.check_for_horiz_tube
  161. })
  162. minetest.register_craft({
  163. output = "pipeworks:one_way_tube 2",
  164. recipe = {
  165. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  166. { "group:stick", "default:mese_crystal", "basic_materials:plastic_sheet" },
  167. { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  168. },
  169. })
  170. end