init.lua 6.4 KB

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