nodes.lua 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. local nodebox_hoedsoil = {
  2. {0, 0, 0, 16, 15, 16},
  3. {0, 15, 2, 16, 15.5, 7},
  4. {0, 15, 9, 16, 15.5, 14},
  5. }
  6. for k, v in ipairs(nodebox_hoedsoil) do
  7. for m, n in ipairs(v) do
  8. local p = nodebox_hoedsoil[k][m]
  9. p = p / 16
  10. p = p - 0.5
  11. nodebox_hoedsoil[k][m] = p
  12. end
  13. end
  14. minetest.override_item("default:dirt", {
  15. soil = {
  16. base = "default:dirt",
  17. dry = "farming:soil",
  18. wet = "farming:soil_wet"
  19. }
  20. })
  21. minetest.override_item("default:dirt_with_grass", {
  22. soil = {
  23. base = "default:dirt_with_grass",
  24. dry = "farming:soil",
  25. wet = "farming:soil_wet"
  26. }
  27. })
  28. minetest.override_item("moregrass:darkgrass", {
  29. soil = {
  30. base = "moregrass:darkgrass",
  31. dry = "farming:soil",
  32. wet = "farming:soil_wet"
  33. }
  34. })
  35. minetest.override_item("default:dirt_with_dry_grass", {
  36. soil = {
  37. base = "default:dirt_with_dry_grass",
  38. dry = "farming:soil",
  39. wet = "farming:soil_wet"
  40. }
  41. })
  42. minetest.register_node("farming:soil", {
  43. paramtype = "light",
  44. drawtype = "nodebox",
  45. node_box = {
  46. type = "fixed",
  47. fixed = nodebox_hoedsoil,
  48. },
  49. selection_box = {
  50. type = "fixed",
  51. fixed = {
  52. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  53. },
  54. },
  55. description = "Soil",
  56. movement_speed_multiplier = default.SLOW_SPEED,
  57. tiles = {"default_dirt.png^farming_soil.png", "default_dirt.png"},
  58. drop = "default:dirt",
  59. groups = utility.dig_groups("dirt", {not_in_creative_inventory = 1, dirt_type = 1, non_raw_dirt_type = 1, non_sterile_dirt_type = 1, hoed_dirt_type = 1, soil = 2, grassland = 1, falling_node = 1, field = 1, want_notify = 1}),
  60. sounds = default.node_sound_dirt_defaults(),
  61. soil = {
  62. base = "default:dirt",
  63. dry = "farming:soil",
  64. wet = "farming:soil_wet"
  65. },
  66. on_notify = function(pos, other)
  67. if other.y == pos.y+1 then
  68. farming.notify_soil_single(pos)
  69. end
  70. end,
  71. on_timer = function(...)
  72. farming.on_soil_notify(...)
  73. end,
  74. on_finish_collapse = function(pos, node)
  75. minetest.swap_node(pos, {name="default:dirt"})
  76. end,
  77. })
  78. minetest.register_node("farming:soil_wet", {
  79. paramtype = "light",
  80. drawtype = "nodebox",
  81. node_box = {
  82. type = "fixed",
  83. fixed = nodebox_hoedsoil,
  84. },
  85. selection_box = {
  86. type = "fixed",
  87. fixed = {
  88. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  89. },
  90. },
  91. description = "Wet Soil",
  92. movement_speed_multiplier = default.SLOW_SPEED,
  93. tiles = {"default_dirt.png^farming_soil_wet.png", "default_dirt.png^farming_soil_wet_side.png"},
  94. drop = "default:dirt",
  95. groups = utility.dig_groups("dirt", {not_in_creative_inventory = 1, dirt_type = 1, non_raw_dirt_type = 1, non_sterile_dirt_type = 1, hoed_dirt_type = 1, soil = 3, wet = 1, grassland = 1, falling_node = 1, field = 1, want_notify = 1}),
  96. sounds = default.node_sound_dirt_defaults(),
  97. soil = {
  98. base = "default:dirt",
  99. dry = "farming:soil",
  100. wet = "farming:soil_wet"
  101. },
  102. on_notify = function(pos, other)
  103. if other.y == pos.y+1 then
  104. farming.notify_soil_single(pos)
  105. end
  106. end,
  107. on_timer = function(...)
  108. farming.on_soil_notify(...)
  109. end,
  110. on_finish_collapse = function(pos, node)
  111. minetest.swap_node(pos, {name="default:dirt"})
  112. end,
  113. })
  114. minetest.override_item("default:desert_sand", {
  115. soil = {
  116. base = "default:desert_sand",
  117. dry = "farming:desert_sand_soil",
  118. wet = "farming:desert_sand_soil_wet"
  119. }
  120. })
  121. minetest.register_node("farming:desert_sand_soil", {
  122. paramtype = "light",
  123. drawtype = "nodebox",
  124. node_box = {
  125. type = "fixed",
  126. fixed = nodebox_hoedsoil,
  127. },
  128. selection_box = {
  129. type = "fixed",
  130. fixed = {
  131. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  132. },
  133. },
  134. description = "Desert Sand Soil",
  135. movement_speed_multiplier = default.SLOW_SPEED,
  136. drop = "default:desert_sand",
  137. tiles = {"farming_desert_sand_soil.png", "default_desert_sand.png"},
  138. groups = utility.dig_groups("sand", {not_in_creative_inventory = 1, falling_node = 1, sand = 1, soil = 2, desert = 1, field = 1, fall_damage_add_percent=-20, want_notify = 1}),
  139. sounds = default.node_sound_sand_defaults(),
  140. soil = {
  141. base = "default:desert_sand",
  142. dry = "farming:desert_sand_soil",
  143. wet = "farming:desert_sand_soil_wet"
  144. },
  145. on_notify = function(pos, other)
  146. if other.y == pos.y+1 then
  147. farming.notify_soil_single(pos)
  148. end
  149. end,
  150. on_timer = function(...)
  151. farming.on_soil_notify(...)
  152. end,
  153. on_finish_collapse = function(pos, node)
  154. minetest.swap_node(pos, {name="default:desert_sand"})
  155. end,
  156. })
  157. minetest.register_node("farming:desert_sand_soil_wet", {
  158. paramtype = "light",
  159. drawtype = "nodebox",
  160. node_box = {
  161. type = "fixed",
  162. fixed = nodebox_hoedsoil,
  163. },
  164. selection_box = {
  165. type = "fixed",
  166. fixed = {
  167. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  168. },
  169. },
  170. description = "Wet Desert Sand Soil",
  171. movement_speed_multiplier = default.SLOW_SPEED,
  172. drop = "default:desert_sand",
  173. tiles = {"farming_desert_sand_soil_wet.png", "farming_desert_sand_soil_wet_side.png"},
  174. groups = utility.dig_groups("sand", {falling_node = 1, sand = 1, not_in_creative_inventory = 1, soil = 3, wet = 1, desert = 1, field = 1, fall_damage_add_percent=-20, want_notify = 1}),
  175. sounds = default.node_sound_sand_defaults(),
  176. soil = {
  177. base = "default:desert_sand",
  178. dry = "farming:desert_sand_soil",
  179. wet = "farming:desert_sand_soil_wet"
  180. },
  181. on_notify = function(pos, other)
  182. if other.y == pos.y+1 then
  183. farming.notify_soil_single(pos)
  184. end
  185. end,
  186. on_timer = function(...)
  187. farming.on_soil_notify(...)
  188. end,
  189. on_finish_collapse = function(pos, node)
  190. minetest.swap_node(pos, {name="default:desert_sand"})
  191. end,
  192. })
  193. minetest.register_node("farming:straw", {
  194. description = "Straw\n\nA soft material to fall on.",
  195. tiles = {"farming_straw.png"},
  196. is_ground_content = false,
  197. groups = utility.dig_groups("straw", {flammable=4, fall_damage_add_percent=-30, falling_node=1}),
  198. sounds = default.node_sound_leaves_defaults(),
  199. movement_speed_multiplier = default.SLOW_SPEED,
  200. })
  201. minetest.register_node("farming:straw_weathered", {
  202. description = "Weathered Straw\n\nA soft material to fall on.",
  203. tiles = {"farming_straw_weathered.png"},
  204. is_ground_content = false,
  205. groups = utility.dig_groups("straw", {flammable=5, fall_damage_add_percent=-30, falling_node=1}),
  206. sounds = default.node_sound_leaves_defaults(),
  207. movement_speed_multiplier = default.SLOW_SPEED,
  208. })
  209. -- Translate timer callback to update callback.
  210. function farming.on_soil_notify(pos, elapsed)
  211. local node = minetest.get_node(pos)
  212. farming.on_update_soil(pos, node)
  213. end
  214. -- Called whenever soil is notified to update via timer.
  215. -- This was originally an ABM function.
  216. function farming.on_update_soil(pos, node)
  217. local n_def = minetest.reg_ns_nodes[node.name] or nil
  218. local wet = n_def.soil.wet or nil
  219. local base = n_def.soil.base or nil
  220. local dry = n_def.soil.dry or nil
  221. if not n_def or not n_def.soil or not wet or not base or not dry then
  222. return
  223. end
  224. pos.y = pos.y + 1
  225. local nn = minetest.get_node_or_nil(pos)
  226. if not nn or not nn.name then
  227. return
  228. end
  229. local nn_def = minetest.reg_ns_nodes[nn.name] or nil
  230. pos.y = pos.y - 1
  231. if not nn_def or (nn_def.walkable and minetest.get_item_group(nn.name, "plant") == 0) then
  232. minetest.add_node(pos, {name = base})
  233. return
  234. end
  235. -- check if there is water nearby
  236. local wet_lvl = minetest.get_item_group(node.name, "wet")
  237. -- Distance needed for water increased from 3 to 4 meters, to compensate for dirt being a falling node.
  238. -- [MustTest]
  239. local radius = 4
  240. if minetest.find_node_near(pos, radius, {"group:water"}) then
  241. -- if it is dry soil and not base node, turn it into wet soil
  242. if wet_lvl == 0 then
  243. minetest.add_node(pos, {name = wet})
  244. farming.notify_soil_single(pos)
  245. end
  246. else
  247. -- only turn back if there are no unloaded blocks (and therefore
  248. -- possible water sources) nearby
  249. if not minetest.find_node_near(pos, radius, {"ignore"}) then
  250. -- turn it back into base if it is already dry
  251. if wet_lvl == 0 then
  252. -- only turn it back if there is no plant/seed on top of it
  253. if minetest.get_item_group(nn.name, "plant") == 0 and minetest.get_item_group(nn.name, "seed") == 0 then
  254. minetest.add_node(pos, {name = base})
  255. -- Base dirt doesn't need soil notifications.
  256. end
  257. -- if its wet turn it back into dry soil
  258. elseif wet_lvl == 1 then
  259. minetest.add_node(pos, {name = dry})
  260. farming.notify_soil_single(pos)
  261. end
  262. end
  263. end
  264. end
  265. for i = 1, 5 do
  266. minetest.override_item("default:grass_"..i, {
  267. drop = {
  268. max_items = 1,
  269. items = {
  270. {items = {'farming:seed_wheat'}, rarity = 5},
  271. },
  272. },
  273. shears_drop = "default:grass_dummy",
  274. })
  275. end
  276. for i = 1, 5 do
  277. minetest.override_item("default:grass_"..i.."_hanging", {
  278. drop = {
  279. max_items = 1,
  280. items = {
  281. {items = {'farming:seed_wheat'}, rarity = 5},
  282. },
  283. },
  284. shears_drop = "default:grass_dummy",
  285. })
  286. end
  287. for i = 1, 5 do
  288. minetest.override_item("default:dry_grass2_"..i, {
  289. drop = {
  290. max_items = 1,
  291. items = {
  292. {items = {'potatoes:seed'}, rarity = 5},
  293. },
  294. },
  295. })
  296. end
  297. for i = 1, 5 do
  298. minetest.override_item("default:dry_grass2_"..i.."_hanging", {
  299. drop = {
  300. max_items = 1,
  301. items = {
  302. {items = {'potatoes:seed'}, rarity = 5},
  303. },
  304. },
  305. })
  306. end
  307. minetest.override_item("default:junglegrass", {
  308. drop = {
  309. max_items = 1,
  310. items = {
  311. {items = {'farming:seed_cotton'}, rarity = 8},
  312. {items = {'default:stick'}},
  313. },
  314. },
  315. shears_drop = "default:junglegrass",
  316. })