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.

120 lines
4.0KB

  1. local S = minetest.get_translator("pipeworks")
  2. if pipeworks.enable_sand_tube then
  3. pipeworks.register_tube("pipeworks:sand_tube", {
  4. description = S("Vacuuming Pneumatic Tube Segment"),
  5. inventory_image = "pipeworks_sand_tube_inv.png",
  6. short = "pipeworks_sand_tube_short.png",
  7. noctr = {"pipeworks_sand_tube_noctr.png"},
  8. plain = {"pipeworks_sand_tube_plain.png"},
  9. ends = {"pipeworks_sand_tube_end.png"},
  10. node_def = {groups = {vacuum_tube = 1}},
  11. })
  12. minetest.register_craft( {
  13. output = "pipeworks:sand_tube_1 2",
  14. recipe = {
  15. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"},
  16. {"group:sand", "group:sand", "group:sand"},
  17. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"}
  18. },
  19. })
  20. minetest.register_craft( {
  21. output = "pipeworks:sand_tube_1",
  22. recipe = {
  23. {"group:sand", "pipeworks:tube_1", "group:sand"},
  24. },
  25. })
  26. end
  27. if pipeworks.enable_mese_sand_tube then
  28. pipeworks.register_tube("pipeworks:mese_sand_tube", {
  29. description = S("Adjustable Vacuuming Pneumatic Tube Segment"),
  30. inventory_image = "pipeworks_mese_sand_tube_inv.png",
  31. short = "pipeworks_mese_sand_tube_short.png",
  32. noctr = {"pipeworks_mese_sand_tube_noctr.png"},
  33. plain = {"pipeworks_mese_sand_tube_plain.png"},
  34. ends = {"pipeworks_mese_sand_tube_end.png"},
  35. node_def = {
  36. groups = {vacuum_tube = 1},
  37. on_construct = function(pos)
  38. local meta = minetest.get_meta(pos)
  39. meta:set_int("dist", 0)
  40. meta:set_string("formspec", "size[2.1,0.8]"..
  41. "image[0,0;1,1;pipeworks_mese_sand_tube_inv.png]"..
  42. "field[1.3,0.4;1,1;dist;radius;${dist}]"..
  43. default.gui_bg..
  44. default.gui_bg_img)
  45. meta:set_string("infotext", S("Adjustable Vacuuming Pneumatic Tube Segment"))
  46. end,
  47. on_receive_fields = function(pos,formname,fields,sender)
  48. if not pipeworks.may_configure(pos, sender) then return end
  49. local meta = minetest.get_meta(pos)
  50. local dist = tonumber(fields.dist)
  51. if dist then
  52. dist = math.max(0, dist)
  53. dist = math.min(8, dist)
  54. meta:set_int("dist", dist)
  55. meta:set_string("infotext", (S("Adjustable Vacuuming Pneumatic Tube Segment (@1m)", dist)))
  56. end
  57. end,
  58. },
  59. })
  60. minetest.register_craft( {
  61. output = "pipeworks:mese_sand_tube_1 2",
  62. recipe = {
  63. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" },
  64. {"group:sand", "default:mese_crystal", "group:sand" },
  65. {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }
  66. },
  67. })
  68. minetest.register_craft( {
  69. type = "shapeless",
  70. output = "pipeworks:mese_sand_tube_1",
  71. recipe = {
  72. "pipeworks:sand_tube_1",
  73. "default:mese_crystal_fragment",
  74. "default:mese_crystal_fragment",
  75. "default:mese_crystal_fragment",
  76. "default:mese_crystal_fragment"
  77. },
  78. })
  79. end
  80. local function vacuum(pos, radius)
  81. radius = radius + 0.5
  82. for _, object in pairs(minetest.get_objects_inside_radius(pos, math.sqrt(3) * radius)) do
  83. local lua_entity = object:get_luaentity()
  84. if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then
  85. local obj_pos = object:get_pos()
  86. local minpos = vector.subtract(pos, radius)
  87. local maxpos = vector.add(pos, radius)
  88. if obj_pos.x >= minpos.x and obj_pos.x <= maxpos.x
  89. and obj_pos.y >= minpos.y and obj_pos.y <= maxpos.y
  90. and obj_pos.z >= minpos.z and obj_pos.z <= maxpos.z then
  91. if lua_entity.itemstring ~= "" then
  92. pipeworks.tube_inject_item(pos, pos, vector.new(0, 0, 0), lua_entity.itemstring)
  93. lua_entity.itemstring = ""
  94. end
  95. object:remove()
  96. end
  97. end
  98. end
  99. end
  100. minetest.register_abm({nodenames = {"group:vacuum_tube"},
  101. interval = 1,
  102. chance = 1,
  103. label = "Vacuum tubes",
  104. action = function(pos, node, active_object_count, active_object_count_wider)
  105. if node.name:find("pipeworks:sand_tube") then
  106. vacuum(pos, 2)
  107. else
  108. local radius = minetest.get_meta(pos):get_int("dist")
  109. vacuum(pos, radius)
  110. end
  111. end
  112. })