techage.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. techage.register_node({'asrs:controller'}, {
  2. on_inv_request = function(pos, in_dir, access_type)
  3. local meta = minetest.get_meta(pos)
  4. return meta:get_inventory(), 'storage'
  5. end,
  6. on_pull_item = function(pos, in_dir, num)
  7. local meta = minetest.get_meta(pos)
  8. local inv = meta:get_inventory()
  9. return techage.get_items(pos, inv, 'storage', num)
  10. end,
  11. on_push_item = function(pos, in_dir, stack)
  12. local meta = minetest.get_meta(pos)
  13. local inv = meta:get_inventory()
  14. return techage.put_items(inv, 'storage', stack)
  15. end,
  16. on_unpull_item = function(pos, in_dir, stack)
  17. local meta = minetest.get_meta(pos)
  18. local inv = meta:get_inventory()
  19. return techage.put_items(inv, 'storage', stack)
  20. end,
  21. valid_sides = {'B', 'R', 'F', 'L', 'D', 'U'}
  22. })
  23. minetest.register_node('asrs:techage', {
  24. description = 'A.S.R.S techage interface',
  25. tiles = {'asrs_cell.png^techage_tube_hole.png'},
  26. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2},
  27. after_place_node = function(pos, placer)
  28. local neighbor, pos1 = asrs.connected_nodes(pos, 'asrs:lift, asrs:connection_point')
  29. if neighbor then
  30. local this_meta = minetest.get_meta(pos)
  31. local that_meta = minetest.get_meta(pos1)
  32. local children = that_meta:get_int('children')
  33. local sys_id = that_meta:get_string('system_id')
  34. this_meta:set_string('system_id', sys_id)
  35. this_meta:set_int('children', 0)
  36. that_meta:set_int('children', children + 1)
  37. local sys_inv_max = asrs.data[sys_id].max_inv
  38. asrs.data[sys_id].max_inv = sys_inv_max + 10
  39. local connected_nodes = asrs.data[sys_id].nodes
  40. asrs.data[sys_id].nodes = connected_nodes + 1
  41. asrs.save()
  42. else
  43. local name = placer:get_player_name() or ''
  44. minetest.chat_send_player(name, 'You must place this adjacent to a lift or controller node.')
  45. minetest.remove_node(pos)
  46. return true
  47. end
  48. end,
  49. can_dig = function(pos, player)
  50. local meta = minetest.get_meta(pos)
  51. local sys_id = meta:get_string('system_id')
  52. local sys_inv_max = asrs.data[sys_id].max_inv
  53. asrs.sort_inventory(asrs.data[sys_id].inv_pos)
  54. local inv_count = asrs.count_inventory(asrs.data[sys_id].inv_pos)
  55. if inv_count > (sys_inv_max - 10) then
  56. minetest.chat_send_player(player:get_player_name(), 'Remove some inventory from the system first.')
  57. return false
  58. else
  59. return true
  60. end
  61. end,
  62. after_dig_node = function(pos, _, oldmetadata)
  63. local _, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  64. if pos1 then
  65. local that_meta = minetest.get_meta(pos1)
  66. local children = that_meta:get_int('children')
  67. that_meta:set_int('children', children - 1)
  68. end
  69. local sys_id = oldmetadata.fields.system_id
  70. local sys_inv_max = asrs.data[sys_id].max_inv
  71. asrs.data[sys_id].max_inv = sys_inv_max - 10
  72. local connected_nodes = asrs.data[sys_id].nodes
  73. asrs.data[sys_id].nodes = connected_nodes - 1
  74. asrs.save()
  75. end,
  76. })
  77. minetest.register_craft({
  78. output = 'asrs:techage',
  79. type = 'shapeless',
  80. recipe = {'asrs:cell', 'techage:tubeS'}
  81. })
  82. techage.register_node({'asrs:techage'}, {
  83. on_inv_request = function(pos, in_dir, access_type)
  84. local meta = minetest.get_meta(pos)
  85. local sys_id = meta:get_string('system_id')
  86. pos = asrs.data[sys_id].inv_pos
  87. meta = minetest.get_meta(pos)
  88. return meta:get_inventory(), 'storage'
  89. end,
  90. on_pull_item = function(pos, in_dir, num)
  91. local meta = minetest.get_meta(pos)
  92. local sys_id = meta:get_string('system_id')
  93. pos = asrs.data[sys_id].inv_pos
  94. meta = minetest.get_meta(pos)
  95. local inv = meta:get_inventory()
  96. return techage.get_items(pos, inv, 'storage', num)
  97. end,
  98. on_push_item = function(pos, in_dir, stack)
  99. local meta = minetest.get_meta(pos)
  100. local sys_id = meta:get_string('system_id')
  101. pos = asrs.data[sys_id].inv_pos
  102. meta = minetest.get_meta(pos)
  103. local inv = meta:get_inventory()
  104. return techage.put_items(inv, 'storage', stack)
  105. end,
  106. on_unpull_item = function(pos, in_dir, stack)
  107. local meta = minetest.get_meta(pos)
  108. local sys_id = meta:get_string('system_id')
  109. pos = asrs.data[sys_id].inv_pos
  110. meta = minetest.get_meta(pos)
  111. local inv = meta:get_inventory()
  112. return techage.put_items(inv, 'storage', stack)
  113. end,
  114. })