printing_press.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. local formspec_good =
  2. 'formspec_version[3]'..
  3. 'size[10,10]'..
  4. 'bgcolor[;neither]'..
  5. 'background[0,0;10,10;tasks_printing_press_working_bg.png]'..
  6. 'hypertext[2.5,9;5,1;nil;<global halign=center valign=middle><style color=black size=30>Paper stock OK.<style>]'
  7. local function formspec_bad(pos)
  8. local spos = pos.x ..','.. pos.y ..','.. pos.z
  9. local formspec =
  10. 'formspec_version[3]'..
  11. 'size[10,10]'..
  12. 'bgcolor[;neither]'..
  13. 'background[0,0;10,10;tasks_printing_press_broken_bg.png]'..
  14. 'textarea[.5,.5;3,2;;;No paper!\nPrinting halted!]' ..
  15. 'button_exit[6.75,6.25;3,1;gimme;Grab a request form]'..
  16. 'list[nodemeta:'..spos..';part;4.5,4.5;1,1;]'..
  17. 'list[current_player;main;.125,7.5;8,2;]'..
  18. 'listring[current_player;main]'..
  19. 'listring[nodemeta:'..spos..';part]'..
  20. 'image[4.5,4.5;1,1;tasks_paper_stack_line.png]'
  21. return formspec
  22. end
  23. local box = {
  24. type = 'fixed',
  25. fixed = {
  26. {-.5, .4, -.5, 0, 1, .5},
  27. {-.5, -.5, -.5, 1, .4, .5}},}
  28. minetest.register_node('tasks:printing_press_on',{
  29. description = 'Printing Press',
  30. drawtype = 'mesh',
  31. mesh = 'tasks_printing_press_on.obj',
  32. tiles = {'tasks_printing_press_on.png'},
  33. paramtype = 'light',
  34. paramtype2 = 'facedir',
  35. selection_box = box,
  36. collision_box = box,
  37. groups = {breakable = 1, tasks=1},
  38. on_construct = function(pos)
  39. tasks.on_construct(pos, 'Printing Press', 'Needs paper')
  40. end,
  41. on_rightclick = function(pos, node, clicker)
  42. tasks.right_click_on(pos, node, clicker, formspec_good)
  43. end,
  44. on_timer = function(pos)
  45. local node = minetest.get_node(pos)
  46. local meta = minetest.get_meta(pos)
  47. local infotext = meta:get_string('info_repair')
  48. meta:set_string('infotext', infotext)
  49. minetest.swap_node(pos, {name = 'tasks:printing_press_off', param2 = node.param2})
  50. end,
  51. })
  52. minetest.register_node('tasks:printing_press_off',{
  53. description = 'Printing Press',
  54. drawtype = 'mesh',
  55. mesh = 'tasks_printing_press_off.obj',
  56. tiles = {'tasks_printing_press_off.png'},
  57. paramtype = 'light',
  58. paramtype2 = 'facedir',
  59. selection_box = box,
  60. collision_box = box,
  61. groups = {breakable = 1, not_in_creative_inventory=1, tasks=1},
  62. drop = 'tasks:printing_press_on',
  63. req_form = 'tasks:paper_stack_req',
  64. req_count = 1,
  65. on_rightclick = function(pos, node, clicker)
  66. tasks.right_click_off(pos, node, clicker, formspec_bad(pos))
  67. end,
  68. allow_metadata_inventory_put = function(pos, listname, index, stack)
  69. if listname == 'part' then
  70. if stack:get_name() == 'tasks:paper_stack' then
  71. return 1
  72. else
  73. return 0
  74. end
  75. end
  76. end,
  77. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  78. local name = player:get_player_name()
  79. local meta = minetest.get_meta(pos)
  80. local xp = meta:get_int('xp') or 10
  81. local inv = meta:get_inventory()
  82. local node = minetest.get_node(pos)
  83. local timer = minetest.get_node_timer(pos)
  84. local min = meta:get_int('time_min') or 300
  85. local max = meta:get_int('time_max') or 600
  86. local random_number = math.random(min,max)
  87. local infotext = meta:get_string('info_working')
  88. inv:set_stack('part', 1, '')
  89. minetest.swap_node(pos, {name = 'tasks:printing_press_on', param2 = node.param2})
  90. minetest.close_formspec(name, 'tasks:part_req_form')
  91. meta:set_string('infotext', infotext)
  92. tasks.only_add_xp(xp, name)
  93. timer:start(random_number)
  94. end,
  95. })