station_flour_mill.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. unified_inventory.register_craft_type('mill', {
  2. description = 'Flour Mill',
  3. icon = 'stations_flour_mill_icon.png',
  4. width = 1,
  5. height = 1
  6. })
  7. unified_inventory.register_craft({
  8. type = 'mill',
  9. items = {'farming:seed_barley 4'},
  10. output = 'food:flour_barley'
  11. })
  12. unified_inventory.register_craft({
  13. type = 'mill',
  14. items = {'farming:seed_corn 4'},
  15. output = 'food:flour_corn'
  16. })
  17. unified_inventory.register_craft({
  18. type = 'mill',
  19. items = {'farming:seed_oat 4'},
  20. output = 'food:flour_oat'
  21. })
  22. unified_inventory.register_craft({
  23. type = 'mill',
  24. items = {'farming:seed_rice 4'},
  25. output = 'food:flour_rice'
  26. })
  27. unified_inventory.register_craft({
  28. type = 'mill',
  29. items = {'farming:seed_rye 4'},
  30. output = 'food:flour_rye'
  31. })
  32. unified_inventory.register_craft({
  33. type = 'mill',
  34. items = {'farming:seed_wheat 4'},
  35. output = 'food:flour_wheat'
  36. })
  37. stations.flour_seeds = {}
  38. stations.flour_seeds['farming:seed_barley'] = true
  39. stations.flour_seeds['farming:seed_corn'] = true
  40. stations.flour_seeds['farming:seed_oat'] = true
  41. stations.flour_seeds['farming:seed_rice'] = true
  42. stations.flour_seeds['farming:seed_rye'] = true
  43. stations.flour_seeds['farming:seed_wheat'] = true
  44. local formspec =
  45. 'size[8,8.5]'..
  46. 'list[current_name;input;.5,0;1,1;]'..
  47. 'list[current_name;output;5.5,2;2,2;]'..
  48. 'list[current_player;main;0,4.5;8,4;]'..
  49. 'textarea[.5,3.5;5.5,2.25;;;Four seeds will make flour]'..
  50. 'image[2,.5;3,3;stations_flour_mill_icon.png]'..
  51. 'listring[context;output]'..
  52. 'listring[current_player;main]'..
  53. 'listring[context;input]'
  54. minetest.register_node('stations:flour_mill', {
  55. description = 'Flour Mill',
  56. drawtype = 'mesh',
  57. mesh = 'stations_flour_mill.obj',
  58. tiles = {'stations_flour_mill.png'},
  59. use_texture_alpha = 'opaque',
  60. sounds = default.node_sound_wood_defaults(),
  61. paramtype2 = 'facedir',
  62. paramtype = 'light',
  63. selection_box = {
  64. type = 'fixed',
  65. fixed = {-.5, -.5, -.5, .5, .5, .5}},
  66. collision_box = {
  67. type = 'fixed',
  68. fixed = {-.5, -.5, -.5, .5, .5, .5}},
  69. groups = {oddly_breakable_by_hand = 1, choppy=3},
  70. on_construct = function(pos)
  71. local meta = minetest.get_meta(pos)
  72. local inv = meta:get_inventory()
  73. inv:set_size('input', 1)
  74. inv:set_size('output', 2*2)
  75. meta:set_string('infotext', 'Flour Mill')
  76. meta:set_string('formspec', formspec)
  77. end,
  78. can_dig = function(pos,player)
  79. local meta = minetest.get_meta(pos);
  80. local inv = meta:get_inventory()
  81. if inv:is_empty('input') and inv:is_empty('output') then
  82. return true
  83. else
  84. return false
  85. end
  86. end,
  87. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  88. local input = stack:get_name()
  89. if listname == 'input' then
  90. if stations.flour_seeds[input] then
  91. return 99
  92. else
  93. return 0
  94. end
  95. elseif listname == 'output' then
  96. return 0
  97. end
  98. end,
  99. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  100. local timer = minetest.get_node_timer(pos)
  101. timer:start(3)
  102. end,
  103. on_timer = function(pos)
  104. local timer = minetest.get_node_timer(pos)
  105. local meta = minetest.get_meta(pos)
  106. local inv = meta:get_inventory()
  107. local input = inv:get_stack('input', 1)
  108. local input_count = input:get_count()
  109. if input_count >= 4 then
  110. local output = inv:get_stack('output', 1)
  111. local grain_name = input:get_name()
  112. local grain = string.sub(grain_name, 14,-1)
  113. inv:add_item('output', 'food:flour_'..grain)
  114. input:take_item(4)
  115. inv:set_stack('input',1,input)
  116. timer:start(3)
  117. end
  118. end,
  119. })
  120. minetest.register_node('stations:flour_mill_locked', {
  121. description = 'Flour Mill (locked)',
  122. drawtype = 'mesh',
  123. mesh = 'stations_flour_mill.obj',
  124. tiles = {'stations_flour_mill.png'},
  125. use_texture_alpha = 'opaque',
  126. sounds = default.node_sound_wood_defaults(),
  127. paramtype2 = 'facedir',
  128. paramtype = 'light',
  129. selection_box = {
  130. type = 'fixed',
  131. fixed = {-.5, -.5, -.5, .5, .5, .5}},
  132. collision_box = {
  133. type = 'fixed',
  134. fixed = {-.5, -.5, -.5, .5, .5, .5}},
  135. groups = {oddly_breakable_by_hand = 1, choppy=3},
  136. on_construct = function(pos)
  137. local meta = minetest.get_meta(pos)
  138. local inv = meta:get_inventory()
  139. inv:set_size('input', 1)
  140. inv:set_size('output', 2*2)
  141. meta:set_string('infotext', 'Flour Mill')
  142. meta:set_string('formspec', formspec)
  143. end,
  144. can_dig = function(pos,player)
  145. local meta = minetest.get_meta(pos);
  146. local inv = meta:get_inventory()
  147. if inv:is_empty('input') and inv:is_empty('output') then
  148. return true
  149. else
  150. return false
  151. end
  152. end,
  153. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  154. local player_name = player:get_player_name()
  155. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  156. return 0
  157. else
  158. local input = stack:get_name()
  159. if listname == 'input' then
  160. if stations.flour_seeds[input] then
  161. return 99
  162. else
  163. return 0
  164. end
  165. elseif listname == 'output' then
  166. return 0
  167. end
  168. end
  169. end,
  170. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  171. local timer = minetest.get_node_timer(pos)
  172. timer:start(3)
  173. end,
  174. on_timer = function(pos)
  175. local timer = minetest.get_node_timer(pos)
  176. local meta = minetest.get_meta(pos)
  177. local inv = meta:get_inventory()
  178. local input = inv:get_stack('input', 1)
  179. local input_count = input:get_count()
  180. if input_count >= 4 then
  181. local output = inv:get_stack('output', 1)
  182. local grain_name = input:get_name()
  183. local grain = string.sub(grain_name, 14,-1)
  184. inv:add_item('output', 'food:flour_'..grain)
  185. input:take_item(4)
  186. inv:set_stack('input',1,input)
  187. timer:start(3)
  188. end
  189. end,
  190. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  191. local player_name = player:get_player_name()
  192. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  193. return 0
  194. else
  195. return 99
  196. end
  197. end,
  198. })