init.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. --[[
  2. Gravel Sieve Mod
  3. ================
  4. v1.09 by JoSt
  5. Derived from the work of celeron55, Perttu Ahola (furnace)
  6. Pipeworks support added by FiftySix
  7. Copyright (C) 2017-2020 Joachim Stolberg
  8. Copyright (C) 2011-2016 celeron55, Perttu Ahola <celeron55@gmail.com>
  9. Copyright (C) 2011-2016 Various Minetest developers and contributors
  10. AGPL v3
  11. See LICENSE.txt for more information
  12. History:
  13. 2017-06-14 v0.01 First version
  14. 2017-06-15 v0.02 Manually use of the sieve added
  15. 2017-06-17 v0.03 * Settings bug fixed
  16. * Drop bug fixed
  17. * Compressed Gravel block added (Inspired by Modern Hippie)
  18. * Recipes for Compressed Gravel added
  19. 2017-06-17 v0.04 * Support for manual and automatic gravel sieve
  20. * Rarity now configurable
  21. * Output is 50% gravel and 50% sieved gravel
  22. 2017-06-20 v0.05 * Hammer sound bugfix
  23. 2017-06-24 v1.00 * Released version w/o any changes
  24. 2017-07-08 V1.01 * extended for moreores
  25. 2017-07-09 V1.02 * Cobblestone bugfix (NathanSalapat)
  26. * ore_probability is now global accessable (bell07)
  27. 2017-08-29 V1.03 * Fix syntax listring (Jat15)
  28. 2017-09-08 V1.04 * Adaption to Tubelib
  29. 2017-11-03 V1.05 * Adaption to Tubelib v0.06
  30. 2018-01-01 V1.06 * Hopper support added
  31. 2018-01-02 V1.07 * changed to registered ores
  32. 2018-02-09 V1.08 * Pipeworks support added, bugfix for issue #7
  33. 2018-12-28 V1.09 * Ore probability calculation changed (thanks to obl3pplifp)
  34. tubelib aging added
  35. ]]--
  36. gravelsieve = {
  37. }
  38. -- Load support for I18n
  39. gravelsieve.S = minetest.get_translator("gravelsieve")
  40. local S = gravelsieve.S
  41. dofile(minetest.get_modpath("gravelsieve") .. "/hammer.lua")
  42. local settings_get
  43. if minetest.setting_get then
  44. settings_get = minetest.setting_get
  45. else
  46. settings_get = function(...) return minetest.settings:get(...) end
  47. end
  48. gravelsieve.ore_rarity = tonumber(settings_get("gravelsieve_ore_rarity")) or 1.16
  49. gravelsieve.ore_max_elevation = tonumber(settings_get("gravelsieve_ore_max_elevation")) or 0
  50. gravelsieve.ore_min_elevation = tonumber(settings_get("gravelsieve_ore_min_elevation")) or -30912
  51. local y_spread = math.max(1 + gravelsieve.ore_max_elevation - gravelsieve.ore_min_elevation, 1)
  52. -- Increase the probability over the natural occurrence
  53. local PROBABILITY_FACTOR = tonumber(settings_get("gravelsieve_probability_factor")) or 3
  54. local STEP_DELAY = tonumber(settings_get("gravelsieve_step_delay")) or 1.0
  55. -- tubelib aging feature
  56. local AGING_LEVEL1 = nil
  57. local AGING_LEVEL2 = nil
  58. if minetest.get_modpath("tubelib") and tubelib ~= nil then
  59. AGING_LEVEL1 = 15 * tubelib.machine_aging_value
  60. AGING_LEVEL2 = 60 * tubelib.machine_aging_value
  61. end
  62. -- Ore probability table (1/n)
  63. gravelsieve.ore_probability = {
  64. }
  65. gravelsieve.process_probabilities = {}
  66. -- Pipeworks support
  67. local pipeworks_after_dig = nil
  68. local pipeworks_after_place = function(pos, placer) end
  69. if minetest.get_modpath("pipeworks") and pipeworks ~= nil then
  70. pipeworks_after_dig = pipeworks.after_dig
  71. pipeworks_after_place = pipeworks.after_place
  72. end
  73. local function calculate_probability(item)
  74. local ymax = math.min(item.y_max, gravelsieve.ore_max_elevation)
  75. local ymin = math.max(item.y_min, gravelsieve.ore_min_elevation)
  76. return (gravelsieve.ore_rarity / PROBABILITY_FACTOR) *
  77. item.clust_scarcity / (item.clust_num_ores * ((ymax - ymin) / y_spread))
  78. end
  79. local function pairs_by_values(t, f)
  80. if not f then
  81. f = function(a, b) return a > b end
  82. end
  83. local s = {}
  84. for k, v in pairs(t) do
  85. table.insert(s, {k, v})
  86. end
  87. table.sort(s, function(a, b)
  88. return f(a[2], b[2])
  89. end)
  90. local i = 0
  91. return function()
  92. i = i + 1
  93. local v = s[i]
  94. if v then
  95. return unpack(v)
  96. else
  97. return nil
  98. end
  99. end
  100. end
  101. local function parse_drop(drop)
  102. local d, count = drop:match("^%s*(%S+)%s+(%d+)%s*$")
  103. if d and count then
  104. return d, count
  105. end
  106. d, count = drop:match("%s*craft%s+\"?([^%s\"]+)\"?%s+(%d+)%s*")
  107. if d and count then
  108. return d, count
  109. end
  110. return drop, 1
  111. end
  112. -- collect all registered ores and calculate the probability
  113. local function add_ores()
  114. for _,item in pairs(minetest.registered_ores) do
  115. if minetest.registered_nodes[item.ore] then
  116. local drop = minetest.registered_nodes[item.ore].drop
  117. if type(drop) == "string"
  118. and drop ~= item.ore
  119. and drop ~= ""
  120. and item.ore_type == "scatter"
  121. and item.wherein == "default:stone"
  122. and item.clust_scarcity ~= nil and item.clust_scarcity > 0
  123. and item.clust_num_ores ~= nil and item.clust_num_ores > 0
  124. and item.y_max ~= nil and item.y_min ~= nil then
  125. local count
  126. drop, count = parse_drop(drop)
  127. local probability = calculate_probability(item)
  128. if probability > 0 then
  129. local probabilityFraction = count / probability
  130. local cur_probability = gravelsieve.ore_probability[drop]
  131. if cur_probability then
  132. gravelsieve.ore_probability[drop] = cur_probability+probabilityFraction
  133. else
  134. gravelsieve.ore_probability[drop] = probabilityFraction
  135. end
  136. end
  137. end
  138. end
  139. end
  140. minetest.log("action", "[gravelsieve] ore probabilties:")
  141. local overall_probability = 0.0
  142. for name,probability in pairs_by_values(gravelsieve.ore_probability) do
  143. minetest.log("action", ("[gravelsieve] %-32s: 1 / %.02f"):format(name, 1.0/probability))
  144. overall_probability = overall_probability + probability
  145. end
  146. minetest.log("action", ("[gravelsieve] Overall probability %f"):format(overall_probability))
  147. end
  148. local function default_configuration()
  149. local normal_gravel = "default:gravel"
  150. local sieved_gravel = "gravelsieve:sieved_gravel"
  151. local gravel_probabilities = table.copy(gravelsieve.ore_probability)
  152. local overall_probability = 0
  153. for _,v in pairs(gravel_probabilities) do
  154. overall_probability = overall_probability+v
  155. end
  156. local remainder_probability = 0
  157. if overall_probability < 1 then
  158. remainder_probability = 1-overall_probability
  159. end
  160. gravel_probabilities[normal_gravel] = remainder_probability/2.0
  161. gravel_probabilities[sieved_gravel] = remainder_probability/2.0
  162. return {
  163. [normal_gravel] = gravel_probabilities,
  164. [sieved_gravel] = {
  165. [sieved_gravel] = 1
  166. }
  167. }
  168. end
  169. local function normalize_probabilities(conf)
  170. local total = 0
  171. for _,val in pairs(conf) do
  172. if val >= 0 then
  173. total = total + val
  174. end
  175. end
  176. local normalized = {}
  177. for key,val in pairs(conf) do
  178. if val >= 0 then
  179. normalized[key] = val/total
  180. end
  181. end
  182. return normalized
  183. end
  184. local function normalize_config(current_config)
  185. local normalized_config = {}
  186. -- Normalize all inputs so their output probabilities always add up to 1
  187. for input, output_probabilities in pairs(current_config) do
  188. if output_probabilities then
  189. normalized_config[input] = normalize_probabilities(output_probabilities)
  190. end
  191. end
  192. return normalized_config
  193. end
  194. local function merge_config(def_conf, new_conf)
  195. local result_conf = table.copy(def_conf)
  196. for key,val in pairs(new_conf) do
  197. if type(val) == 'table' and type(result_conf[key]) == 'table' then
  198. result_conf[key] = merge_config(result_conf[key], val)
  199. else
  200. result_conf[key] = val
  201. end
  202. end
  203. return result_conf
  204. end
  205. local function configure_probabilities_step(current_config, funct_or_table)
  206. local var_type = type(funct_or_table)
  207. local conf
  208. if var_type == 'function' then
  209. conf = funct_or_table()
  210. elseif var_type == 'table' then
  211. conf = funct_or_table
  212. end
  213. if conf then
  214. return merge_config(current_config, conf)
  215. end
  216. return current_config
  217. end
  218. local configured = false
  219. local set_probabilities = {default_configuration}
  220. function gravelsieve.set_probabilities(funct_or_table)
  221. if configured then
  222. -- This is here so you can do hard overrides after everything has loaded if you need to
  223. -- Otherwise the order mods are loaded may cause them to override your configs
  224. local current_config = gravelsieve.process_probabilities
  225. current_config = configure_probabilities_step(current_config, funct_or_table)
  226. gravelsieve.process_probabilities = normalize_config(current_config)
  227. else
  228. -- Build up a list of callbacks to be run after all mods are loaded
  229. table.insert(set_probabilities, funct_or_table)
  230. end
  231. end
  232. local function configure_probabilities()
  233. configured = true
  234. add_ores()
  235. local current_config = {}
  236. -- Run through all configs in order and merge them
  237. for _,funct_or_table in ipairs(set_probabilities) do
  238. current_config = configure_probabilities_step(current_config, funct_or_table)
  239. end
  240. gravelsieve.process_probabilities = normalize_config(current_config)
  241. end
  242. minetest.after(1, configure_probabilities)
  243. local sieve_formspec =
  244. "size[8,8]"..
  245. default.gui_bg..
  246. default.gui_bg_img..
  247. default.gui_slots..
  248. "list[context;src;1,1.5;1,1;]"..
  249. "image[3,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
  250. "list[context;dst;4,0;4,4;]"..
  251. "list[current_player;main;0,4.2;8,4;]"..
  252. "listring[context;dst]"..
  253. "listring[current_player;main]"..
  254. "listring[context;src]"..
  255. "listring[current_player;main]"
  256. local function allow_metadata_inventory_put(pos, listname, index, stack, player)
  257. if minetest.is_protected(pos, player:get_player_name()) then
  258. return 0
  259. end
  260. local meta = minetest.get_meta(pos)
  261. local inv = meta:get_inventory()
  262. if listname == "src" then
  263. return stack:get_count()
  264. elseif listname == "dst" then
  265. return 0
  266. end
  267. end
  268. local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
  269. local meta = minetest.get_meta(pos)
  270. local inv = meta:get_inventory()
  271. local stack = inv:get_stack(from_list, from_index)
  272. return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
  273. end
  274. local function allow_metadata_inventory_take(pos, listname, index, stack, player)
  275. if minetest.is_protected(pos, player:get_player_name()) then
  276. return 0
  277. end
  278. return stack:get_count()
  279. end
  280. local function aging(pos, meta)
  281. if AGING_LEVEL1 then
  282. local cnt = meta:get_int("tubelib_aging") + 1
  283. meta:set_int("tubelib_aging", cnt)
  284. if cnt > AGING_LEVEL1 and math.random(AGING_LEVEL2) == 1 then
  285. minetest.get_node_timer(pos):stop()
  286. minetest.swap_node(pos, {name = "gravelsieve:sieve_defect"})
  287. end
  288. end
  289. end
  290. -- handle the sieve animation
  291. local function swap_node(pos, meta, start)
  292. local node = minetest.get_node(pos)
  293. local idx = meta:get_int("idx")
  294. if start then
  295. if idx == 3 then
  296. idx = 0
  297. end
  298. else
  299. idx = (idx + 1) % 4
  300. end
  301. meta:set_int("idx", idx)
  302. node.name = meta:get_string("node_name")..idx
  303. minetest.swap_node(pos, node)
  304. return idx == 3
  305. end
  306. -- place ores to dst according to the calculated probability
  307. local function move_random_ore(inv, item)
  308. local running_total = 0
  309. local probabilities = gravelsieve.process_probabilities[item]
  310. local chosen = math.random()
  311. for ore, probability in pairs(probabilities) do
  312. running_total = running_total + probability
  313. if chosen < running_total then
  314. local ore_item = ItemStack(ore)
  315. if not inv:room_for_item("dst", ore_item) then
  316. return false
  317. end
  318. inv:add_item("dst", ore_item)
  319. return true
  320. end
  321. end
  322. return false -- Failure, this shouldn't really happen but might due to floating point errors
  323. end
  324. -- move gravel and ores to dst
  325. local function move_src2dst(meta, pos, inv, item, dst)
  326. local src = ItemStack(item)
  327. if inv:room_for_item("dst", dst) and inv:contains_item("src", src) then
  328. local res = swap_node(pos, meta, false)
  329. if res then -- time to move one item?
  330. local processed = move_random_ore(inv, item)
  331. if processed then
  332. inv:remove_item("src", src)
  333. end
  334. end
  335. return true -- process finished
  336. end
  337. return false -- process still running
  338. end
  339. -- timer callback, alternatively called by on_punch
  340. local function sieve_node_timer(pos, elapsed)
  341. local meta = minetest.get_meta(pos)
  342. local inv = meta:get_inventory()
  343. for item,probabilities in pairs(gravelsieve.process_probabilities) do
  344. if probabilities and move_src2dst(meta, pos, inv, item) then
  345. aging(pos, meta)
  346. return true
  347. end
  348. end
  349. minetest.get_node_timer(pos):stop()
  350. return false
  351. end
  352. for automatic = 0,1 do
  353. for idx = 0,4 do
  354. local nodebox_data = {
  355. { -8/16, -8/16, -8/16, 8/16, 4/16, -6/16 },
  356. { -8/16, -8/16, 6/16, 8/16, 4/16, 8/16 },
  357. { -8/16, -8/16, -8/16, -6/16, 4/16, 8/16 },
  358. { 6/16, -8/16, -8/16, 8/16, 4/16, 8/16 },
  359. { -6/16, -2/16, -6/16, 6/16, 8/16, 6/16 },
  360. }
  361. nodebox_data[5][5] = (8 - 2*idx) / 16
  362. local node_name
  363. local description
  364. local tiles_data
  365. local tube_info
  366. if automatic == 0 then
  367. node_name = "gravelsieve:sieve"
  368. description = S("Gravel Sieve")
  369. tiles_data = {
  370. -- up, down, right, left, back, front
  371. "gravelsieve_gravel.png",
  372. "gravelsieve_gravel.png",
  373. "gravelsieve_sieve.png",
  374. "gravelsieve_sieve.png",
  375. "gravelsieve_sieve.png",
  376. "gravelsieve_sieve.png",
  377. }
  378. else
  379. node_name = "gravelsieve:auto_sieve"
  380. description = S("Automatic Gravel Sieve")
  381. tiles_data = {
  382. -- up, down, right, left, back, front
  383. "gravelsieve_gravel.png",
  384. "gravelsieve_gravel.png",
  385. "gravelsieve_auto_sieve.png",
  386. "gravelsieve_auto_sieve.png",
  387. "gravelsieve_auto_sieve.png",
  388. "gravelsieve_auto_sieve.png",
  389. }
  390. -- Pipeworks support
  391. tube_info = {
  392. insert_object = function(pos, node, stack, direction)
  393. local meta = minetest.get_meta(pos)
  394. local inv = meta:get_inventory()
  395. if automatic == 0 then
  396. local meta = minetest.get_meta(pos)
  397. swap_node(pos, meta, true)
  398. else
  399. minetest.get_node_timer(pos):start(STEP_DELAY)
  400. end
  401. return inv:add_item("src", stack)
  402. end,
  403. can_insert = function(pos, node, stack, direction)
  404. local meta = minetest.get_meta(pos)
  405. local inv = meta:get_inventory()
  406. return inv:room_for_item("src", stack)
  407. end,
  408. input_inventory = "dst",
  409. connect_sides = {left = 1, right = 1, front = 1, back = 1, bottom = 1, top = 1}
  410. }
  411. end
  412. local not_in_creative_inventory
  413. if idx == 3 then
  414. tiles_data[1] = "gravelsieve_top.png"
  415. not_in_creative_inventory = 0
  416. else
  417. not_in_creative_inventory = 1
  418. end
  419. minetest.register_node(node_name..idx, {
  420. description = description,
  421. tiles = tiles_data,
  422. drawtype = "nodebox",
  423. drop = node_name,
  424. tube = tube_info, -- NEW
  425. node_box = {
  426. type = "fixed",
  427. fixed = nodebox_data,
  428. },
  429. selection_box = {
  430. type = "fixed",
  431. fixed = { -8/16, -8/16, -8/16, 8/16, 4/16, 8/16 },
  432. },
  433. on_timer = sieve_node_timer,
  434. on_construct = function(pos)
  435. local meta = minetest.get_meta(pos)
  436. meta:set_int("idx", idx) -- for the 4 sieve phases
  437. meta:set_int("gravel_cnt", 0) -- counter to switch between gravel and sieved gravel
  438. meta:set_string("node_name", node_name)
  439. meta:set_string("formspec", sieve_formspec)
  440. local inv = meta:get_inventory()
  441. inv:set_size('src', 1)
  442. inv:set_size('dst', 16)
  443. end,
  444. -- Pipeworks support
  445. after_dig_node = pipeworks_after_dig,
  446. after_place_node = function(pos, placer)
  447. local meta = minetest.get_meta(pos)
  448. meta:set_string("infotext", "Gravel Sieve")
  449. -- Pipeworks support
  450. pipeworks_after_place(pos, placer)
  451. end,
  452. on_metadata_inventory_move = function(pos)
  453. if automatic == 0 then
  454. local meta = minetest.get_meta(pos)
  455. swap_node(pos, meta, true)
  456. else
  457. minetest.get_node_timer(pos):start(STEP_DELAY)
  458. end
  459. end,
  460. on_metadata_inventory_take = function(pos)
  461. if automatic == 0 then
  462. local meta = minetest.get_meta(pos)
  463. local inv = meta:get_inventory()
  464. if inv:is_empty("src") then
  465. -- sieve should be empty
  466. meta:set_int("idx", 2)
  467. swap_node(pos, meta, false)
  468. meta:set_int("gravel_cnt", 0)
  469. end
  470. else
  471. minetest.get_node_timer(pos):start(STEP_DELAY)
  472. end
  473. end,
  474. on_metadata_inventory_put = function(pos)
  475. if automatic == 0 then
  476. local meta = minetest.get_meta(pos)
  477. swap_node(pos, meta, true)
  478. else
  479. minetest.get_node_timer(pos):start(STEP_DELAY)
  480. end
  481. end,
  482. on_punch = function(pos, node, puncher, pointed_thing)
  483. local meta = minetest.get_meta(pos)
  484. local inv = meta:get_inventory()
  485. if inv:is_empty("dst") and inv:is_empty("src") then
  486. minetest.node_punch(pos, node, puncher, pointed_thing)
  487. else
  488. sieve_node_timer(pos, 0)
  489. end
  490. end,
  491. on_dig = function(pos, node, puncher, pointed_thing)
  492. local meta = minetest.get_meta(pos)
  493. local inv = meta:get_inventory()
  494. if inv:is_empty("dst") and inv:is_empty("src") then
  495. minetest.node_dig(pos, node, puncher, pointed_thing)
  496. end
  497. end,
  498. allow_metadata_inventory_put = allow_metadata_inventory_put,
  499. allow_metadata_inventory_move = allow_metadata_inventory_move,
  500. allow_metadata_inventory_take = allow_metadata_inventory_take,
  501. paramtype = "light",
  502. sounds = default.node_sound_wood_defaults(),
  503. paramtype2 = "facedir",
  504. sunlight_propagates = true,
  505. is_ground_content = false,
  506. groups = {choppy=2, cracky=1, not_in_creative_inventory=not_in_creative_inventory, tubedevice = 1, tubedevice_receiver = 1},
  507. drop = node_name.."3",
  508. })
  509. end
  510. end
  511. ------------------------------------------------------------------------
  512. -- Optional adaption to tubelib
  513. ------------------------------------------------------------------------
  514. if minetest.global_exists("tubelib") then
  515. minetest.register_node("gravelsieve:sieve_defect", {
  516. tiles = {
  517. -- up, down, right, left, back, front
  518. "gravelsieve_top.png",
  519. "gravelsieve_gravel.png",
  520. "gravelsieve_auto_sieve.png^tubelib_defect.png",
  521. },
  522. drawtype = "nodebox",
  523. node_box = {
  524. type = "fixed",
  525. fixed = {
  526. { -8/16, -8/16, -8/16, 8/16, 4/16, -6/16 },
  527. { -8/16, -8/16, 6/16, 8/16, 4/16, 8/16 },
  528. { -8/16, -8/16, -8/16, -6/16, 4/16, 8/16 },
  529. { 6/16, -8/16, -8/16, 8/16, 4/16, 8/16 },
  530. { -6/16, -2/16, -6/16, 6/16, 2/16, 6/16 },
  531. },
  532. },
  533. selection_box = {
  534. type = "fixed",
  535. fixed = { -8/16, -8/16, -8/16, 8/16, 4/16, 8/16 },
  536. },
  537. on_construct = function(pos)
  538. local meta = minetest.get_meta(pos)
  539. meta:set_int("idx", 0) -- for the 4 sieve phases
  540. meta:set_int("gravel_cnt", 0) -- counter to switch between gravel and sieved gravel
  541. meta:set_string("node_name", "gravelsieve:auto_sieve")
  542. meta:set_string("formspec", sieve_formspec)
  543. local inv = meta:get_inventory()
  544. inv:set_size('src', 1)
  545. inv:set_size('dst', 16)
  546. end,
  547. after_place_node = function(pos, placer)
  548. local meta = minetest.get_meta(pos)
  549. meta:set_string("infotext", S("Gravel Sieve"))
  550. end,
  551. on_dig = function(pos, node, puncher, pointed_thing)
  552. local meta = minetest.get_meta(pos)
  553. local inv = meta:get_inventory()
  554. if inv:is_empty("dst") and inv:is_empty("src") then
  555. minetest.node_dig(pos, node, puncher, pointed_thing)
  556. end
  557. end,
  558. allow_metadata_inventory_put = allow_metadata_inventory_put,
  559. allow_metadata_inventory_move = allow_metadata_inventory_move,
  560. allow_metadata_inventory_take = allow_metadata_inventory_take,
  561. paramtype = "light",
  562. sounds = default.node_sound_wood_defaults(),
  563. paramtype2 = "facedir",
  564. sunlight_propagates = true,
  565. is_ground_content = false,
  566. groups = {choppy=2, cracky=1, not_in_creative_inventory=1},
  567. })
  568. tubelib.register_node("gravelsieve:auto_sieve3",
  569. {
  570. "gravelsieve:auto_sieve0",
  571. "gravelsieve:auto_sieve1",
  572. "gravelsieve:auto_sieve2",
  573. "gravelsieve:sieve_defect",
  574. },
  575. {
  576. on_pull_item = function(pos, side)
  577. local meta = minetest.get_meta(pos)
  578. return tubelib.get_item(meta, "dst")
  579. end,
  580. on_push_item = function(pos, side, item)
  581. minetest.get_node_timer(pos):start(STEP_DELAY)
  582. local meta = minetest.get_meta(pos)
  583. return tubelib.put_item(meta, "src", item)
  584. end,
  585. on_unpull_item = function(pos, side, item)
  586. local meta = minetest.get_meta(pos)
  587. return tubelib.put_item(meta, "dst", item)
  588. end,
  589. on_node_load = function(pos)
  590. minetest.get_node_timer(pos):start(STEP_DELAY)
  591. end,
  592. on_node_repair = function(pos)
  593. local meta = minetest.get_meta(pos)
  594. meta:set_int("tubelib_aging", 0)
  595. meta:set_int("idx", 2)
  596. meta:set_string("node_name", "gravelsieve:auto_sieve")
  597. local inv = meta:get_inventory()
  598. inv:set_size('src', 1)
  599. inv:set_size('dst', 16)
  600. swap_node(pos, meta, false)
  601. minetest.get_node_timer(pos):start(STEP_DELAY)
  602. return true
  603. end,
  604. })
  605. end
  606. minetest.register_node("gravelsieve:sieved_gravel", {
  607. description = S("Sieved Gravel"),
  608. tiles = {"default_gravel.png"},
  609. groups = {crumbly=2, falling_node=1, not_in_creative_inventory=1},
  610. sounds = default.node_sound_gravel_defaults(),
  611. })
  612. minetest.register_node("gravelsieve:compressed_gravel", {
  613. description = S("Compressed Gravel"),
  614. tiles = {"gravelsieve_compressed_gravel.png"},
  615. groups = {cracky=2, crumbly = 2, cracky = 2},
  616. sounds = default.node_sound_gravel_defaults(),
  617. })
  618. minetest.register_craft({
  619. output = "gravelsieve:sieve3",
  620. recipe = {
  621. {"group:wood", "", "group:wood"},
  622. {"group:wood", "default:steel_ingot", "group:wood"},
  623. {"group:wood", "", "group:wood"},
  624. },
  625. })
  626. minetest.register_craft({
  627. output = "gravelsieve:auto_sieve3",
  628. type = "shapeless",
  629. recipe = {
  630. "gravelsieve:sieve3", "default:mese_crystal", "default:mese_crystal",
  631. },
  632. })
  633. minetest.register_craft({
  634. output = "gravelsieve:compressed_gravel",
  635. recipe = {
  636. {"gravelsieve:sieved_gravel", "gravelsieve:sieved_gravel"},
  637. {"gravelsieve:sieved_gravel", "gravelsieve:sieved_gravel"},
  638. },
  639. })
  640. minetest.register_craft({
  641. type = "cooking",
  642. output = "default:cobble",
  643. recipe = "gravelsieve:compressed_gravel",
  644. cooktime = 10,
  645. })
  646. minetest.register_alias("gravelsieve:sieve", "gravelsieve:sieve3")
  647. minetest.register_alias("gravelsieve:auto_sieve", "gravelsieve:auto_sieve3")
  648. -- adaption to hopper
  649. if minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil then
  650. hopper:add_container({
  651. {"bottom", "gravelsieve:auto_sieve0", "src"},
  652. {"top", "gravelsieve:auto_sieve0", "dst"},
  653. {"side", "gravelsieve:auto_sieve0", "src"},
  654. {"bottom", "gravelsieve:auto_sieve1", "src"},
  655. {"top", "gravelsieve:auto_sieve1", "dst"},
  656. {"side", "gravelsieve:auto_sieve1", "src"},
  657. {"bottom", "gravelsieve:auto_sieve2", "src"},
  658. {"top", "gravelsieve:auto_sieve2", "dst"},
  659. {"side", "gravelsieve:auto_sieve2", "src"},
  660. {"bottom", "gravelsieve:auto_sieve3", "src"},
  661. {"top", "gravelsieve:auto_sieve3", "dst"},
  662. {"side", "gravelsieve:auto_sieve3", "src"},
  663. })
  664. end
  665. -- adaption to Circular Saw
  666. if minetest.get_modpath("moreblocks") then
  667. stairsplus:register_all("gravelsieve", "compressed_gravel", "gravelsieve:compressed_gravel", {
  668. description=S("Compressed Gravel"),
  669. groups={cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
  670. tiles = {"gravelsieve_compressed_gravel.png"},
  671. sounds = default.node_sound_stone_defaults(),
  672. })
  673. end