nodes.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. local remote_box = {
  10. type = 'fixed',
  11. fixed = {
  12. {-.5, -.5, -.5, .5, .5, .5}, --Desk
  13. {-.46875, .75, .4375, 0.46875, 1.5, .3125}, --TV
  14. }
  15. }
  16. core.register_node('asrs:controller', {
  17. description = 'A.S.R.S Controller',
  18. drawtype = 'mesh',
  19. mesh = 'asrs_controller.obj',
  20. tiles = {'asrs_controller.png'},
  21. paramtype = 'light',
  22. paramtype2 = 'facedir',
  23. selection_box = controller_box,
  24. collision_box = controller_box,
  25. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1, handy=1, pixkaxey=1},
  26. after_place_node = function(pos, placer)
  27. if asrs.space_to_place(pos) then
  28. local meta = core.get_meta(pos)
  29. local player_name = placer:get_player_name()
  30. local sys_id = asrs.create_id(player_name, pos)
  31. local inv = meta:get_inventory()
  32. inv:set_size('storage', 0)
  33. inv:set_size('search', 0)
  34. meta:set_string('infotext', 'Automated Storage & Retrieval System')
  35. meta:set_string('system_id', sys_id)
  36. meta:set_string('owner', player_name)
  37. meta:set_int('inv_page', 0)
  38. else
  39. core.remove_node(pos)
  40. core.chat_send_player(placer:get_player_name(), 'It looks like there is a node in the way.')
  41. return true
  42. end
  43. end,
  44. on_rightclick = function(pos, node, clicker)
  45. asrs.update_inventory(pos)
  46. local meta = core.get_meta(pos)
  47. local owner = meta:get_string('owner')
  48. local players = ' '..meta:get_string('players')..' '
  49. local name = clicker:get_player_name()
  50. if name == owner or string.find(players, ' '..name..' ') then
  51. local inv = meta:get_inventory()
  52. inv:set_size('search', 0)
  53. asrs.clicker[name] = {pos = pos, filter = '', node = 'main'}
  54. core.show_formspec(name, 'asrs:control_panel', asrs.main(pos))
  55. else
  56. core.chat_send_player(name, 'You do not have access to this system.')
  57. end
  58. end,
  59. can_dig = function(pos, player)
  60. local meta = core.get_meta(pos)
  61. local sys_id = meta:get_string('system_id')
  62. if sys_id ~= '' then
  63. local connected_nodes = asrs.data[sys_id].nodes
  64. if connected_nodes <= 1 then
  65. return true
  66. else
  67. core.chat_send_player(player:get_player_name(), 'Please remove lifts and cells first.')
  68. return false
  69. end
  70. else
  71. return true
  72. end
  73. end,
  74. after_dig_node = function(pos, oldnode, oldmetadata)
  75. local sys_id = oldmetadata.fields.system_id
  76. if sys_id then
  77. asrs.data[sys_id] = nil
  78. end
  79. asrs.remove_side_node(pos, oldnode)
  80. asrs.save()
  81. end,
  82. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  83. if listname == 'search' then
  84. if stack and stack:get_count() > 0 then
  85. core.log('action', player:get_player_name()..' took '..stack:get_name()..' from the asrs.')
  86. local meta = core.get_meta(pos)
  87. local inv = meta:get_inventory()
  88. inv:remove_item('storage', stack)
  89. end
  90. end
  91. end,
  92. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  93. if listname == 'search' then
  94. if stack and stack:get_count() > 0 then
  95. core.log('action', player:get_player_name()..' placed '..stack:get_name()..' into the asrs.')
  96. local meta = core.get_meta(pos)
  97. local inv = meta:get_inventory()
  98. inv:add_item('storage', stack)
  99. end
  100. end
  101. end,
  102. tube = {
  103. insert_object = function(pos, node, stack, direction)
  104. local meta = core.get_meta(pos)
  105. local inv = meta:get_inventory()
  106. return inv:add_item('storage', stack)
  107. end,
  108. can_insert = function(pos, node, stack, direction)
  109. local meta = core.get_meta(pos)
  110. local inv = meta:get_inventory()
  111. return inv:room_for_item('storage', stack)
  112. end,
  113. input_inventory = 'storage',
  114. connect_sides = {back = 1, bottom = 1}
  115. },
  116. })
  117. core.register_node('asrs:remote_node', {
  118. description = 'Remote Access',
  119. drawtype = 'mesh',
  120. mesh = 'asrs_remote.obj',
  121. tiles = {'asrs_remote.png'},
  122. paramtype = 'light',
  123. paramtype2 = 'facedir',
  124. selection_box = remote_box,
  125. collision_box = remote_box,
  126. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, tubedevice = 1, tubedevice_receiver = 1, handy=1, pixkaxey=1},
  127. after_place_node = function(pos, placer)
  128. local placer_name = placer:get_player_name()
  129. local neighbor, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  130. local above_pos = {x = pos.x, y = pos.y+1, z = pos.z}
  131. local above_node = core.get_node(above_pos)
  132. local above_def = core.registered_nodes[above_node.name] or nil
  133. if neighbor and above_def.buildable_to then
  134. local that_meta = core.get_meta(pos1)
  135. local sys_id = that_meta:get_string('system_id')
  136. local system_owner = asrs.data[sys_id].name
  137. if (placer_name == system_owner) then
  138. local this_meta = core.get_meta(pos)
  139. local children = that_meta:get_int('children')
  140. this_meta:set_string('owner', placer_name)
  141. this_meta:set_string('system_id', sys_id)
  142. that_meta:set_int('children', children + 1)
  143. local connected_nodes = asrs.data[sys_id].nodes
  144. asrs.data[sys_id].nodes = connected_nodes + 1
  145. asrs.save()
  146. else
  147. core.chat_send_player(placer_name, 'You can only place this next to your own system.')
  148. end
  149. else
  150. local name = placer:get_player_name()
  151. core.chat_send_player(name, 'You must place this adjacent to a lift node, with air space above.')
  152. core.remove_node(pos)
  153. return true
  154. end
  155. end,
  156. on_rightclick = function(pos, node, clicker)
  157. local meta = core.get_meta(pos)
  158. local owner = meta:get_string('owner')
  159. local players = ' '..meta:get_string('players')..' '
  160. local sys_id = meta:get_string('system_id')
  161. pos = asrs.data[sys_id].inv_pos
  162. local infotext = asrs.data[sys_id].infotext
  163. meta:set_string('infotext', infotext)
  164. local name = clicker:get_player_name()
  165. if name == owner or string.find(players, ' '..name..' ') then
  166. asrs.update_inventory(pos)
  167. local inv = meta:get_inventory()
  168. inv:set_size('search', 0)
  169. asrs.clicker[name] = {pos = pos, filter = '', node = 'remote'}
  170. core.show_formspec(name, 'asrs:control_panel', asrs.main(pos, 'remote'))
  171. else
  172. core.chat_send_player(name, 'You do not have access to this system.')
  173. end
  174. end,
  175. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  176. if listname == 'search' then
  177. if stack and stack:get_count() > 0 then
  178. core.log('action', player:get_player_name()..' took '..stack:get_name()..' from the asrs.')
  179. local meta = core.get_meta(pos)
  180. local sys_id = meta:get_string('system_id')
  181. pos = asrs.data[sys_id].inv_pos
  182. local meta = core.get_meta(pos)
  183. local inv = meta:get_inventory()
  184. inv:remove_item('storage', stack)
  185. end
  186. end
  187. end,
  188. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  189. if listname == 'search' then
  190. if stack and stack:get_count() > 0 then
  191. core.log('action', player:get_player_name()..' placed '..stack:get_name()..' into the asrs.')
  192. local meta = core.get_meta(pos)
  193. local sys_id = meta:get_string('system_id')
  194. pos = asrs.data[sys_id].inv_pos
  195. local meta = core.get_meta(pos)
  196. local inv = meta:get_inventory()
  197. inv:add_item('storage', stack)
  198. end
  199. end
  200. end,
  201. tube = {
  202. insert_object = function(pos, node, stack, direction)
  203. local meta = core.get_meta(pos)
  204. local inv = meta:get_inventory()
  205. return inv:add_item('storage', stack)
  206. end,
  207. can_insert = function(pos, node, stack, direction)
  208. local meta = core.get_meta(pos)
  209. local inv = meta:get_inventory()
  210. return inv:room_for_item('storage', stack)
  211. end,
  212. input_inventory = 'storage',
  213. connect_sides = {back = 1, bottom = 1}
  214. },
  215. })
  216. core.register_node('asrs:blank', {
  217. description = 'Invisible Border',
  218. drawtype = 'airlike',
  219. paramtype = 'light',
  220. pointable = false,
  221. walkable = false,
  222. tiles = {'air.png'},
  223. groups = {not_in_creative_inventory=1},
  224. })
  225. core.register_node('asrs:connection_point', {
  226. description = 'Invisible Border',
  227. drawtype = 'airlike',
  228. paramtype = 'light',
  229. pointable = false,
  230. walkable = false,
  231. tiles = {'air.png'},
  232. groups = {not_in_creative_inventory=1},
  233. on_construct = function(pos)
  234. local pos1 = {x = pos.x, y = pos.y-1, z = pos.z}
  235. local this_meta = core.get_meta(pos)
  236. local that_meta = core.get_meta(pos1)
  237. local sys_id = that_meta:get_string('system_id')
  238. local children = that_meta:get_int('children')
  239. this_meta:set_string('system_id', sys_id)
  240. that_meta:set_int('children', children + 1)
  241. local connected_nodes = asrs.data[sys_id].nodes
  242. asrs.data[sys_id].nodes = connected_nodes + 1
  243. end
  244. })
  245. core.register_node('asrs:cell', {
  246. description = 'A.S.R.S Storage Cell',
  247. tiles = {'asrs_cell.png'},
  248. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, handy=1, pixkaxey=1},
  249. after_place_node = function(pos, placer)
  250. local neighbor, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  251. if neighbor then
  252. local this_meta = core.get_meta(pos)
  253. local that_meta = core.get_meta(pos1)
  254. local sys_id = that_meta:get_string('system_id')
  255. local children = that_meta:get_int('children')
  256. this_meta:set_string('system_id', sys_id)
  257. that_meta:set_int('children', children + 1)
  258. local sys_inv_max = asrs.data[sys_id].max_inv
  259. asrs.data[sys_id].max_inv = sys_inv_max + 20
  260. local connected_nodes = asrs.data[sys_id].nodes
  261. asrs.data[sys_id].nodes = connected_nodes + 1
  262. asrs.save()
  263. else
  264. local name = placer:get_player_name()
  265. core.chat_send_player(name, 'You must place this adjacent to a lift node.')
  266. core.remove_node(pos)
  267. return true
  268. end
  269. end,
  270. can_dig = function(pos, player)
  271. local meta = core.get_meta(pos)
  272. local sys_id = meta:get_string('system_id')
  273. local sys_inv_max = asrs.data[sys_id].max_inv
  274. asrs.sort_inventory(asrs.data[sys_id].inv_pos)
  275. local inv_count = asrs.count_inventory(asrs.data[sys_id].inv_pos)
  276. if inv_count > (sys_inv_max - 20) then
  277. core.chat_send_player(player:get_player_name(), 'Remove some inventory from the system first.')
  278. return false
  279. else
  280. return true
  281. end
  282. end,
  283. after_dig_node = function(pos, _, oldmetadata)
  284. local _, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  285. if pos1 then
  286. local that_meta = core.get_meta(pos1)
  287. local children = that_meta:get_int('children')
  288. that_meta:set_int('children', children - 1)
  289. end
  290. local sys_id = oldmetadata.fields.system_id
  291. local sys_inv_max = asrs.data[sys_id].max_inv
  292. asrs.data[sys_id].max_inv = sys_inv_max - 20
  293. local connected_nodes = asrs.data[sys_id].nodes
  294. asrs.data[sys_id].nodes = connected_nodes - 1
  295. asrs.save()
  296. end,
  297. })
  298. core.register_node('asrs:lift', {
  299. description = 'A.S.R.S Lift',
  300. tiles = {'asrs_lift_top.png', 'asrs_lift_top.png', 'asrs_lift_side.png'},
  301. groups = {cracky=2, choppy=2, oddly_breakable_by_hand=2, handy=1, pixkaxey=1},
  302. after_place_node = function(pos, placer)
  303. local neighbor, pos1 = asrs.connected_nodes(pos, 'asrs:lift, asrs:connection_point')
  304. if neighbor then
  305. local this_meta = core.get_meta(pos)
  306. local that_meta = core.get_meta(pos1)
  307. local children = that_meta:get_int('children')
  308. local sys_id = that_meta:get_string('system_id')
  309. this_meta:set_string('system_id', sys_id)
  310. this_meta:set_int('children', 0)
  311. that_meta:set_int('children', children + 1)
  312. local connected_nodes = asrs.data[sys_id].nodes
  313. asrs.data[sys_id].nodes = connected_nodes + 1
  314. asrs.save()
  315. else
  316. local name = placer:get_player_name() or ''
  317. core.chat_send_player(name, 'You must place this adjacent to a lift or controller node.')
  318. core.remove_node(pos)
  319. return true
  320. end
  321. end,
  322. can_dig = function(pos, player)
  323. --local undiggable, pos1 = asrs.connected_nodes(pos, 'asrs:cell')
  324. local meta = core.get_meta(pos)
  325. local children = meta:get_int('children')
  326. --if undiggable then
  327. if children > 0 then
  328. core.chat_send_player(player:get_player_name(), 'Remove connected nodes first.')
  329. return false
  330. else
  331. return true
  332. end
  333. end,
  334. after_dig_node = function(pos, _, oldmetadata)
  335. local _, pos1 = asrs.connected_nodes(pos, 'asrs:lift')
  336. if pos1 then
  337. that_meta = core.get_meta(pos1)
  338. local children = that_meta:get_int('children')
  339. that_meta:set_int('children', children - 1)
  340. end
  341. local sys_id = oldmetadata.fields.system_id
  342. local connected_nodes = asrs.data[sys_id].nodes
  343. asrs.data[sys_id].nodes = connected_nodes - 1
  344. asrs.save()
  345. end,
  346. })