storage_locker.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --This is a support node, it doesn't give out XP, but rather items.
  2. --The items can be required by other nodes and those will reward XP.
  3. local storage_locker =
  4. 'size[8,6]'..
  5. 'textarea[2.25,.5;4.25,2.1;;Instructions;Place an item request in the left, and take your item out of the slot on the right.\nPlease be patient, it takes time to find the part you want.]' ..
  6. 'list[current_name;src;.75,1;1,1;]'..
  7. 'list[current_name;dst;6.25,1;1,1;]'..
  8. 'list[current_player;main;0,4;8,2;]'..
  9. 'listring[current_player;main]'..
  10. 'listring[current_name;src]'..
  11. 'listring[current_name;dst]'..
  12. 'listring[current_player;main]'
  13. local storage_on_construct = function(pos)
  14. local meta = minetest.get_meta(pos)
  15. local inv = meta:get_inventory()
  16. inv:set_size('src', 1)
  17. inv:set_size('dst', 1)
  18. meta:set_string('infotext', 'Storage Locker')
  19. meta:set_string('formspec', storage_locker)
  20. end
  21. local storage_allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  22. if listname == 'src' then
  23. local item = string.sub(stack:get_name(), -3)
  24. if item == 'req' then
  25. return 1
  26. else
  27. return 0
  28. end
  29. else
  30. return 0
  31. end
  32. end
  33. local storage_on_metadata_inventory_put = function(pos, listname, index, stack, player)
  34. local timer = minetest.get_node_timer(pos)
  35. timer:start(5)
  36. end
  37. local storage_on_timer = function(pos)
  38. local meta = minetest.get_meta(pos)
  39. local inv = meta:get_inventory()
  40. local instack = inv:get_stack('src', 1)
  41. local inputstack = instack:get_name()
  42. local item = string.sub(inputstack, 0, -5)
  43. minetest.sound_play('tasks_storage_locker', {pos = pos, gain = 1, max_hear_distance = 10})
  44. inv:set_stack('src', 1, '')
  45. inv:set_stack('dst', 1, item)
  46. end
  47. local col_box = {
  48. type = 'fixed',
  49. fixed = {{-.45, -.5, -.45, .5, .275, .5},
  50. {-.45, .275, 0, .5, .7, .5}, --Left, Bottom, Front, Right, Top, Back
  51. {.5, -.5, -.45, 1.45, 1.5, .5}}
  52. }
  53. minetest.register_node('tasks:storage_locker_0', {
  54. description = 'Red Storage Locker',
  55. drawtype = 'mesh',
  56. mesh = 'tasks_storage_locker.obj',
  57. tiles = {'tasks_storage_locker_0.png'},
  58. use_texture_alpha = 'clip',
  59. groups = {breakable=1},
  60. light_source = 2,
  61. paramtype = 'light',
  62. paramtype2 = 'facedir',
  63. selection_box = col_box,
  64. collision_box = col_box,
  65. on_construct = storage_on_construct,
  66. allow_metadata_inventory_put = storage_allow_metadata_inventory_put,
  67. on_metadata_inventory_put = storage_on_metadata_inventory_put,
  68. on_timer = storage_on_timer
  69. })
  70. minetest.register_node('tasks:storage_trunk_0', {
  71. description = 'Old Storage Trunk',
  72. drawtype = 'mesh',
  73. mesh = 'tasks_storage_trunk.obj',
  74. tiles = {'tasks_storage_trunk.png'},
  75. groups = {breakable=1},
  76. paramtype = 'light',
  77. paramtype2 = 'facedir',
  78. selection_box = {
  79. type = 'fixed',
  80. fixed = {-.5, -.5, -.5, 1.5, .5, .5},
  81. },
  82. collision_box = {
  83. type = 'fixed',
  84. fixed = {-.5, -.5, -.5, 1.5, .5, .5},
  85. },
  86. on_construct = storage_on_construct,
  87. allow_metadata_inventory_put = storage_allow_metadata_inventory_put,
  88. on_metadata_inventory_put = storage_on_metadata_inventory_put,
  89. on_timer = storage_on_timer
  90. })