storage_locker.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 col_box = {
  4. type = 'fixed',
  5. fixed = {{-.45, -.5, -.45, .5, .275, .5},
  6. {-.45, .275, 0, .5, .7, .5}, --Left, Bottom, Front, Right, Top, Back
  7. {.5, -.5, -.45, 1.45, 1.5, .5}}
  8. }
  9. local storage_locker =
  10. 'size[8,6]'..
  11. '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.]' ..
  12. 'list[current_name;src;.75,1;1,1;]'..
  13. 'list[current_name;dst;6.25,1;1,1;]'..
  14. 'list[current_player;main;0,3;8,3;]'
  15. minetest.register_node('tasks:storage_locker_0', {
  16. description = 'Red Storage Locker',
  17. drawtype = 'mesh',
  18. mesh = 'tasks_storage_locker.obj',
  19. tiles = {'tasks_storage_locker_0.png'},
  20. groups = {breakable=1},
  21. light_source = 2,
  22. paramtype = 'light',
  23. paramtype2 = 'facedir',
  24. selection_box = col_box,
  25. collision_box = col_box,
  26. on_construct = function(pos)
  27. local meta = minetest.get_meta(pos)
  28. local inv = meta:get_inventory()
  29. inv:set_size('src', 1)
  30. inv:set_size('dst', 1)
  31. meta:set_string('infotext', 'Storage Locker')
  32. meta:set_string('formspec', storage_locker)
  33. end,
  34. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  35. if listname == 'src' then
  36. local item = string.sub(stack:get_name(), -3)
  37. if item == 'req' then
  38. return 1
  39. else
  40. return 0
  41. end
  42. else
  43. return 0
  44. end
  45. end,
  46. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  47. local timer = minetest.get_node_timer(pos)
  48. timer:start(5)
  49. end,
  50. on_timer = function(pos)
  51. local meta = minetest.get_meta(pos)
  52. local inv = meta:get_inventory()
  53. local instack = inv:get_stack('src', 1)
  54. local inputstack = instack:get_name()
  55. local item = string.sub(inputstack, 0, -5)
  56. inv:set_stack('src', 1, '')
  57. inv:set_stack('dst', 1, item)
  58. end,
  59. })