farming.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. function mese_crystals.get_grow_time()
  2. return mese_crystals.growtime + math.random(1, 30)
  3. --return mese_crystals.growtime
  4. end
  5. function mese_crystals.get_long_grow_time()
  6. return mese_crystals.longgrowtime + math.random(1, 30)
  7. --return mese_crystals.longgrowtime
  8. end
  9. local check_lava = function(pos)
  10. local name = minetest.get_node(pos).name
  11. if minetest.get_item_group(name, "lava") > 0 then
  12. return 1
  13. else
  14. return 0
  15. end
  16. end
  17. local grow_mese_crystal_ore = function(pos, node)
  18. -- Crystals grown outside the nether should grow much slower.
  19. local nether = true
  20. if pos.y > -30770 then
  21. nether = false
  22. end
  23. local pos1 = {x = pos.x, y = pos.y, z = pos.z}
  24. pos1.y = pos1.y - 1
  25. local name = minetest.get_node(pos1).name
  26. if name ~= "default:obsidian" then
  27. -- Cannot grow, do not restart timer.
  28. return
  29. end
  30. local lava_count = 0
  31. pos1.z = pos.z - 1
  32. lava_count = lava_count + check_lava(pos1)
  33. pos1.z = pos.z + 1
  34. lava_count = lava_count + check_lava(pos1)
  35. pos1.z = pos.z
  36. pos1.x = pos.x - 1
  37. lava_count = lava_count + check_lava(pos1)
  38. pos1.x = pos.x + 1
  39. lava_count = lava_count + check_lava(pos1)
  40. pos1.x = pos.x
  41. pos1.y = pos1.y -1
  42. lava_count = lava_count + check_lava(pos1)
  43. -- Not enough lava!
  44. if lava_count < 2 then
  45. minetest.get_node_timer(pos):start(mese_crystals.get_long_grow_time())
  46. return
  47. end
  48. local keepgrowing = false
  49. if node.name == "mese_crystals:mese_crystal_ore3" then
  50. node.name = "mese_crystals:mese_crystal_ore4"
  51. minetest.swap_node(pos, node)
  52. -- Last stage, does not need node timer.
  53. elseif node.name == "mese_crystals:mese_crystal_ore2" then
  54. node.name = "mese_crystals:mese_crystal_ore3"
  55. minetest.swap_node(pos, node)
  56. keepgrowing = true
  57. elseif node.name == "mese_crystals:mese_crystal_ore1" then
  58. node.name = "mese_crystals:mese_crystal_ore2"
  59. minetest.swap_node(pos, node)
  60. keepgrowing = true
  61. end
  62. if keepgrowing then
  63. if nether then
  64. minetest.get_node_timer(pos):start(mese_crystals.get_grow_time())
  65. else
  66. minetest.get_node_timer(pos):start(mese_crystals.get_long_grow_time())
  67. end
  68. end
  69. end
  70. function mese_crystals.on_timer(pos, elapsed)
  71. local node = minetest.get_node(pos)
  72. return grow_mese_crystal_ore(pos, node)
  73. end