station_printing.lua 4.2 KB

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