init.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. bonemeal = bonemeal or {}
  2. bonemeal.modpath = minetest.get_modpath("bonemeal")
  3. -- Localize for performance.
  4. local math_random = math.random
  5. function bonemeal.do_dirtspread(pos)
  6. local above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
  7. if above.name ~= "air" then
  8. return
  9. end
  10. local dirt = minetest.find_node_near(pos, 2, {
  11. "default:dirt_with_grass",
  12. "default:dirt_with_dry_grass",
  13. "moregrass:darkgrass",
  14. })
  15. if dirt then
  16. local node = minetest.get_node(dirt)
  17. minetest.add_node(pos, {name=node.name})
  18. end
  19. end
  20. function bonemeal.on_use(itemstack, user, pt)
  21. if not user or not user:is_player() then
  22. return
  23. end
  24. if pt.type == "node" then
  25. local pos = pt.under
  26. if minetest.is_protected(pos, user:get_player_name()) then
  27. return
  28. end
  29. minetest.punch_node(pos)
  30. local node = minetest.get_node(pos)
  31. local def = minetest.registered_items[node.name]
  32. local take = false
  33. if def then
  34. if def.next_plant and def.on_timer then
  35. local timer = minetest.get_node_timer(pos)
  36. if timer:is_started() then
  37. local timeout = timer:get_timeout()
  38. local elapsed = timer:get_elapsed()
  39. local remain = (timeout - elapsed)
  40. if remain > 0 then
  41. -- Plant growtime is reduced by 2 thirds.
  42. local newtime = (remain / 3)
  43. timer:set(newtime, elapsed)
  44. end
  45. end
  46. take = true
  47. elseif def.groups and def.groups.flora and def.groups.flora > 0 then
  48. if math_random(1, 3) == 1 then
  49. flowers.flower_spread(pos, node)
  50. end
  51. take = true
  52. elseif node.name == "flowers:mushroom_brown" or
  53. node.name == "flowers:mushroom_red" or
  54. node.name == "cavestuff:mycena" or
  55. node.name == "cavestuff:fungus" then
  56. if math_random(1, 3) == 1 then
  57. flowers.mushroom_spread(pos, node)
  58. end
  59. take = true
  60. elseif node.name == "default:cactus" then
  61. if math_random(1, 3) == 1 then
  62. cactus.grow(pos, node)
  63. end
  64. take = true
  65. elseif node.name == "default:papyrus" then
  66. if math_random(1, 3) == 1 then
  67. papyrus.grow(pos, node)
  68. end
  69. take = true
  70. elseif node.name == "default:tvine" or
  71. node.name == "default:tvine_alt" or
  72. node.name == "default:tvine_top" or
  73. node.name == "default:tvine_top_alt" then
  74. if math_random(1, 3) == 1 then
  75. tvine.grow(pos, node)
  76. end
  77. take = true
  78. elseif def.groups and def.groups.sapling and def.groups.sapling > 0 and def.on_timer then
  79. local timer = minetest.get_node_timer(pos)
  80. if timer:is_started() then
  81. local timeout = timer:get_timeout()
  82. local elapsed = timer:get_elapsed()
  83. local remain = (timeout - elapsed)
  84. if remain > 0 then
  85. local newtime = (remain / 3)*2
  86. timer:set(newtime, elapsed)
  87. end
  88. end
  89. take = true
  90. elseif node.name == "nethervine:vine" then
  91. if math_random(1, 3) == 1 then
  92. nethervine.grow(pos, node)
  93. end
  94. take = true
  95. elseif node.name == "default:dirt" then
  96. if math_random(1, 3) == 1 then
  97. bonemeal.do_dirtspread(pos)
  98. end
  99. take = true
  100. elseif node.name == "default:dirt_with_dry_grass" then
  101. if math_random(1, 2) == 1 then
  102. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  103. local anode = minetest.get_node(above)
  104. if anode.name == "air" then
  105. if not minetest.is_protected(above, user:get_player_name()) then
  106. if math_random(1, 4) > 1 then
  107. minetest.add_node(above, {name="default:dry_grass_" .. math_random(1, 5), param2=2})
  108. else
  109. minetest.add_node(above, {name="default:dry_shrub"})
  110. end
  111. end
  112. end
  113. end
  114. take = true
  115. elseif node.name == "default:dirt_with_grass" then
  116. if math_random(1, 2) == 1 then
  117. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  118. local anode = minetest.get_node(above)
  119. if anode.name == "air" then
  120. if not minetest.is_protected(above, user:get_player_name()) then
  121. if math_random(1, 2) == 1 then
  122. minetest.add_node(above, {name="default:grass_" .. math_random(1, 5), param2=2})
  123. else
  124. minetest.add_node(above, {name="default:coarsegrass", param2=2})
  125. end
  126. end
  127. end
  128. end
  129. take = true
  130. elseif node.name == "moregrass:darkgrass" then
  131. if math_random(1, 2) == 1 then
  132. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  133. local anode = minetest.get_node(above)
  134. if anode.name == "air" then
  135. if not minetest.is_protected(above, user:get_player_name()) then
  136. if math_random(1, 2) == 1 then
  137. minetest.add_node(above, {name="default:junglegrass", param2=2})
  138. else
  139. minetest.add_node(above, {name="default:coarsegrass", param2=2})
  140. end
  141. end
  142. end
  143. end
  144. take = true
  145. elseif string.find(node.name, "^nether:grass_%d$") then
  146. if math_random(1, 2) == 1 then
  147. if not minetest.is_protected(pos, user:get_player_name()) then
  148. nethervine.flora_spread(pos, minetest.get_node(pos))
  149. end
  150. end
  151. take = true
  152. end
  153. end
  154. if take then
  155. itemstack:take_item()
  156. end
  157. return itemstack
  158. end
  159. end
  160. if not bonemeal.run_once then
  161. -- bone item
  162. minetest.register_craftitem("bonemeal:bone", {
  163. description = "Bone",
  164. inventory_image = "bone_bone.png",
  165. })
  166. minetest.register_craft({
  167. output = "bonemeal:bone 16",
  168. recipe = {
  169. {'bones:bones_type2', 'bones:bones_type2'},
  170. {'bones:bones_type2', 'bones:bones_type2'},
  171. },
  172. })
  173. minetest.register_craft({
  174. output = "bones:bones_type2",
  175. recipe = {
  176. {'bonemeal:bone', 'bonemeal:bone'},
  177. {'bonemeal:bone', 'bonemeal:bone'},
  178. },
  179. })
  180. -- bonemeal recipe
  181. minetest.register_craft({
  182. output = 'bonemeal:meal 3',
  183. recipe = {{'bonemeal:bone'}},
  184. })
  185. minetest.register_craft({
  186. type = "anvil",
  187. output = 'bonemeal:meal 5',
  188. recipe = 'bonemeal:bone',
  189. })
  190. minetest.register_craft({
  191. type = "grinding",
  192. output = 'bonemeal:meal 6',
  193. recipe = 'bonemeal:bone',
  194. time = 4,
  195. })
  196. -- bonemeal item
  197. minetest.register_craftitem("bonemeal:meal", {
  198. description = "Bone Meal",
  199. inventory_image = "bone_bonemeal.png",
  200. liquids_pointable = false,
  201. on_use = function(...)
  202. return bonemeal.on_use(...)
  203. end,
  204. })
  205. local c = "bonemeal:core"
  206. local f = bonemeal.modpath .. "/init.lua"
  207. reload.register_file(c, f, false)
  208. bonemeal.run_once = true
  209. end