init.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 def.groups and def.groups.sapling and def.groups.sapling > 0 and def.on_timer then
  71. local timer = minetest.get_node_timer(pos)
  72. if timer:is_started() then
  73. local timeout = timer:get_timeout()
  74. local elapsed = timer:get_elapsed()
  75. local remain = (timeout - elapsed)
  76. if remain > 0 then
  77. local newtime = (remain / 3)*2
  78. timer:set(newtime, elapsed)
  79. end
  80. end
  81. take = true
  82. elseif node.name == "nethervine:vine" then
  83. if math_random(1, 3) == 1 then
  84. nethervine.grow(pos, node)
  85. end
  86. take = true
  87. elseif node.name == "default:dirt" then
  88. if math_random(1, 3) == 1 then
  89. bonemeal.do_dirtspread(pos)
  90. end
  91. take = true
  92. elseif node.name == "default:dirt_with_dry_grass" then
  93. if math_random(1, 2) == 1 then
  94. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  95. local anode = minetest.get_node(above)
  96. if anode.name == "air" then
  97. if not minetest.is_protected(above, user:get_player_name()) then
  98. if math_random(1, 4) > 1 then
  99. minetest.add_node(above, {name="default:dry_grass_" .. math_random(1, 5), param2=2})
  100. else
  101. minetest.add_node(above, {name="default:dry_shrub"})
  102. end
  103. end
  104. end
  105. end
  106. take = true
  107. elseif node.name == "default:dirt_with_grass" then
  108. if math_random(1, 2) == 1 then
  109. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  110. local anode = minetest.get_node(above)
  111. if anode.name == "air" then
  112. if not minetest.is_protected(above, user:get_player_name()) then
  113. if math_random(1, 2) == 1 then
  114. minetest.add_node(above, {name="default:grass_" .. math_random(1, 5), param2=2})
  115. else
  116. minetest.add_node(above, {name="default:coarsegrass", param2=2})
  117. end
  118. end
  119. end
  120. end
  121. take = true
  122. elseif node.name == "moregrass:darkgrass" then
  123. if math_random(1, 2) == 1 then
  124. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  125. local anode = minetest.get_node(above)
  126. if anode.name == "air" then
  127. if not minetest.is_protected(above, user:get_player_name()) then
  128. if math_random(1, 2) == 1 then
  129. minetest.add_node(above, {name="default:junglegrass", param2=2})
  130. else
  131. minetest.add_node(above, {name="default:coarsegrass", param2=2})
  132. end
  133. end
  134. end
  135. end
  136. take = true
  137. elseif string.find(node.name, "^nether:grass_%d$") then
  138. if math_random(1, 2) == 1 then
  139. if not minetest.is_protected(pos, user:get_player_name()) then
  140. nethervine.flora_spread(pos, minetest.get_node(pos))
  141. end
  142. end
  143. take = true
  144. end
  145. end
  146. if take then
  147. itemstack:take_item()
  148. end
  149. return itemstack
  150. end
  151. end
  152. if not bonemeal.run_once then
  153. -- bone item
  154. minetest.register_craftitem("bonemeal:bone", {
  155. description = "Bone",
  156. inventory_image = "bone_bone.png",
  157. })
  158. minetest.register_craft({
  159. output = "bonemeal:bone 16",
  160. recipe = {
  161. {'bones:bones_type2', 'bones:bones_type2'},
  162. {'bones:bones_type2', 'bones:bones_type2'},
  163. },
  164. })
  165. minetest.register_craft({
  166. output = "bones:bones_type2",
  167. recipe = {
  168. {'bonemeal:bone', 'bonemeal:bone'},
  169. {'bonemeal:bone', 'bonemeal:bone'},
  170. },
  171. })
  172. -- bonemeal recipe
  173. minetest.register_craft({
  174. output = 'bonemeal:meal 4',
  175. recipe = {{'bonemeal:bone'}},
  176. })
  177. minetest.register_craft({
  178. type = "grinding",
  179. output = 'bonemeal:meal 6',
  180. recipe = 'bonemeal:bone',
  181. time = 4,
  182. })
  183. -- bonemeal item
  184. minetest.register_craftitem("bonemeal:meal", {
  185. description = "Bone Meal",
  186. inventory_image = "bone_bonemeal.png",
  187. liquids_pointable = false,
  188. on_use = function(...)
  189. return bonemeal.on_use(...)
  190. end,
  191. })
  192. local c = "bonemeal:core"
  193. local f = bonemeal.modpath .. "/init.lua"
  194. reload.register_file(c, f, false)
  195. bonemeal.run_once = true
  196. end