pipeworks.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. minetest.register_node('asrs:pipeworks', {
  2. description = 'A.S.R.S pipeworks interface',
  3. tiles = {'asrs_cell.png^pipeworks_tube_connection_metallic.png'},
  4. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1},
  5. tube = {
  6. insert_object = function(pos, node, stack, direction)
  7. local meta = minetest.get_meta(pos)
  8. local sys_id = meta:get_string('system_id')
  9. pos = asrs.data[sys_id].inv_pos
  10. meta = minetest.get_meta(pos)
  11. local inv = meta:get_inventory()
  12. return inv:add_item('storage', stack)
  13. end,
  14. can_insert = function(pos, node, stack, direction)
  15. local meta = minetest.get_meta(pos)
  16. local sys_id = meta:get_string('system_id')
  17. pos = asrs.data[sys_id].inv_pos
  18. meta = minetest.get_meta(pos)
  19. local inv = meta:get_inventory()
  20. return inv:room_for_item('storage', stack)
  21. end,
  22. input_inventory = 'storage',
  23. connect_sides = {left = 1, right = 1, front = 1, back = 1, bottom = 1, top = 1}
  24. },
  25. after_place_node = function(pos, placer)
  26. local neighbor, pos1 = asrs.connected_nodes(pos, 'asrs:lift, asrs:connection_point')
  27. if neighbor then
  28. local this_meta = minetest.get_meta(pos)
  29. local that_meta = minetest.get_meta(pos1)
  30. local children = that_meta:get_int('children')
  31. local sys_id = that_meta:get_string('system_id')
  32. this_meta:set_string('system_id', sys_id)
  33. this_meta:set_int('children', 0)
  34. that_meta:set_int('children', children + 1)
  35. local sys_inv_max = asrs.data[sys_id].max_inv
  36. asrs.data[sys_id].max_inv = sys_inv_max + 10
  37. local connected_nodes = asrs.data[sys_id].nodes
  38. asrs.data[sys_id].nodes = connected_nodes + 1
  39. asrs.save()
  40. else
  41. local name = placer:get_player_name() or ''
  42. minetest.chat_send_player(name, 'You must place this adjacent to a lift or controller node.')
  43. minetest.remove_node(pos)
  44. return true
  45. end
  46. end,
  47. can_dig = function(pos, player)
  48. local meta = minetest.get_meta(pos)
  49. local sys_id = meta:get_string('system_id')
  50. local sys_inv_max = asrs.data[sys_id].max_inv
  51. asrs.sort_inventory(asrs.data[sys_id].inv_pos)
  52. local inv_count = asrs.count_inventory(asrs.data[sys_id].inv_pos)
  53. if inv_count > (sys_inv_max - 10) then
  54. minetest.chat_send_player(player:get_player_name(), 'Remove some inventory from the system first.')
  55. return false
  56. else
  57. return true
  58. end
  59. end,
  60. after_dig_node = function(pos, _, oldmetadata)
  61. local _, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  62. if pos1 then
  63. local that_meta = minetest.get_meta(pos1)
  64. local children = that_meta:get_int('children')
  65. that_meta:set_int('children', children - 1)
  66. end
  67. local sys_id = oldmetadata.fields.system_id
  68. local sys_inv_max = asrs.data[sys_id].max_inv
  69. asrs.data[sys_id].max_inv = sys_inv_max - 10
  70. local connected_nodes = asrs.data[sys_id].nodes
  71. asrs.data[sys_id].nodes = connected_nodes - 1
  72. asrs.save()
  73. end,
  74. })
  75. minetest.register_craft({
  76. output = 'asrs:pipeworks',
  77. type = 'shapeless',
  78. recipe = {'asrs:cell', 'pipeworks:tube_1'}
  79. })