station_jewelry.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. local jewelry_formspec =
  2. 'size[8,8.5]'..
  3. 'list[current_name;jewelry;.5,0;1,1;]'..
  4. 'list[current_name;crystal;1.5,0;1,1;]'..
  5. 'list[current_name;mese;3,0;1,1;]'..
  6. 'image[3,0;1,1;armor_mese_outline.png]'..
  7. 'list[current_name;orb;4,0;1,1;]'..
  8. 'image[4,0;1,1;armor_orb_outline.png]'..
  9. 'list[current_name;output;6,.5;1,1;]'..
  10. 'list[current_name;relics;1,3;6,1;]'..
  11. 'list[current_player;main;0,4.5;8,4;]'..
  12. 'button[5.75,1.55;1.5,.75;forge;Forge]'..
  13. 'textarea[.5,1;5.5,2.25;;;'..
  14. 'Input a plain ring, amulet or pair of gloves, and a Gemstone with the perk you want added.'..
  15. '\nYou\'ll also need a mese crystal and lava orb.'..
  16. '\nRelics can be added to tweak the chances that control how powerful the outputted item will be.'..
  17. ' Relics are not typically consumed and can be used time and time again.]'..
  18. 'label[0,3;Relics\n--->]'
  19. minetest.register_node('stations:jewelry', {
  20. description = 'Jewelry Workshop',
  21. drawtype = 'mesh',
  22. mesh = 'stations_jewelry.obj',
  23. tiles = {'stations_jewelry.png'},
  24. use_texture_alpha = 'opaque',
  25. sounds = default.node_sound_metal_defaults(),
  26. paramtype2 = 'facedir',
  27. paramtype = 'light',
  28. selection_box = {
  29. type = 'fixed',
  30. fixed = {
  31. {-.5, -.5, -.5, 1.5, .5, .5},
  32. }
  33. },
  34. collision_box = {
  35. type = 'fixed',
  36. {-.5, -.5, -.5, 1.5, .5, .5},
  37. },
  38. groups = {oddly_breakable_by_hand=3, cracky=1},
  39. on_construct = function(pos)
  40. local meta = minetest.get_meta(pos)
  41. local inv = meta:get_inventory()
  42. inv:set_size('main', 8*4)
  43. inv:set_size('jewelry', 1)
  44. inv:set_size('mese', 1)
  45. inv:set_size('orb', 1)
  46. inv:set_size('crystal', 1)
  47. inv:set_size('output', 1)
  48. inv:set_size('relics', 6)
  49. meta:set_string('infotext', 'Jewelry Workshop')
  50. meta:set_string('formspec', jewelry_formspec)
  51. end,
  52. after_place_node = function(pos, placer, itemstack)
  53. if not epic.space_to_side(pos) then
  54. minetest.remove_node(pos)
  55. return itemstack
  56. end
  57. end,
  58. can_dig = function(pos,player)
  59. local meta = minetest.get_meta(pos);
  60. local inv = meta:get_inventory()
  61. if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
  62. and inv:is_empty('crystal') and inv:is_empty('output') then
  63. return true
  64. else
  65. return false
  66. end
  67. end,
  68. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  69. epic.remove_side_node(pos, oldnode)
  70. end,
  71. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  72. local input = stack:get_name()
  73. if listname == 'jewelry' then
  74. if input == 'armor:ring_gol' or input == 'armor:ring_tit' or input == 'armor:gloves'
  75. or input == 'armor:amulet_gol' or input == 'armor:amulet_tit' then
  76. return 99
  77. else
  78. return 0
  79. end
  80. elseif listname == 'mese' then
  81. if input == 'default:mese_crystal' then
  82. return 99
  83. else
  84. return 0
  85. end
  86. elseif listname == 'orb' then
  87. if input == 'mobs:lava_orb' then
  88. return 99
  89. else
  90. return 0
  91. end
  92. elseif listname == 'crystal' then
  93. if input == 'epic:float_crystal' or input == 'epic:bloodstone' or input == 'epic:huntite'
  94. or input == 'ocean:prismarine_crystals' or input == 'epic:garnet' or input == 'quartz:quartz_crystal_piece' then
  95. return 99
  96. else
  97. return 0
  98. end
  99. elseif listname == 'output' then
  100. return 0
  101. end
  102. return 1
  103. end,
  104. allow_metadata_inventory_move = function(pos, listname, index, stack, player)
  105. return 0
  106. end,
  107. can_dig = function(pos,player)
  108. local meta = minetest.get_meta(pos);
  109. local inv = meta:get_inventory()
  110. if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
  111. and inv:is_empty('crystal') and inv:is_empty('output') and inv:is_empty ('relics') then
  112. return true
  113. else
  114. return false
  115. end
  116. end,
  117. on_receive_fields = function(pos, formname, fields, sender)
  118. local meta = minetest.get_meta(pos)
  119. local inv = meta:get_inventory(pos)
  120. local output = inv:get_stack('output', 1)
  121. local output_count = output:get_count()
  122. if fields['forge'] and output_count == 0 then
  123. local jewelry = inv:get_stack('jewelry', 1)
  124. local mese = inv:get_stack('mese', 1)
  125. local orb = inv:get_stack('orb', 1)
  126. local crystal = inv:get_stack('crystal', 1)
  127. local relics = inv:get_list('relics')
  128. local jewelry_name = jewelry:get_name()
  129. local mese_name = mese:get_name()
  130. local orb_name = orb:get_name()
  131. local crystal_name = crystal:get_name()
  132. local perk = 'nothing'
  133. if crystal_name == 'epic:float_crystal' then
  134. perk = 'gravity'
  135. elseif crystal_name == 'epic:bloodstone' then
  136. perk = 'healing'
  137. elseif crystal_name == 'epic:huntite' then
  138. perk = 'fire'
  139. elseif crystal_name == 'ocean:prismarine_crystals' then
  140. perk = 'water'
  141. elseif crystal_name == 'epic:garnet' then
  142. perk = 'speed'
  143. elseif crystal_name == 'quartz:quartz_crystal_piece' then
  144. perk = 'jump'
  145. end
  146. local level = 0
  147. if type(relics) == 'table' then
  148. for i, stack in pairs(relics) do
  149. local def = stack:get_definition()
  150. if def.groups['relic_general'] then
  151. level = level + def.groups['relic_general']
  152. end
  153. if def.groups['relic_'..perk] then
  154. level = level + def.groups['relic_'..perk]
  155. end
  156. end
  157. end
  158. --If you're looking at the code to see how this works please don't spoil it for other players.
  159. --If I expect that is going on, I'll be forced to change things around, and not release the code.
  160. local random = math.random(0, 100)
  161. local chance = random + level
  162. local tier = 1
  163. if chance < 0 then
  164. tier = 0
  165. elseif chance > 0 and chance <= 80 then
  166. tier = 1
  167. elseif chance > 80 and chance <= 90 then
  168. tier = 2
  169. elseif chance > 90 and chance <= 98 then
  170. tier = 3
  171. elseif chance > 98 and chance <= 100 then
  172. tier = 4
  173. end
  174. local phase = moon_phases.get_phase()
  175. local time_of_day = minetest.get_timeofday()
  176. if phase == 4 and (time_of_day < .2 or time_of_day > .8) then
  177. tier = tier + 1
  178. end
  179. if perk ~= 'nothing' and jewelry_name ~= '' and mese_name ~= '' and orb_name ~= '' and tier ~= 0 then
  180. jewelry:take_item(1)
  181. mese:take_item(1)
  182. orb:take_item(1)
  183. crystal:take_item(1)
  184. inv:set_stack('jewelry', 1, jewelry)
  185. inv:set_stack('mese', 1, mese)
  186. inv:set_stack('orb', 1, orb)
  187. inv:set_stack('crystal', 1, crystal)
  188. inv:set_stack('output', 1, jewelry_name..'_'..perk..'_'..tier)
  189. minetest.log("action", sender:get_player_name() .. " crafts "..jewelry_name..'_'..perk..'_'..tier)
  190. end
  191. end
  192. end,
  193. on_rotate = function(pos, node)
  194. return false
  195. end,
  196. })
  197. minetest.register_node('stations:jewelry_locked', {
  198. description = 'Jewelry Workshop (Locked)',
  199. drawtype = 'mesh',
  200. mesh = 'stations_jewelry.obj',
  201. tiles = {'stations_jewelry.png'},
  202. use_texture_alpha = 'opaque',
  203. sounds = default.node_sound_metal_defaults(),
  204. paramtype2 = 'facedir',
  205. paramtype = 'light',
  206. selection_box = {
  207. type = 'fixed',
  208. fixed = {
  209. {-.5, -.5, -.5, 1.5, .5, .5},
  210. }
  211. },
  212. collision_box = {
  213. type = 'fixed',
  214. {-.5, -.5, -.5, 1.5, .5, .5},
  215. },
  216. groups = {oddly_breakable_by_hand=3, cracky=1},
  217. on_construct = function(pos)
  218. local meta = minetest.get_meta(pos)
  219. local inv = meta:get_inventory()
  220. inv:set_size('main', 8*4)
  221. inv:set_size('jewelry', 1)
  222. inv:set_size('mese', 1)
  223. inv:set_size('orb', 1)
  224. inv:set_size('crystal', 1)
  225. inv:set_size('output', 1)
  226. inv:set_size('relics', 6)
  227. meta:set_string('infotext', 'Jewelry Workshop (Locked)')
  228. meta:set_string('formspec', jewelry_formspec)
  229. end,
  230. after_place_node = function(pos, placer, itemstack)
  231. if not epic.space_to_side(pos) then
  232. minetest.remove_node(pos)
  233. return itemstack
  234. end
  235. end,
  236. can_dig = function(pos,player)
  237. local meta = minetest.get_meta(pos);
  238. local inv = meta:get_inventory()
  239. if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
  240. and inv:is_empty('crystal') and inv:is_empty('output') then
  241. return true
  242. else
  243. return false
  244. end
  245. end,
  246. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  247. epic.remove_side_node(pos, oldnode)
  248. end,
  249. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  250. local player_name = player:get_player_name()
  251. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  252. return 0
  253. else
  254. local input = stack:get_name()
  255. if listname == 'jewelry' then
  256. if input == 'armor:ring_gol' or input == 'armor:ring_tit' or input == 'armor:gloves'
  257. or input == 'armor:amulet_gol' or input == 'armor:amulet_tit' then
  258. return 99
  259. else
  260. return 0
  261. end
  262. elseif listname == 'mese' then
  263. if input == 'default:mese_crystal' then
  264. return 99
  265. else
  266. return 0
  267. end
  268. elseif listname == 'orb' then
  269. if input == 'mobs:lava_orb' then
  270. return 99
  271. else
  272. return 0
  273. end
  274. elseif listname == 'crystal' then
  275. if input == 'epic:float_crystal' or input == 'epic:bloodstone' or input == 'epic:huntite'
  276. or input == 'ocean:prismarine_crystals' or input == 'epic:garnet' or input == 'quartz:quartz_crystal_piece' then
  277. return 99
  278. else
  279. return 0
  280. end
  281. elseif listname == 'output' then
  282. return 0
  283. else
  284. return 1
  285. end
  286. end
  287. end,
  288. allow_metadata_inventory_move = function(pos, listname, index, stack, player)
  289. return 0
  290. end,
  291. can_dig = function(pos,player)
  292. local meta = minetest.get_meta(pos);
  293. local inv = meta:get_inventory()
  294. if inv:is_empty('jewelry') and inv:is_empty('mese') and inv:is_empty('orb')
  295. and inv:is_empty('crystal') and inv:is_empty('output') and inv:is_empty ('relics') then
  296. return true
  297. else
  298. return false
  299. end
  300. end,
  301. on_receive_fields = function(pos, formname, fields, sender)
  302. local player_name = sender:get_player_name()
  303. if not minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  304. local meta = minetest.get_meta(pos)
  305. local inv = meta:get_inventory(pos)
  306. local output = inv:get_stack('output', 1)
  307. local output_count = output:get_count()
  308. if fields['forge'] and output_count == 0 then
  309. local jewelry = inv:get_stack('jewelry', 1)
  310. local mese = inv:get_stack('mese', 1)
  311. local orb = inv:get_stack('orb', 1)
  312. local crystal = inv:get_stack('crystal', 1)
  313. local relics = inv:get_list('relics')
  314. local jewelry_name = jewelry:get_name()
  315. local mese_name = mese:get_name()
  316. local orb_name = orb:get_name()
  317. local crystal_name = crystal:get_name()
  318. local perk = 'nothing'
  319. if crystal_name == 'epic:float_crystal' then
  320. perk = 'gravity'
  321. elseif crystal_name == 'epic:bloodstone' then
  322. perk = 'healing'
  323. elseif crystal_name == 'epic:huntite' then
  324. perk = 'fire'
  325. elseif crystal_name == 'ocean:prismarine_crystals' then
  326. perk = 'water'
  327. elseif crystal_name == 'epic:garnet' then
  328. perk = 'speed'
  329. elseif crystal_name == 'quartz:quartz_crystal_piece' then
  330. perk = 'jump'
  331. end
  332. local level = 0
  333. if type(relics) == 'table' then
  334. for i, stack in pairs(relics) do
  335. local def = stack:get_definition()
  336. if def.groups['relic_general'] then
  337. level = level + def.groups['relic_general']
  338. end
  339. if def.groups['relic_'..perk] then
  340. level = level + def.groups['relic_'..perk]
  341. end
  342. end
  343. end
  344. --If you're looking at the code to see how this works please don't spoil it for other players.
  345. --If I expect that is going on, I'll be forced to change things around, and not release the code.
  346. local random = math.random(0, 100)
  347. local chance = random + level
  348. local tier = 1
  349. if chance < 0 then
  350. tier = 0
  351. elseif chance > 0 and chance <= 80 then
  352. tier = 1
  353. elseif chance > 80 and chance <= 90 then
  354. tier = 2
  355. elseif chance > 90 and chance <= 98 then
  356. tier = 3
  357. elseif chance > 98 and chance <= 100 then
  358. tier = 4
  359. end
  360. local phase = moon_phases.get_phase()
  361. local time_of_day = minetest.get_timeofday()
  362. if phase == 4 and (time_of_day < .2 or time_of_day > .8) then
  363. tier = tier + 1
  364. end
  365. if perk ~= 'nothing' and jewelry_name ~= '' and mese_name ~= '' and orb_name ~= '' and tier ~= 0 then
  366. jewelry:take_item(1)
  367. mese:take_item(1)
  368. orb:take_item(1)
  369. crystal:take_item(1)
  370. inv:set_stack('jewelry', 1, jewelry)
  371. inv:set_stack('mese', 1, mese)
  372. inv:set_stack('orb', 1, orb)
  373. inv:set_stack('crystal', 1, crystal)
  374. inv:set_stack('output', 1, jewelry_name..'_'..perk..'_'..tier)
  375. minetest.log("action", sender:get_player_name() .. " crafts "..jewelry_name..'_'..perk..'_'..tier)
  376. end
  377. end
  378. end
  379. end,
  380. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  381. local player_name = player:get_player_name()
  382. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player, 'protection_bypass') then
  383. return 0
  384. else
  385. return 99
  386. end
  387. end,
  388. on_rotate = function(pos, node)
  389. return false
  390. end,
  391. })
  392. unified_inventory.register_craft_type("jewelry", {
  393. description = "Jewelry Workshop",
  394. icon = 'stations_jewelry_icon.png',
  395. width = 4,
  396. height = 1,
  397. uses_crafting_grid = false
  398. })