station_dying.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. unified_inventory.register_craft_type('dye', {
  2. description = 'Dying Station',
  3. icon = 'stations_dye_icon.png',
  4. width = 2,
  5. height = 1
  6. })
  7. local dye_table = dye.dyes
  8. for i in ipairs(dye_table) do
  9. local name = dye_table[i][1]
  10. unified_inventory.register_craft({
  11. type = 'dye',
  12. items = {'furniture:fabric_white', 'dye:'..name},
  13. output = 'furniture:fabric_'..name
  14. })
  15. end
  16. local function dying_formspec(water_level)
  17. formspec =
  18. 'size[8,8.5]'..
  19. 'list[current_name;dye;.5,0;1,1;]'..
  20. 'label[1.5,0.25;Input dye]'..
  21. 'list[current_name;salt;.5,1;1,1;]'..
  22. 'label[1.5,1.25;Input salt]'..
  23. 'list[current_name;fabric;.5,2;1,1;]'..
  24. 'label[1.5,2.25;Input fabric/thread]'..
  25. 'list[current_name;water;.5,3;1,1;]'..
  26. 'label[1.5,3.25;Input water]'..
  27. 'list[current_name;output;6.5,0;1,4;]'..
  28. 'image[4.5,.5;1,3;stations_dye_bg.png^[lowpart:'..(water_level*10)..':stations_dye_fg.png]'..
  29. 'list[current_player;main;0,4.5;8,4;]'..
  30. 'listring[context;output]'..
  31. 'listring[current_player;main]'
  32. return formspec
  33. end
  34. minetest.register_node('stations:dying', {
  35. description = 'Dying Station',
  36. drawtype = 'mesh',
  37. mesh = 'stations_dying.obj',
  38. tiles = {'stations_dying.png'},
  39. use_texture_alpha = 'opaque',
  40. sounds = default.node_sound_wood_defaults(),
  41. paramtype2 = 'facedir',
  42. paramtype = 'light',
  43. selection_box = {
  44. type = 'fixed',
  45. fixed = {-.5, -.5, -.5, 1.5, .3, .5}},
  46. collision_box = {
  47. type = 'fixed',
  48. fixed = {-.5, -.5, -.5, 1.5, .3, .5}},
  49. groups = {oddly_breakable_by_hand = 1, choppy=3},
  50. after_place_node = function(pos, placer, itemstack)
  51. if not epic.space_to_side(pos) then
  52. minetest.remove_node(pos)
  53. return itemstack
  54. end
  55. end,
  56. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  57. epic.remove_side_node(pos, oldnode)
  58. end,
  59. on_construct = function(pos)
  60. local meta = minetest.get_meta(pos)
  61. local inv = meta:get_inventory()
  62. inv:set_size('dye', 1)
  63. inv:set_size('salt', 1)
  64. inv:set_size('fabric', 1)
  65. inv:set_size('water', 1)
  66. inv:set_size('output', 4)
  67. meta:set_string('water_level', 0)
  68. meta:set_string('infotext', 'Dying Station')
  69. meta:set_string('formspec', dying_formspec(0))
  70. end,
  71. can_dig = function(pos,player)
  72. local meta = minetest.get_meta(pos);
  73. local inv = meta:get_inventory()
  74. if inv:is_empty('dye') and inv:is_empty('salt') and inv:is_empty('fabric')
  75. and inv:is_empty('water') and inv:is_empty('output') then
  76. return true
  77. else
  78. return false
  79. end
  80. end,
  81. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  82. local input = stack:get_name()
  83. if listname == 'dye' then
  84. if minetest.get_item_group(input, 'dye') > 0 and input ~= 'dye:white' then
  85. return 99
  86. else
  87. return 0
  88. end
  89. elseif listname == 'salt' then
  90. if input == 'epic:salt' then
  91. return 99
  92. else
  93. return 0
  94. end
  95. elseif listname == 'fabric' then
  96. if input == 'furniture:fabric_white' or input == 'furniture:thread_white' then
  97. return 99
  98. else
  99. return 0
  100. end
  101. elseif listname == 'water' then
  102. if input == 'bucket:bucket_river_water' or input == 'bucket:bucket_water'
  103. or input == 'earthbuild:clay_pot_river_water' or input == 'earthbuild:clay_pot_water' then
  104. return 1
  105. else
  106. return 0
  107. end
  108. elseif listname == 'output' then
  109. return 0
  110. end
  111. end,
  112. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  113. local meta = minetest.get_meta(pos)
  114. local input = stack:get_name()
  115. local inv = meta:get_inventory()
  116. local timer = minetest.get_node_timer(pos)
  117. timer:start(3)
  118. if listname == 'water' then
  119. meta:set_string('formspec', dying_formspec(10))
  120. meta:set_string('water_level', 10)
  121. local vessel = string.sub(input, 1,3)
  122. if vessel == 'ear' then
  123. inv:set_stack('water', 1, 'earthbuild:clay_pot')
  124. elseif vessel == 'buc' then
  125. inv:set_stack('water', 1, 'bucket:bucket_empty')
  126. end
  127. end
  128. end,
  129. on_timer = function(pos)
  130. local timer = minetest.get_node_timer(pos)
  131. local meta = minetest.get_meta(pos)
  132. local water_level = tonumber(meta:get_string('water_level'))
  133. if water_level > 0 then
  134. local inv = meta:get_inventory()
  135. local input_dye = inv:get_stack('dye', 1)
  136. local input_salt = inv:get_stack('salt', 1)
  137. local input_fabric = inv:get_stack('fabric', 1)
  138. local dye = input_dye:get_count()
  139. local salt = input_salt:get_count()
  140. local fabric = input_fabric:get_count()
  141. if dye > 0 and salt > 0 and fabric > 0 then --Let's dye things
  142. local dye_name = input_dye:get_name()
  143. local color = string.sub(dye_name, 5,-1)
  144. local fabric_name = input_fabric:get_name()
  145. local material = string.sub(fabric_name, 11,-7)
  146. inv:add_item('output', 'furniture:'..material..'_'..color)
  147. meta:set_string('water_level', (water_level-1))
  148. meta:set_string('formspec', dying_formspec(water_level-1))
  149. input_dye:take_item(1)
  150. input_salt:take_item(1)
  151. input_fabric:take_item(1)
  152. inv:set_stack('dye',1,input_dye)
  153. inv:set_stack('salt',1,input_salt)
  154. inv:set_stack('fabric',1,input_fabric)
  155. timer:start(3)
  156. end
  157. end
  158. end,
  159. on_rotate = function(pos, node)
  160. return false
  161. end,
  162. })
  163. minetest.register_node('stations:dying_locked', {
  164. description = 'Dying Station (locked)',
  165. drawtype = 'mesh',
  166. mesh = 'stations_dying.obj',
  167. tiles = {'stations_dying.png'},
  168. use_texture_alpha = 'opaque',
  169. sounds = default.node_sound_wood_defaults(),
  170. paramtype2 = 'facedir',
  171. paramtype = 'light',
  172. selection_box = {
  173. type = 'fixed',
  174. fixed = {-.5, -.5, -.5, 1.5, .3, .5}},
  175. collision_box = {
  176. type = 'fixed',
  177. fixed = {-.5, -.5, -.5, 1.5, .3, .5}},
  178. groups = {oddly_breakable_by_hand = 1, choppy=3},
  179. after_place_node = function(pos, placer, itemstack)
  180. if not epic.space_to_side(pos) then
  181. minetest.remove_node(pos)
  182. return itemstack
  183. end
  184. end,
  185. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  186. epic.remove_side_node(pos, oldnode)
  187. end,
  188. on_construct = function(pos)
  189. local meta = minetest.get_meta(pos)
  190. local inv = meta:get_inventory()
  191. inv:set_size('dye', 1)
  192. inv:set_size('salt', 1)
  193. inv:set_size('fabric', 1)
  194. inv:set_size('water', 1)
  195. inv:set_size('output', 4)
  196. meta:set_string('water_level', 0)
  197. meta:set_string('infotext', 'Dying Station (locked)')
  198. meta:set_string('formspec', dying_formspec(0))
  199. end,
  200. can_dig = function(pos,player)
  201. local meta = minetest.get_meta(pos);
  202. local inv = meta:get_inventory()
  203. if inv:is_empty('dye') and inv:is_empty('salt') and inv:is_empty('fabric')
  204. and inv:is_empty('water') and inv:is_empty('output') then
  205. return true
  206. else
  207. return false
  208. end
  209. end,
  210. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  211. local player_name = player:get_player_name()
  212. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  213. return 0
  214. else
  215. local input = stack:get_name()
  216. if listname == 'dye' then
  217. if minetest.get_item_group(input, 'dye') > 0 and input ~= 'dye:white' then
  218. return 99
  219. else
  220. return 0
  221. end
  222. elseif listname == 'salt' then
  223. if input == 'epic:salt' then
  224. return 99
  225. else
  226. return 0
  227. end
  228. elseif listname == 'fabric' then
  229. if input == 'furniture:fabric_white' or input == 'furniture:thread_white' then
  230. return 99
  231. else
  232. return 0
  233. end
  234. elseif listname == 'water' then
  235. if input == 'bucket:bucket_river_water' or input == 'bucket:bucket_water'
  236. or input == 'earthbuild:clay_pot_river_water' or input == 'earthbuild:clay_pot_water' then
  237. return 1
  238. else
  239. return 0
  240. end
  241. elseif listname == 'output' then
  242. return 0
  243. end
  244. end
  245. end,
  246. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  247. local meta = minetest.get_meta(pos)
  248. local input = stack:get_name()
  249. local inv = meta:get_inventory()
  250. local timer = minetest.get_node_timer(pos)
  251. timer:start(3)
  252. if listname == 'water' then
  253. meta:set_string('formspec', dying_formspec(10))
  254. meta:set_string('water_level', 10)
  255. local vessel = string.sub(input, 1,3)
  256. if vessel == 'ear' then
  257. inv:set_stack('water', 1, 'earthbuild:clay_pot')
  258. elseif vessel == 'buc' then
  259. inv:set_stack('water', 1, 'bucket:bucket_empty')
  260. end
  261. end
  262. end,
  263. on_timer = function(pos)
  264. local timer = minetest.get_node_timer(pos)
  265. local meta = minetest.get_meta(pos)
  266. local water_level = tonumber(meta:get_string('water_level'))
  267. if water_level > 0 then
  268. local inv = meta:get_inventory()
  269. local input_dye = inv:get_stack('dye', 1)
  270. local input_salt = inv:get_stack('salt', 1)
  271. local input_fabric = inv:get_stack('fabric', 1)
  272. local dye = input_dye:get_count()
  273. local salt = input_salt:get_count()
  274. local fabric = input_fabric:get_count()
  275. if dye > 0 and salt > 0 and fabric > 0 then --Let's dye things
  276. local dye_name = input_dye:get_name()
  277. local color = string.sub(dye_name, 5,-1)
  278. local fabric_name = input_fabric:get_name()
  279. local material = string.sub(fabric_name, 11,-7)
  280. inv:add_item('output', 'furniture:'..material..'_'..color)
  281. meta:set_string('water_level', (water_level-1))
  282. meta:set_string('formspec', dying_formspec(water_level-1))
  283. input_dye:take_item(1)
  284. input_salt:take_item(1)
  285. input_fabric:take_item(1)
  286. inv:set_stack('dye',1,input_dye)
  287. inv:set_stack('salt',1,input_salt)
  288. inv:set_stack('fabric',1,input_fabric)
  289. timer:start(3)
  290. end
  291. end
  292. end,
  293. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  294. local player_name = player:get_player_name()
  295. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  296. return 0
  297. else
  298. return 99
  299. end
  300. end,
  301. on_rotate = function(pos, node)
  302. return false
  303. end,
  304. })