init.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. farming = {}
  2. function place_seed(itemstack, placer, pointed_thing, plantname, param2)
  3. local pt = pointed_thing
  4. if not pt then
  5. return
  6. end
  7. if pt.type ~= "node" then
  8. return
  9. end
  10. local under = minetest.get_node(pt.under)
  11. local above = minetest.get_node(pt.above)
  12. if not minetest.registered_nodes[under.name] then
  13. return
  14. end
  15. if not minetest.registered_nodes[above.name] then
  16. return
  17. end
  18. if pt.above.y ~= pt.under.y+1 then
  19. return
  20. end
  21. if not minetest.registered_nodes[above.name].buildable_to then
  22. return
  23. end
  24. if minetest.get_item_group(under.name, "soil") <= 1 then
  25. return
  26. end
  27. minetest.add_node(pt.above, {name=plantname, param2=param2})
  28. if not minetest.setting_getbool("creative_mode") then
  29. itemstack:take_item()
  30. end
  31. return itemstack
  32. end
  33. function place_spore(itemstack, placer, pointed_thing, plantname, p2)
  34. local pt = pointed_thing
  35. if not pt then
  36. return
  37. end
  38. if pt.type ~= "node" then
  39. return
  40. end
  41. local under = minetest.get_node(pt.under)
  42. local above = minetest.get_node(pt.above)
  43. if not minetest.registered_nodes[under.name] then
  44. return
  45. end
  46. if not minetest.registered_nodes[above.name] then
  47. return
  48. end
  49. if pt.above.y ~= pt.under.y+1 then
  50. return
  51. end
  52. if not minetest.registered_nodes[above.name].buildable_to then
  53. return
  54. end
  55. if minetest.get_item_group(under.name, "fungi") <= 1 then
  56. return
  57. end
  58. minetest.add_node(pt.above, {name=plantname, param2 = p2})
  59. if not minetest.setting_getbool("creative_mode") then
  60. itemstack:take_item()
  61. end
  62. return itemstack
  63. end
  64. function farming.hoe_on_use(itemstack, user, pointed_thing, uses)
  65. local pt = pointed_thing
  66. -- check if pointing at a node
  67. if not pt then
  68. return
  69. end
  70. if pt.type ~= "node" then
  71. return
  72. end
  73. local under = minetest.get_node(pt.under)
  74. local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
  75. local above = minetest.get_node(p)
  76. -- return if any of the nodes is not registered
  77. if not minetest.registered_nodes[under.name] then
  78. return
  79. end
  80. if not minetest.registered_nodes[above.name] then
  81. return
  82. end
  83. -- check if the node above the pointed thing is air
  84. if above.name ~= "air" then
  85. return
  86. end
  87. -- check if pointing at dirt
  88. if minetest.get_item_group(under.name, "soil") ~= 1 then
  89. return
  90. end
  91. -- turn the node into soil, wear out item and play sound
  92. minetest.set_node(pt.under, {name="farming:soil"})
  93. minetest.sound_play("default_dig_crumbly", {
  94. pos = pt.under,
  95. gain = 0.5,
  96. })
  97. itemstack:add_wear(65535/(uses-1))
  98. return itemstack
  99. end
  100. function farming:add_plant(full_grown, names, interval, chance, p2)
  101. minetest.register_abm({
  102. nodenames = names,
  103. interval = interval,
  104. chance = chance,
  105. action = function(pos, node)
  106. pos.y = pos.y-1
  107. if minetest.get_node(pos).name ~= "farming:soil_wet" then
  108. return
  109. end
  110. pos.y = pos.y+1
  111. local light_level = minetest.get_node_light(pos)
  112. if not light_level then
  113. return
  114. end
  115. local c = math.ceil(2 * (light_level - 13) ^ 2 + 1)
  116. if light_level > 7 and (math.random(1, c) == 1 or light_level >= 13) then
  117. local step
  118. for i,name in ipairs(names) do
  119. if name == node.name then
  120. step = i
  121. break
  122. end
  123. end
  124. if not step then
  125. return
  126. end
  127. local new_node = {name=names[step+1], param2=p2}
  128. if new_node.name == nil then
  129. new_node.name = full_grown
  130. end
  131. minetest.set_node(pos, new_node)
  132. end
  133. end
  134. })
  135. end
  136. -- ========= CORN =========
  137. dofile(minetest.get_modpath("lottfarming").."/corn.lua")
  138. -- ========= BERRIES =========
  139. dofile(minetest.get_modpath("lottfarming").."/berries.lua")
  140. -- ========= CABBAGE =========
  141. dofile(minetest.get_modpath("lottfarming").."/cabbage.lua")
  142. -- ========= ATHELAS =========
  143. dofile(minetest.get_modpath("lottfarming").."/athelas.lua")
  144. -- ========= POTATO =========
  145. dofile(minetest.get_modpath("lottfarming").."/potato.lua")
  146. -- ========= TOMATO =========
  147. dofile(minetest.get_modpath("lottfarming").."/tomatoes.lua")
  148. -- ========= TURNIP =========
  149. dofile(minetest.get_modpath("lottfarming").."/turnips.lua")
  150. -- ========= PIPEWEED =========
  151. dofile(minetest.get_modpath("lottfarming").."/pipeweed.lua")
  152. -- ========= MELON =========
  153. dofile(minetest.get_modpath("lottfarming").."/melon.lua")
  154. -- ========= BARLEY =========
  155. dofile(minetest.get_modpath("lottfarming").."/barley.lua")
  156. -- ========= CRAFTS =========
  157. dofile(minetest.get_modpath("lottfarming").."/crafting.lua")
  158. -- ========= BROWN MUSHROOM =========
  159. dofile(minetest.get_modpath("lottfarming").."/brown.lua")
  160. -- ========= RED MUSHROOM =========
  161. dofile(minetest.get_modpath("lottfarming").."/red.lua")
  162. -- ========= BLUE MUSHROOM =========
  163. dofile(minetest.get_modpath("lottfarming").."/blue.lua")
  164. -- ========= GREEN MUSHROOM =========
  165. dofile(minetest.get_modpath("lottfarming").."/green.lua")
  166. -- ========= WHITE MUSHROOM =========
  167. dofile(minetest.get_modpath("lottfarming").."/white.lua")
  168. -- ========= ORC FOOD =========
  169. dofile(minetest.get_modpath("lottfarming").."/orc_food.lua")