init.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. farming = {}
  2. function farming:add_plant(full_grown, names, interval, chance)
  3. minetest.register_abm({
  4. nodenames = names,
  5. interval = interval,
  6. chance = chance,
  7. action = function(pos, node)
  8. pos.y = pos.y-1
  9. if minetest.env:get_node(pos).name ~= "farming:soil_wet" then
  10. return
  11. end
  12. pos.y = pos.y+1
  13. if not minetest.env:get_node_light(pos) then
  14. return
  15. end
  16. if minetest.env:get_node_light(pos) < 8 then
  17. return
  18. end
  19. local step = nil
  20. for i,name in ipairs(names) do
  21. if name == node.name then
  22. step = i
  23. break
  24. end
  25. end
  26. if step == nil then
  27. return
  28. end
  29. local new_node = {name=names[step+1]}
  30. if new_node.name == nil then
  31. new_node.name = full_grown
  32. end
  33. minetest.env:set_node(pos, new_node)
  34. end
  35. } )
  36. end
  37. function farming:generate_tree(pos, trunk, leaves, underground, replacements)
  38. pos.y = pos.y-1
  39. local nodename = minetest.env:get_node(pos).name
  40. local ret = true
  41. for _,name in ipairs(underground) do
  42. if nodename == name then
  43. ret = false
  44. break
  45. end
  46. end
  47. pos.y = pos.y+1
  48. if not minetest.env:get_node_light(pos) then
  49. return
  50. end
  51. if ret or minetest.env:get_node_light(pos) < 8 then
  52. return
  53. end
  54. node = {name = ""}
  55. for dy=1,4 do
  56. pos.y = pos.y+dy
  57. if minetest.env:get_node(pos).name ~= "air" then
  58. return
  59. end
  60. pos.y = pos.y-dy
  61. end
  62. node.name = trunk
  63. for dy=0,4 do
  64. pos.y = pos.y+dy
  65. minetest.env:set_node(pos, node)
  66. pos.y = pos.y-dy
  67. end
  68. if not replacements then
  69. replacements = {}
  70. end
  71. node.name = leaves
  72. pos.y = pos.y+3
  73. for dx=-2,2 do
  74. for dz=-2,2 do
  75. for dy=0,3 do
  76. pos.x = pos.x+dx
  77. pos.y = pos.y+dy
  78. pos.z = pos.z+dz
  79. if dx == 0 and dz == 0 and dy==3 then
  80. if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
  81. minetest.env:set_node(pos, node)
  82. for name,rarity in pairs(replacements) do
  83. if math.random(1, rarity) == 1 then
  84. minetest.env:set_node(pos, {name=name})
  85. end
  86. end
  87. end
  88. elseif dx == 0 and dz == 0 and dy==4 then
  89. if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
  90. minetest.env:set_node(pos, node)
  91. for name,rarity in pairs(replacements) do
  92. if math.random(1, rarity) == 1 then
  93. minetest.env:set_node(pos, {name=name})
  94. end
  95. end
  96. end
  97. elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
  98. if minetest.env:get_node(pos).name == "air" then
  99. minetest.env:set_node(pos, node)
  100. for name,rarity in pairs(replacements) do
  101. if math.random(1, rarity) == 1 then
  102. minetest.env:set_node(pos, {name=name})
  103. end
  104. end
  105. end
  106. else
  107. if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
  108. if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
  109. minetest.env:set_node(pos, node)
  110. for name,rarity in pairs(replacements) do
  111. if math.random(1, rarity) == 1 then
  112. minetest.env:set_node(pos, {name=name})
  113. end
  114. end
  115. end
  116. end
  117. end
  118. pos.x = pos.x-dx
  119. pos.y = pos.y-dy
  120. pos.z = pos.z-dz
  121. end
  122. end
  123. end
  124. end
  125. farming.seeds = {
  126. ["farming:wheat_seed"]=20,
  127. ["farming:cotton_seed"]=30,
  128. ["farming:pumpkin_seed"]=60,
  129. }
  130. -- ========= ALIASES FOR FARMING MOD BY SAPIER =========
  131. -- hoes
  132. minetest.register_alias("farming:wood_hoe", "farming:hoe_wood")
  133. minetest.register_alias("farming:cobble_hoe", "farming:hoe_stone")
  134. minetest.register_alias("farming:steel_hoe", "farming:hoe_steel")
  135. minetest.register_alias("farming:mese_hoe", "farming:hoe_steel")
  136. -- wheat -> wheat
  137. minetest.register_alias("farming:wheat_node", "farming:wheat")
  138. --minetest.register_alias("farming:wheat", "farming_wheat_harvested") cant do this
  139. minetest.register_alias("farming:wheat_straw", "farming:wheat")
  140. minetest.register_alias("farming:seed_wheat", "farming:wheat_seed")
  141. for lvl = 1, 6, 1 do
  142. minetest.register_entity(":farming:wheat_lvl"..lvl, {
  143. on_activate = function(self, staticdata)
  144. minetest.env:set_node(self.object:getpos(), {name="farming:wheat_1"})
  145. end
  146. })
  147. end
  148. -- rye -> wheat
  149. minetest.register_alias("farming:rhy_node", "farming:wheat")
  150. minetest.register_alias("farming:rhy", "farming:wheat_harvested")
  151. minetest.register_alias("farming:rhy_straw", "farming:wheat")
  152. minetest.register_alias("farming:seed_rhy", "farming:wheat_seed")
  153. for lvl = 1, 6, 1 do
  154. minetest.register_entity(":farming:rhy_lvl"..lvl, {
  155. on_activate = function(self, staticdata)
  156. minetest.env:set_node(self.object:getpos(), {name="farming:wheat_1"})
  157. end
  158. })
  159. end
  160. -- corn -> wheat
  161. minetest.register_alias("farming:corn_node", "farming:wheat")
  162. minetest.register_alias("farming:corn", "farming:wheat_harvested")
  163. minetest.register_alias("farming:corn_straw", "farming:wheat")
  164. minetest.register_alias("farming:seed_corn", "farming:wheat_seed")
  165. for lvl = 1, 6, 1 do
  166. minetest.register_entity(":farming:corn_lvl"..lvl, {
  167. on_activate = function(self, staticdata)
  168. minetest.env:set_node(self.object:getpos(), {name="farming:wheat_1"})
  169. end
  170. })
  171. end
  172. -- ========= SOIL =========
  173. dofile(minetest.get_modpath("farming").."/soil.lua")
  174. -- ========= HOES =========
  175. dofile(minetest.get_modpath("farming").."/hoes.lua")
  176. -- ========= CORN =========
  177. dofile(minetest.get_modpath("farming").."/wheat.lua")
  178. -- ========= COTTON =========
  179. dofile(minetest.get_modpath("farming").."/cotton.lua")
  180. -- ========= PUMPKIN =========
  181. --dofile(minetest.get_modpath("farming").."/pumpkin.lua")
  182. -- ========= WEED =========
  183. dofile(minetest.get_modpath("farming").."/weed.lua")
  184. -- ========= PAPYRUS =========
  185. dofile(minetest.get_modpath("farming").."/papyrus.lua")
  186. -- ========= CACTUS =========
  187. dofile(minetest.get_modpath("farming").."/cactus.lua")
  188. if minetest.setting_get("log_mods") then
  189. minetest.log("action", "farming loaded")
  190. end