nodes.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. local controller_box = {
  2. type = 'fixed',
  3. fixed = {
  4. {-.5, -.5, -.4375, 1.4375, .5, .5}, --Desk
  5. {.375, .75, .375, 1.3125, 1.5, .5}, --TV
  6. {-.5, .5, -.5, -.125, 1.5, .5} -- Extractor
  7. }
  8. }
  9. minetest.register_node('asrs:controller', {
  10. description = 'A.S.R.S Controller',
  11. drawtype = 'mesh',
  12. mesh = 'asrs_controller.obj',
  13. tiles = {'asrs_controller.png'},
  14. paramtype = 'light',
  15. paramtype2 = 'facedir',
  16. selection_box = controller_box,
  17. collision_box = controller_box,
  18. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1, handy=1, pixkaxey=1},
  19. after_place_node = function(pos, placer)
  20. if asrs.space_to_place(pos) then
  21. local meta = minetest.get_meta(pos)
  22. local player_name = placer:get_player_name()
  23. local sys_id = asrs.create_id(player_name, pos)
  24. local inv = meta:get_inventory()
  25. inv:set_size('storage', 0)
  26. inv:set_size('search', 0)
  27. meta:set_string('infotext', 'Automated Storage & Retrieval System')
  28. meta:set_string('system_id', sys_id)
  29. meta:set_string('owner', player_name)
  30. meta:set_int('inv_page', 0)
  31. else
  32. minetest.remove_node(pos)
  33. minetest.chat_send_player(placer:get_player_name(), 'It looks like there is a node in the way.')
  34. return true
  35. end
  36. end,
  37. on_rightclick = function(pos, node, clicker)
  38. asrs.update_inventory(pos)
  39. local meta = minetest.get_meta(pos)
  40. local owner = meta:get_string('owner')
  41. local players = ' '..meta:get_string('players')..' '
  42. local name = clicker:get_player_name()
  43. if name == owner or string.find(players, ' '..name..' ') then
  44. local inv = meta:get_inventory()
  45. inv:set_size('search', 0)
  46. asrs.clicker[name] = {pos = pos, filter = ''}
  47. minetest.show_formspec(name, 'asrs:control_panel', asrs.main(pos))
  48. else
  49. minetest.chat_send_player(name, 'You do not have access to this system.')
  50. end
  51. end,
  52. can_dig = function(pos, player)
  53. local meta = minetest.get_meta(pos)
  54. local sys_id = meta:get_string('system_id')
  55. if sys_id ~= '' then
  56. local connected_nodes = asrs.data[sys_id].nodes
  57. if connected_nodes <= 1 then
  58. return true
  59. else
  60. minetest.chat_send_player(player:get_player_name(), 'Please remove lifts and cells first.')
  61. return false
  62. end
  63. else
  64. return true
  65. end
  66. end,
  67. after_dig_node = function(pos, oldnode, oldmetadata)
  68. local sys_id = oldmetadata.fields.system_id
  69. if sys_id then
  70. asrs.data[sys_id] = nil
  71. end
  72. asrs.remove_side_node(pos, oldnode)
  73. asrs.save()
  74. end,
  75. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  76. if listname == 'search' then
  77. if stack and stack:get_count() > 0 then
  78. minetest.log('action', player:get_player_name()..' took '..stack:get_name()..' from the asrs.')
  79. local meta = minetest.get_meta(pos)
  80. local inv = meta:get_inventory()
  81. inv:remove_item('storage', stack)
  82. end
  83. end
  84. end,
  85. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  86. if listname == 'search' then
  87. if stack and stack:get_count() > 0 then
  88. minetest.log('action', player:get_player_name()..' placed '..stack:get_name()..' into the asrs.')
  89. local meta = minetest.get_meta(pos)
  90. local inv = meta:get_inventory()
  91. inv:add_item('storage', stack)
  92. end
  93. end
  94. end,
  95. tube = {
  96. insert_object = function(pos, node, stack, direction)
  97. local meta = minetest.get_meta(pos)
  98. local inv = meta:get_inventory()
  99. return inv:add_item('storage', stack)
  100. end,
  101. can_insert = function(pos, node, stack, direction)
  102. local meta = minetest.get_meta(pos)
  103. local inv = meta:get_inventory()
  104. return inv:room_for_item('storage', stack)
  105. end,
  106. input_inventory = 'storage',
  107. connect_sides = {back = 1, bottom = 1}
  108. },
  109. })
  110. minetest.register_node('asrs:blank', {
  111. description = 'Invisible Border',
  112. drawtype = 'airlike',
  113. paramtype = 'light',
  114. pointable = false,
  115. walkable = false,
  116. tiles = {'air.png'},
  117. groups = {not_in_creative_inventory=1},
  118. })
  119. minetest.register_node('asrs:connection_point', {
  120. description = 'Invisible Border',
  121. drawtype = 'airlike',
  122. paramtype = 'light',
  123. pointable = false,
  124. walkable = false,
  125. tiles = {'air.png'},
  126. groups = {not_in_creative_inventory=1},
  127. on_construct = function(pos)
  128. local pos1 = {x = pos.x, y = pos.y-1, z = pos.z}
  129. local this_meta = minetest.get_meta(pos)
  130. local that_meta = minetest.get_meta(pos1)
  131. local sys_id = that_meta:get_string('system_id')
  132. local children = that_meta:get_int('children')
  133. this_meta:set_string('system_id', sys_id)
  134. that_meta:set_int('children', children + 1)
  135. local connected_nodes = asrs.data[sys_id].nodes
  136. asrs.data[sys_id].nodes = connected_nodes + 1
  137. end
  138. })
  139. minetest.register_node('asrs:cell', {
  140. description = 'A.S.R.S Storage Cell',
  141. tiles = {'asrs_cell.png'},
  142. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, handy=1, pixkaxey=1},
  143. after_place_node = function(pos, placer)
  144. local neighbor, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  145. if neighbor then
  146. local this_meta = minetest.get_meta(pos)
  147. local that_meta = minetest.get_meta(pos1)
  148. local sys_id = that_meta:get_string('system_id')
  149. local children = that_meta:get_int('children')
  150. this_meta:set_string('system_id', sys_id)
  151. that_meta:set_int('children', children + 1)
  152. local sys_inv_max = asrs.data[sys_id].max_inv
  153. asrs.data[sys_id].max_inv = sys_inv_max + 20
  154. local connected_nodes = asrs.data[sys_id].nodes
  155. asrs.data[sys_id].nodes = connected_nodes + 1
  156. asrs.save()
  157. else
  158. local name = placer:get_player_name()
  159. minetest.chat_send_player(name, 'You must place this adjacent to a lift node.')
  160. minetest.remove_node(pos)
  161. return true
  162. end
  163. end,
  164. can_dig = function(pos, player)
  165. local meta = minetest.get_meta(pos)
  166. local sys_id = meta:get_string('system_id')
  167. local sys_inv_max = asrs.data[sys_id].max_inv
  168. asrs.sort_inventory(asrs.data[sys_id].inv_pos)
  169. local inv_count = asrs.count_inventory(asrs.data[sys_id].inv_pos)
  170. if inv_count > (sys_inv_max - 20) then
  171. minetest.chat_send_player(player:get_player_name(), 'Remove some inventory from the system first.')
  172. return false
  173. else
  174. return true
  175. end
  176. end,
  177. after_dig_node = function(pos, _, oldmetadata)
  178. local _, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  179. if pos1 then
  180. local that_meta = minetest.get_meta(pos1)
  181. local children = that_meta:get_int('children')
  182. that_meta:set_int('children', children - 1)
  183. end
  184. local sys_id = oldmetadata.fields.system_id
  185. local sys_inv_max = asrs.data[sys_id].max_inv
  186. asrs.data[sys_id].max_inv = sys_inv_max - 20
  187. local connected_nodes = asrs.data[sys_id].nodes
  188. asrs.data[sys_id].nodes = connected_nodes - 1
  189. asrs.save()
  190. end,
  191. })
  192. minetest.register_node('asrs:lift', {
  193. description = 'A.S.R.S Lift',
  194. tiles = {'asrs_lift_top.png', 'asrs_lift_top.png', 'asrs_lift_side.png'},
  195. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, handy=1, pixkaxey=1},
  196. after_place_node = function(pos, placer)
  197. local neighbor, pos1 = asrs.connected_nodes(pos, 'asrs:lift, asrs:connection_point')
  198. if neighbor then
  199. local this_meta = minetest.get_meta(pos)
  200. local that_meta = minetest.get_meta(pos1)
  201. local children = that_meta:get_int('children')
  202. local sys_id = that_meta:get_string('system_id')
  203. this_meta:set_string('system_id', sys_id)
  204. this_meta:set_int('children', 0)
  205. that_meta:set_int('children', children + 1)
  206. local connected_nodes = asrs.data[sys_id].nodes
  207. asrs.data[sys_id].nodes = connected_nodes + 1
  208. asrs.save()
  209. else
  210. local name = placer:get_player_name() or ''
  211. minetest.chat_send_player(name, 'You must place this adjacent to a lift or controller node.')
  212. minetest.remove_node(pos)
  213. return true
  214. end
  215. end,
  216. can_dig = function(pos, player)
  217. --local undiggable, pos1 = asrs.connected_nodes(pos, 'asrs:cell')
  218. local meta = minetest.get_meta(pos)
  219. local children = meta:get_int('children')
  220. --if undiggable then
  221. if children > 0 then
  222. minetest.chat_send_player(player:get_player_name(), 'Remove connected nodes first.')
  223. return false
  224. else
  225. return true
  226. end
  227. end,
  228. after_dig_node = function(pos, _, oldmetadata)
  229. local _, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  230. if pos1 then
  231. that_meta = minetest.get_meta(pos1)
  232. local children = that_meta:get_int('children')
  233. that_meta:set_int('children', children - 1)
  234. end
  235. local sys_id = oldmetadata.fields.system_id
  236. local connected_nodes = asrs.data[sys_id].nodes
  237. asrs.data[sys_id].nodes = connected_nodes - 1
  238. asrs.save()
  239. end,
  240. })