init.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. -- Minetest 0.4 mod: default
  2. -- See README.txt for licensing and other information.
  3. -- Namespace for functions
  4. flowers = {}
  5. -- Map Generation
  6. dofile(minetest.get_modpath("flowers") .. "/mapgen.lua")
  7. --
  8. -- Flowers
  9. --
  10. -- Aliases for original flowers mod
  11. minetest.register_alias("flowers:flower_rose", "flowers:rose")
  12. minetest.register_alias("flowers:flower_tulip", "flowers:tulip")
  13. minetest.register_alias("flowers:flower_dandelion_yellow", "flowers:dandelion_yellow")
  14. minetest.register_alias("flowers:flower_geranium", "flowers:geranium")
  15. minetest.register_alias("flowers:flower_viola", "flowers:viola")
  16. minetest.register_alias("flowers:flower_dandelion_white", "flowers:dandelion_white")
  17. -- And now for the tulips mod
  18. minetest.register_alias("tulips:white_seeds", "flowers:dandelion_white")
  19. minetest.register_alias("tulips:white_sprout", "flowers:dandelion_white")
  20. minetest.register_alias("tulips:white", "flowers:dandelion_white")
  21. minetest.register_alias("tulips:grey_seeds", "flowers:dandelion_white")
  22. minetest.register_alias("tulips:grey_sprout", "flowers:dandelion_white")
  23. minetest.register_alias("tulips:grey", "flowers:dandelion_white")
  24. minetest.register_alias("tulips:black_seeds", "flowers:rose")
  25. minetest.register_alias("tulips:black_sprout", "flowers:rose")
  26. minetest.register_alias("tulips:black", "flowers:rose")
  27. minetest.register_alias("tulips:red_seeds", "flowers:rose")
  28. minetest.register_alias("tulips:red_sprout", "flowers:rose")
  29. minetest.register_alias("tulips:red", "flowers:rose")
  30. minetest.register_alias("tulips:yellow_seeds", "flowers:dandelion_yellow")
  31. minetest.register_alias("tulips:yellow_sprout", "flowers:dandelion_yellow")
  32. minetest.register_alias("tulips:yellow", "flowers:dandelion_yellow")
  33. minetest.register_alias("tulips:green_seeds", "flowers:tulip")
  34. minetest.register_alias("tulips:green_sprout", "flowers:tulip")
  35. minetest.register_alias("tulips:green", "flowers:tulip")
  36. minetest.register_alias("tulips:cyan_seeds", "flowers:geranium")
  37. minetest.register_alias("tulips:cyan_sprout", "flowers:geranium")
  38. minetest.register_alias("tulips:cyan", "flowers:geranium")
  39. minetest.register_alias("tulips:blue_seeds", "flowers:geranium")
  40. minetest.register_alias("tulips:blue_sprout", "flowers:geranium")
  41. minetest.register_alias("tulips:magenta_seeds", "flowers:viola")
  42. minetest.register_alias("tulips:magenta_sprout", "flowers:viola")
  43. minetest.register_alias("tulips:magenta", "flowers:viola")
  44. -- Flower registration
  45. local function add_simple_flower(name, desc, box, f_groups)
  46. -- Common flowers' groups
  47. f_groups.snappy = 3
  48. f_groups.flower = 1
  49. f_groups.flora = 1
  50. f_groups.attached_node = 1
  51. minetest.register_node("flowers:" .. name, {
  52. description = desc,
  53. drawtype = "plantlike",
  54. waving = 1,
  55. tiles = {"flowers_" .. name .. ".png"},
  56. inventory_image = "flowers_" .. name .. ".png",
  57. wield_image = "flowers_" .. name .. ".png",
  58. sunlight_propagates = true,
  59. paramtype = "light",
  60. drawtype = "nodebox",
  61. node_box = {
  62. type = "fixed",
  63. fixed = {
  64. {-0.5/5, -2.5/5, -0.5/5, 0.5/5, 0.5/5, 0.5/5},
  65. {-1.5/5, -0.5/5, -1.5/5, -0.5/5, 1.5/5, -0.5/5},
  66. {0.5/5, -0.5/5, -1.5/5, 1.5/5, 1.5/5, -0.5/5},
  67. {0.5/5, -0.5/5, 0.5/5, 1.5/5, 1.5/5, 1.5/5},
  68. {-1.5/5, -0.5/5, 0.5/5, -0.5/5, 1.5/5, 1.5/5},
  69. }
  70. },
  71. walkable = false,
  72. buildable_to = true,
  73. stack_max = 99,
  74. groups = f_groups,
  75. sounds = default.node_sound_leaves_defaults(),
  76. selection_box = {
  77. type = "fixed",
  78. fixed = box
  79. }
  80. })
  81. end
  82. flowers.datas = {
  83. {
  84. "rose",
  85. "Red Rose",
  86. {-2 / 16, -0.5, -2 / 16, 2 / 16, 5 / 16, 2 / 16},
  87. {color_red = 1, flammable = 1}
  88. },
  89. {
  90. "tulip",
  91. "Orange Tulip",
  92. {-2 / 16, -0.5, -2 / 16, 2 / 16, 3 / 16, 2 / 16},
  93. {color_orange = 1, flammable = 1}
  94. },
  95. {
  96. "dandelion_yellow",
  97. "Yellow Dandelion",
  98. {-4 / 16, -0.5, -4 / 16, 4 / 16, -2 / 16, 4 / 16},
  99. {color_yellow = 1, flammable = 1}
  100. },
  101. {
  102. "geranium",
  103. "Blue Geranium",
  104. {-2 / 16, -0.5, -2 / 16, 2 / 16, 2 / 16, 2 / 16},
  105. {color_blue = 1, flammable = 1}
  106. },
  107. {
  108. "viola",
  109. "Viola",
  110. {-5 / 16, -0.5, -5 / 16, 5 / 16, -1 / 16, 5 / 16},
  111. {color_violet = 1, flammable = 1}
  112. },
  113. {
  114. "dandelion_white",
  115. "White Dandelion",
  116. {-5 / 16, -0.5, -5 / 16, 5 / 16, -2 / 16, 5 / 16},
  117. {color_white = 1, flammable = 1}
  118. },
  119. }
  120. for _,item in pairs(flowers.datas) do
  121. add_simple_flower(unpack(item))
  122. end
  123. -- Flower spread
  124. -- Public function to enable override by mods
  125. function flowers.flower_spread(pos, node)
  126. pos.y = pos.y - 1
  127. local under = minetest.get_node(pos)
  128. pos.y = pos.y + 1
  129. -- Replace flora with dry shrub in desert sand and silver sand,
  130. -- as this is the only way to generate them.
  131. -- However, preserve grasses in sand dune biomes.
  132. if minetest.get_item_group(under.name, "sand") == 1 and
  133. under.name ~= "default:sand" then
  134. minetest.set_node(pos, {name = "default:dry_shrub"})
  135. return
  136. end
  137. if minetest.get_item_group(under.name, "soil") == 0 then
  138. return
  139. end
  140. local light = minetest.get_node_light(pos)
  141. if not light or light < 13 then
  142. return
  143. end
  144. local pos0 = vector.subtract(pos, 4)
  145. local pos1 = vector.add(pos, 4)
  146. if #minetest.find_nodes_in_area(pos0, pos1, "group:flora") > 3 then
  147. return
  148. end
  149. local soils = minetest.find_nodes_in_area_under_air(
  150. pos0, pos1, "group:soil")
  151. if #soils > 0 then
  152. local seedling = soils[math.random(#soils)]
  153. local seedling_above =
  154. {x = seedling.x, y = seedling.y + 1, z = seedling.z}
  155. light = minetest.get_node_light(seedling_above)
  156. if not light or light < 13 or
  157. -- Desert sand is in the soil group
  158. minetest.get_node(seedling).name == "default:desert_sand" then
  159. return
  160. end
  161. minetest.set_node(seedling_above, {name = node.name})
  162. end
  163. end
  164. minetest.register_abm({
  165. label = "Flower spread",
  166. nodenames = {"group:flora"},
  167. interval = 13,
  168. chance = 96,
  169. action = function(...)
  170. flowers.flower_spread(...)
  171. end,
  172. })
  173. --
  174. -- Mushrooms
  175. --
  176. minetest.register_node("flowers:mushroom_red", {
  177. description = "Red Mushroom",
  178. tiles = {"flowers_mushroom_red.png"},
  179. inventory_image = "flowers_mushroom_red.png",
  180. wield_image = "flowers_mushroom_red.png",
  181. drawtype = "plantlike",
  182. paramtype = "light",
  183. sunlight_propagates = true,
  184. walkable = false,
  185. buildable_to = true,
  186. groups = {snappy = 3, attached_node = 1, flammable = 1},
  187. sounds = default.node_sound_leaves_defaults(),
  188. on_use = minetest.item_eat(-5),
  189. selection_box = {
  190. type = "fixed",
  191. fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, -1 / 16, 4 / 16},
  192. }
  193. })
  194. minetest.register_node("flowers:mushroom_brown", {
  195. description = "Brown Mushroom",
  196. tiles = {"flowers_mushroom_brown.png"},
  197. inventory_image = "flowers_mushroom_brown.png",
  198. wield_image = "flowers_mushroom_brown.png",
  199. drawtype = "plantlike",
  200. paramtype = "light",
  201. sunlight_propagates = true,
  202. walkable = false,
  203. buildable_to = true,
  204. groups = {snappy = 3, attached_node = 1, flammable = 1},
  205. sounds = default.node_sound_leaves_defaults(),
  206. on_use = minetest.item_eat(1),
  207. selection_box = {
  208. type = "fixed",
  209. fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -2 / 16, 3 / 16},
  210. }
  211. })
  212. minetest.register_node("flowers:mushroom_jade", {
  213. description = "Jade Mushroom",
  214. tiles = {"flowers_mushroom_jade.png"},
  215. inventory_image = "flowers_mushroom_jade.png",
  216. wield_image = "flowers_mushroom_jade.png",
  217. drawtype = "plantlike",
  218. paramtype = "light",
  219. sunlight_propagates = true,
  220. walkable = false,
  221. buildable_to = true,
  222. groups = {snappy = 3, attached_node = 1, flammable = 1},
  223. sounds = default.node_sound_leaves_defaults(),
  224. on_use = minetest.item_eat(3),
  225. selection_box = {
  226. type = "fixed",
  227. fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -2 / 16, 3 / 16},
  228. }
  229. })
  230. minetest.register_node("flowers:mushroom_french", {
  231. description = "French Mushroom",
  232. tiles = {"flowers_mushroom_french.png"},
  233. inventory_image = "flowers_mushroom_french.png",
  234. wield_image = "flowers_mushroom_french.png",
  235. drawtype = "plantlike",
  236. paramtype = "light",
  237. sunlight_propagates = true,
  238. walkable = false,
  239. buildable_to = true,
  240. groups = {snappy = 3, attached_node = 1, flammable = 1},
  241. sounds = default.node_sound_leaves_defaults(),
  242. on_use = minetest.item_eat(1),
  243. selection_box = {
  244. type = "fixed",
  245. fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -2 / 16, 3 / 16},
  246. }
  247. })
  248. minetest.register_node("flowers:mushroom_lemon", {
  249. description = "Lemon Mushroom",
  250. tiles = {"flowers_mushroom_lemon.png"},
  251. inventory_image = "flowers_mushroom_lemon.png",
  252. wield_image = "flowers_mushroom_lemon.png",
  253. drawtype = "plantlike",
  254. paramtype = "light",
  255. sunlight_propagates = true,
  256. walkable = false,
  257. buildable_to = true,
  258. groups = {snappy = 3, attached_node = 1, flammable = 1},
  259. sounds = default.node_sound_leaves_defaults(),
  260. on_use = minetest.item_eat(0),
  261. selection_box = {
  262. type = "fixed",
  263. fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -2 / 16, 3 / 16},
  264. }
  265. })
  266. minetest.register_node("flowers:mushroom_sleepy", {
  267. description = "Sleepy Mushroom",
  268. tiles = {"flowers_mushroom_sleepy.png"},
  269. inventory_image = "flowers_mushroom_sleepy.png",
  270. wield_image = "flowers_mushroom_sleepy.png",
  271. drawtype = "plantlike",
  272. paramtype = "light",
  273. sunlight_propagates = true,
  274. walkable = false,
  275. buildable_to = true,
  276. groups = {snappy = 3, attached_node = 1, flammable = 1},
  277. sounds = default.node_sound_leaves_defaults(),
  278. on_use = minetest.item_eat(-18),
  279. selection_box = {
  280. type = "fixed",
  281. fixed = {-3 / 16, -0.5, -3 / 16, 3 / 16, -2 / 16, 3 / 16},
  282. }
  283. })
  284. -- Mushroom spread and death
  285. minetest.register_abm({
  286. label = "Mushroom spread",
  287. nodenames = {"flowers:mushroom_brown", "flowers:mushroom_red", "flowers:mushroom_jade",
  288. "flowers:mushroom_french", "flowers:mushroom_lemon", "flowers:mushroom_sleepy"},
  289. interval = 11,
  290. chance = 50,
  291. action = function(pos, node)
  292. if minetest.get_node_light(pos, nil) == 15 then
  293. minetest.remove_node(pos)
  294. return
  295. end
  296. local random = {
  297. x = pos.x + math.random(-2, 2),
  298. y = pos.y + math.random(-1, 1),
  299. z = pos.z + math.random(-2, 2)
  300. }
  301. local random_node = minetest.get_node_or_nil(random)
  302. if not random_node or random_node.name ~= "air" then
  303. return
  304. end
  305. local node_under = minetest.get_node_or_nil({x = random.x,
  306. y = random.y - 1, z = random.z})
  307. if not node_under then
  308. return
  309. end
  310. if (minetest.get_item_group(node_under.name, "soil") ~= 0 or
  311. minetest.get_item_group(node_under.name, "tree") ~= 0) and
  312. minetest.get_node_light(pos, 0.5) <= 3 and
  313. minetest.get_node_light(random, 0.5) <= 3 then
  314. minetest.set_node(random, {name = node.name})
  315. end
  316. end
  317. })
  318. -- These old mushroom related nodes can be simplified now
  319. minetest.register_alias("flowers:mushroom_spores_brown", "flowers:mushroom_brown")
  320. minetest.register_alias("flowers:mushroom_spores_red", "flowers:mushroom_red")
  321. minetest.register_alias("flowers:mushroom_fertile_brown", "flowers:mushroom_brown")
  322. minetest.register_alias("flowers:mushroom_fertile_red", "flowers:mushroom_red")
  323. minetest.register_alias("mushroom:brown_natural", "flowers:mushroom_brown")
  324. minetest.register_alias("mushroom:red_natural", "flowers:mushroom_red")
  325. --
  326. -- Waterlily
  327. --
  328. minetest.register_node("flowers:waterlily", {
  329. description = "Waterlily",
  330. drawtype = "nodebox",
  331. paramtype = "light",
  332. paramtype2 = "facedir",
  333. tiles = {"flowers_waterlily.png", "flowers_waterlily_bottom.png"},
  334. inventory_image = "flowers_waterlily.png",
  335. wield_image = "flowers_waterlily.png",
  336. liquids_pointable = true,
  337. walkable = false,
  338. buildable_to = true,
  339. sunlight_propagates = true,
  340. floodable = true,
  341. groups = {snappy = 3, flower = 1, flammable = 1},
  342. sounds = default.node_sound_leaves_defaults(),
  343. node_placement_prediction = "",
  344. node_box = {
  345. type = "fixed",
  346. fixed = {-0.5, -31 / 64, -0.5, 0.5, -15 / 32, 0.5}
  347. },
  348. selection_box = {
  349. type = "fixed",
  350. fixed = {-7 / 16, -0.5, -7 / 16, 7 / 16, -15 / 32, 7 / 16}
  351. },
  352. on_place = function(itemstack, placer, pointed_thing)
  353. local pos = pointed_thing.above
  354. local node = minetest.get_node(pointed_thing.under).name
  355. local def = minetest.registered_nodes[node]
  356. local player_name = placer:get_player_name()
  357. if def and def.liquidtype == "source" and
  358. minetest.get_item_group(node, "water") > 0 then
  359. if not minetest.is_protected(pos, player_name) then
  360. minetest.set_node(pos, {name = "flowers:waterlily",
  361. param2 = math.random(0, 3)})
  362. if not (creative and creative.is_enabled_for
  363. and creative.is_enabled_for(player_name)) then
  364. itemstack:take_item()
  365. end
  366. else
  367. minetest.chat_send_player(player_name, "Node is protected")
  368. minetest.record_protection_violation(pos, player_name)
  369. end
  370. end
  371. return itemstack
  372. end
  373. })