init.lua 5.8 KB

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