station_printing.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. minetest.register_node('stations:printing_press', {
  2. description = 'Printing Press',
  3. drawtype = 'mesh',
  4. mesh = 'stations_printing_press.obj',
  5. tiles = {'stations_printing_press.png'},
  6. sounds = default.node_sound_wood_defaults(),
  7. paramtype2 = 'facedir',
  8. paramtype = 'light',
  9. selection_box = {
  10. type = 'fixed',
  11. fixed = {
  12. {-.5, .4, -.5, 0, 1, .5}, --Upright
  13. {-.5, -.5, -.5, 1, .4, .5}, --base
  14. }
  15. },
  16. collision_box = {
  17. type = 'fixed',
  18. fixed = {-.5, -.5, -.5, 1, .4, .5}, --base
  19. },
  20. groups = {oddly_breakable_by_hand=3, choppy=1},
  21. after_place_node = function(pos, placer)
  22. if not epic.space_to_side(pos) then
  23. minetest.remove_node(pos)
  24. return itemstack
  25. else
  26. local meta = minetest.get_meta(pos)
  27. local inv = meta:get_inventory()
  28. inv:set_size('master', 1)
  29. inv:set_size('input', 1)
  30. inv:set_size('output', 1)
  31. meta:set_string('infotext', 'printing press')
  32. meta:set_string('owner' , placer:get_player_name())
  33. end
  34. end,
  35. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  36. epic.remove_side_node(pos, oldnode)
  37. end,
  38. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  39. if listname == 'output' then
  40. return 0
  41. elseif listname == 'master' then
  42. local meta = minetest.get_meta(pos)
  43. local name = player:get_player_name()
  44. local owner = meta:get_string('owner')
  45. if name == owner then
  46. if stack:get_name() == ('default:book_written') then
  47. return 1
  48. else
  49. return 0
  50. end
  51. else
  52. return 0
  53. end
  54. elseif listname == 'input' then
  55. if stack:get_name() == ('default:book') then
  56. return 1
  57. else
  58. return 0
  59. end
  60. end
  61. end,
  62. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  63. return 0
  64. end,
  65. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  66. local meta=minetest.get_meta(pos)
  67. local name = player:get_player_name()
  68. local owner = meta:get_string('owner')
  69. local spos = pos.x..','..pos.y..','..pos.z
  70. local gui = 'size[8,7;]'..
  71. 'label[5,0.25;Master Copy:]'..
  72. 'list[nodemeta:'..spos..';master;4,0;1,1]'..
  73. 'label[1.5,1.25;Empty Book.]'..
  74. 'list[nodemeta:'..spos..';input;.5,1;1,1;]'..
  75. 'label[1.5,2.25;Printed Copy.]'..
  76. 'list[nodemeta:'..spos..';output;.5,2;1,1;]'..
  77. 'button[4.5,1.5;2,1;copy;Print a copy!]'..
  78. 'list[current_player;main;0,3;8,4;]'
  79. meta:set_string('formspec', gui)
  80. end,
  81. on_receive_fields = function(pos, formname, fields, sender)
  82. local meta = minetest.get_meta(pos)
  83. if fields ['copy'] then
  84. local meta = minetest.get_meta(pos)
  85. local inv = meta:get_inventory()
  86. local master_stack = inv:get_stack('master', 1)
  87. local input_stack = inv:get_stack('input', 1)
  88. local master_book = master_stack:get_name()
  89. local empty_book = input_stack:get_name()
  90. if master_book == 'default:book_written' then
  91. if empty_book == 'default:book' then
  92. inv:add_item('output', 'default:book_written')
  93. input_stack:take_item(1)
  94. local output = inv:get_stack('output', 1)
  95. local copymeta = master_stack:get_meta():to_table()
  96. output:get_meta():from_table(copymeta)
  97. inv:set_stack('output', 1, output)
  98. inv:set_stack('input', 1, input_stack)
  99. end
  100. end
  101. end
  102. end,
  103. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  104. local meta = minetest.get_meta(pos)
  105. local name = player:get_player_name()
  106. local owner = meta:get_string('owner')
  107. if listname == 'master' then
  108. if name == owner then
  109. return 1
  110. else
  111. return 0
  112. end
  113. elseif listname == 'input' then
  114. return 1
  115. elseif listname == 'output' then
  116. return 1
  117. end
  118. end,
  119. })