station_weaving_loom.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. unified_inventory.register_craft_type('loom', {
  2. description = 'Weaving Loom',
  3. icon = 'stations_loom_icon.png',
  4. width = 1,
  5. height = 1
  6. })
  7. unified_inventory.register_craft({
  8. type = 'loom',
  9. items = {'farming:string 5'},
  10. output = 'furniture:fabric_white'
  11. })
  12. unified_inventory.register_craft({
  13. type = 'loom',
  14. items = {'ropes:ropesegment 5'},
  15. output = 'epic:burlap'
  16. })
  17. local function loom_formspec(progress)
  18. local formspec =
  19. 'size[8,8.5]'..
  20. 'list[current_name;input;.5,1;1,1;]'..
  21. 'label[1.5,1.5;Input string]'..
  22. 'list[current_name;output;.5,3;1,1;]'..
  23. 'label[1.5,3.5;Take fabric]'..
  24. 'image[5,1;2,2.375;furniture_fabric_bg.png^[lowpart:'..(progress*20)..':furniture_fabric_fg.png]'..
  25. 'list[current_player;main;0,4.5;8,4;]'..
  26. 'listring[current_player;main]'..
  27. 'listring[context;input]'..
  28. 'listring[context;output]'..
  29. 'listring[current_player;main]'
  30. return formspec
  31. end
  32. minetest.register_node('stations:weaving_loom', {
  33. description = 'Weaving Loom',
  34. drawtype = 'mesh',
  35. mesh = 'stations_weaving_loom.obj',
  36. tiles = {'stations_weaving_loom.png'},
  37. use_texture_alpha = 'clip',
  38. sounds = default.node_sound_wood_defaults(),
  39. paramtype2 = 'facedir',
  40. paramtype = 'light',
  41. selection_box = {
  42. type = 'fixed',
  43. fixed = {
  44. {-.5, -.5, -.15, 1.5, 1.5, .15},
  45. }
  46. },
  47. collision_box = {
  48. type = 'fixed',
  49. fixed = {
  50. {-.5, -.5, -.15, 1.5, 1.5, .15},
  51. }
  52. },
  53. groups = {oddly_breakable_by_hand = 1, choppy=3},
  54. after_place_node = function(pos, placer, itemstack)
  55. if not epic.space_to_top_and_side(pos) then
  56. minetest.remove_node(pos)
  57. return itemstack
  58. end
  59. end,
  60. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  61. epic.remove_side_node(pos, oldnode)
  62. epic.remove_top_node(pos)
  63. end,
  64. on_construct = function(pos)
  65. local meta = minetest.get_meta(pos)
  66. local inv = meta:get_inventory()
  67. inv:set_size('main', 8*4)
  68. inv:set_size('input', 1)
  69. inv:set_size('output', 1)
  70. meta:set_string('progress', 0)
  71. meta:set_string('infotext', 'Weaving Loom')
  72. meta:set_string('formspec', loom_formspec(0))
  73. end,
  74. can_dig = function(pos,player)
  75. local meta = minetest.get_meta(pos);
  76. local inv = meta:get_inventory()
  77. if inv:is_empty('input') and inv:is_empty('output') then
  78. return true
  79. else
  80. return false
  81. end
  82. end,
  83. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  84. local input = stack:get_name()
  85. if listname == 'input' then
  86. if input == 'farming:string' or input == 'ropes:ropesegment' then
  87. return 99
  88. else
  89. return 0
  90. end
  91. elseif listname == 'output' then
  92. return 0
  93. end
  94. end,
  95. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  96. local timer = minetest.get_node_timer(pos)
  97. timer:start(5)
  98. end,
  99. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  100. if listname == 'output' then
  101. local meta = minetest.get_meta(pos)
  102. local progress = tonumber(meta:get_string('progress'))
  103. if progress == 0 then
  104. meta:set_string('infotext', 'Weaving Loom')
  105. meta:set_string('formspec', loom_formspec(0))
  106. end
  107. end
  108. end,
  109. on_timer = function(pos)
  110. local timer = minetest.get_node_timer(pos)
  111. local meta = minetest.get_meta(pos)
  112. local progress = tonumber(meta:get_string('progress'))
  113. local inv = meta:get_inventory()
  114. local input = inv:get_stack('input', 1)
  115. if input:get_name() == 'farming:string' or input:get_name() == 'ropes:ropesegment' then
  116. input:take_item()
  117. inv:set_stack('input',1,input)
  118. meta:set_string('progress', (progress+1))
  119. meta:set_string('infotext', 'Weaving Loom ('..((progress+1)*20)..'%)')
  120. meta:set_string('formspec', loom_formspec(progress+1))
  121. timer:start(5)
  122. if progress >= 4 then
  123. if input:get_name() == 'farming:string' then
  124. inv:add_item('output', 'furniture:fabric_white')
  125. meta:set_string('progress', 0)
  126. meta:set_string('formspec', loom_formspec(0))
  127. elseif
  128. input:get_name() == 'ropes:ropesegment' then
  129. inv:add_item('output', 'epic:burlap')
  130. meta:set_string('progress', 0)
  131. meta:set_string('formspec', loom_formspec(0))
  132. else
  133. inv:add_item('output', 'furniture:fabric_white')
  134. meta:set_string('progress', 0)
  135. meta:set_string('formspec', loom_formspec(0))
  136. end
  137. end
  138. end
  139. end,
  140. on_rotate = function(pos, node)
  141. return false
  142. end,
  143. })
  144. minetest.register_node('stations:weaving_loom_locked', {
  145. description = 'Weaving Loom (locked)',
  146. drawtype = 'mesh',
  147. mesh = 'stations_weaving_loom.obj',
  148. tiles = {'stations_weaving_loom.png'},
  149. use_texture_alpha = 'clip',
  150. sounds = default.node_sound_wood_defaults(),
  151. paramtype2 = 'facedir',
  152. paramtype = 'light',
  153. selection_box = {
  154. type = 'fixed',
  155. fixed = {
  156. {-.5, -.5, -.15, 1.5, 1.5, .15},
  157. }
  158. },
  159. collision_box = {
  160. type = 'fixed',
  161. fixed = {
  162. {-.5, -.5, -.15, 1.5, 1.5, .15},
  163. }
  164. },
  165. groups = {oddly_breakable_by_hand = 1, choppy=3},
  166. after_place_node = function(pos, placer, itemstack)
  167. if not epic.space_to_top_and_side(pos) then
  168. minetest.remove_node(pos)
  169. return itemstack
  170. end
  171. end,
  172. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  173. epic.remove_side_node(pos, oldnode)
  174. epic.remove_top_node(pos)
  175. end,
  176. on_construct = function(pos)
  177. local meta = minetest.get_meta(pos)
  178. local inv = meta:get_inventory()
  179. inv:set_size('main', 8*4)
  180. inv:set_size('input', 1)
  181. inv:set_size('output', 1)
  182. meta:set_string('progress', 0)
  183. meta:set_string('infotext', 'Weaving Loom (locked)')
  184. meta:set_string('formspec', loom_formspec(0))
  185. end,
  186. can_dig = function(pos,player)
  187. local meta = minetest.get_meta(pos);
  188. local inv = meta:get_inventory()
  189. if inv:is_empty('input') and inv:is_empty('output') then
  190. return true
  191. else
  192. return false
  193. end
  194. end,
  195. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  196. local player_name = player:get_player_name()
  197. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  198. return 0
  199. else
  200. local input = stack:get_name()
  201. if listname == 'input' then
  202. if input == 'farming:string' or input == 'ropes:ropesegment' then
  203. return 99
  204. else
  205. return 0
  206. end
  207. elseif listname == 'output' then
  208. return 0
  209. end
  210. end
  211. end,
  212. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  213. local timer = minetest.get_node_timer(pos)
  214. timer:start(5)
  215. end,
  216. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  217. local player_name = player:get_player_name()
  218. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  219. return 0
  220. else
  221. return 99
  222. end
  223. end,
  224. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  225. if listname == 'output' then
  226. local meta = minetest.get_meta(pos)
  227. local progress = tonumber(meta:get_string('progress'))
  228. if progress == 0 then
  229. meta:set_string('infotext', 'Weaving Loom')
  230. meta:set_string('formspec', loom_formspec(0))
  231. end
  232. end
  233. end,
  234. on_timer = function(pos)
  235. local timer = minetest.get_node_timer(pos)
  236. local meta = minetest.get_meta(pos)
  237. local progress = tonumber(meta:get_string('progress'))
  238. local inv = meta:get_inventory()
  239. local input = inv:get_stack('input', 1)
  240. if input:get_name() == 'farming:string' or input:get_name() == 'ropes:ropesegment' then
  241. input:take_item()
  242. inv:set_stack('input',1,input)
  243. meta:set_string('progress', (progress+1))
  244. meta:set_string('infotext', 'Weaving Loom ('..((progress+1)*20)..'%)')
  245. meta:set_string('formspec', loom_formspec(progress+1))
  246. timer:start(5)
  247. if progress >= 4 then
  248. if input:get_name() == 'farming:string' then
  249. inv:add_item('output', 'furniture:fabric_white')
  250. meta:set_string('progress', 0)
  251. meta:set_string('formspec', loom_formspec(0))
  252. elseif
  253. input:get_name() == 'ropes:ropesegment' then
  254. inv:add_item('output', 'epic:burlap')
  255. meta:set_string('progress', 0)
  256. meta:set_string('formspec', loom_formspec(0))
  257. else
  258. inv:add_item('output', 'furniture:fabric_white')
  259. meta:set_string('progress', 0)
  260. meta:set_string('formspec', loom_formspec(0))
  261. end
  262. end
  263. end
  264. end,
  265. on_rotate = function(pos, node)
  266. return false
  267. end,
  268. })