reedmace.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. -----------------------------------------------------------------------------------------------
  2. -- Grasses - Reedmace 0.1.1
  3. -----------------------------------------------------------------------------------------------
  4. -- by Mossmanikin
  5. -- textures & ideas partly by Neuromancer
  6. -- Contains code from: biome_lib
  7. -- Looked at code from: default, trees
  8. -----------------------------------------------------------------------------------------------
  9. -- NOTES (from wikipedia, some of this might get implemented)
  10. -- rhizomes are edible
  11. -- outer portion of young plants can be peeled and the heart can be eaten raw or boiled and eaten like asparagus
  12. -- leaf bases can be eaten raw or cooked
  13. -- sheath can be removed from the developing green flower spike, which can then be boiled and eaten like corn on the cob
  14. -- pollen can be collected and used as a flour supplement or thickener
  15. -- Typha stems and leaves can be used to make paper
  16. -- The seed hairs were used by some Native American groups as tinder for starting fires
  17. -- support for i18n
  18. local S = minetest.get_translator("dryplants")
  19. -----------------------------------------------------------------------------------------------
  20. -- REEDMACE SHAPES
  21. -----------------------------------------------------------------------------------------------
  22. abstract_dryplants.grow_reedmace = function(pos)
  23. local size = math.random(1,3)
  24. local spikes = math.random(1,3)
  25. local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z}
  26. local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z}
  27. local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z}
  28. if minetest.get_node(pos_01).name == "air" -- bug fix
  29. or minetest.get_node(pos_01).name == "dryplants:reedmace_sapling" then
  30. if minetest.get_node(pos_02).name ~= "air" then
  31. minetest.swap_node(pos_01, {name="dryplants:reedmace_top"})
  32. elseif minetest.get_node(pos_03).name ~= "air" then
  33. minetest.swap_node(pos_01, {name="dryplants:reedmace_height_2"})
  34. elseif size == 1 then
  35. minetest.swap_node(pos_01, {name="dryplants:reedmace_top"})
  36. elseif size == 2 then
  37. minetest.swap_node(pos_01, {name="dryplants:reedmace_height_2"})
  38. elseif size == 3 then
  39. if spikes == 1 then
  40. minetest.swap_node(pos_01, {name="dryplants:reedmace_height_3_spikes"})
  41. else
  42. minetest.swap_node(pos_01, {name="dryplants:reedmace_height_3"})
  43. end
  44. end
  45. end
  46. end
  47. abstract_dryplants.grow_reedmace_water = function(pos)
  48. local size = math.random(1,3)
  49. local spikes = math.random(1,3)
  50. local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z}
  51. local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z}
  52. local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z}
  53. local pos_04 = {x = pos.x, y = pos.y + 4, z = pos.z}
  54. minetest.add_entity(pos_01, "dryplants:reedmace_water_entity")
  55. if minetest.get_node(pos_02).name == "air" then -- bug fix
  56. if minetest.get_node(pos_03).name ~= "air" then
  57. minetest.swap_node(pos_02, {name="dryplants:reedmace_top"})
  58. elseif minetest.get_node(pos_04).name ~= "air" then
  59. minetest.swap_node(pos_02, {name="dryplants:reedmace_height_2"})
  60. elseif size == 1 then
  61. minetest.swap_node(pos_02, {name="dryplants:reedmace_top"})
  62. elseif size == 2 then
  63. minetest.swap_node(pos_02, {name="dryplants:reedmace_height_2"})
  64. elseif size == 3 then
  65. if spikes == 1 then
  66. minetest.swap_node(pos_02, {name="dryplants:reedmace_height_3_spikes"})
  67. else
  68. minetest.swap_node(pos_02, {name="dryplants:reedmace_height_3"})
  69. end
  70. end
  71. end
  72. end
  73. -----------------------------------------------------------------------------------------------
  74. -- REEDMACE SPIKES
  75. -----------------------------------------------------------------------------------------------
  76. minetest.register_node("dryplants:reedmace_spikes", {
  77. description = S("Reedmace"),
  78. drawtype = "plantlike",
  79. paramtype = "light",
  80. tiles = {"dryplants_reedmace_spikes.png"},
  81. inventory_image = "dryplants_reedmace_spikes.png",
  82. walkable = false,
  83. groups = {
  84. snappy=3,
  85. flammable=2,
  86. not_in_creative_inventory=1
  87. },
  88. drop = 'dryplants:reedmace_sapling',
  89. sounds = default.node_sound_leaves_defaults(),
  90. selection_box = {
  91. type = "fixed",
  92. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  93. },
  94. })
  95. -----------------------------------------------------------------------------------------------
  96. -- REEDMACE height: 1
  97. -----------------------------------------------------------------------------------------------
  98. minetest.register_node("dryplants:reedmace_top", {
  99. description = S("Reedmace, height: 1"),
  100. drawtype = "plantlike",
  101. paramtype = "light",
  102. tiles = {"dryplants_reedmace_top.png"},
  103. inventory_image = "dryplants_reedmace_top.png",
  104. walkable = false,
  105. groups = {
  106. snappy=3,
  107. flammable=2,
  108. not_in_creative_inventory=1
  109. },
  110. drop = 'dryplants:reedmace_sapling',
  111. sounds = default.node_sound_leaves_defaults(),
  112. selection_box = {
  113. type = "fixed",
  114. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  115. },
  116. })
  117. -----------------------------------------------------------------------------------------------
  118. -- REEDMACE height: 2
  119. -----------------------------------------------------------------------------------------------
  120. minetest.register_node("dryplants:reedmace_height_2", {
  121. description = S("Reedmace, height: 2"),
  122. drawtype = "plantlike",
  123. visual_scale = math.sqrt(8),
  124. paramtype = "light",
  125. tiles = {"dryplants_reedmace_height_2.png"},
  126. inventory_image = "dryplants_reedmace_top.png",
  127. walkable = false,
  128. groups = {
  129. snappy=3,
  130. flammable=2--,
  131. --not_in_creative_inventory=1
  132. },
  133. drop = 'dryplants:reedmace_sapling',
  134. sounds = default.node_sound_leaves_defaults(),
  135. selection_box = {
  136. type = "fixed",
  137. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  138. },
  139. })
  140. -----------------------------------------------------------------------------------------------
  141. -- REEDMACE height: 3
  142. -----------------------------------------------------------------------------------------------
  143. minetest.register_node("dryplants:reedmace_height_3", {
  144. description = S("Reedmace, height: 3"),
  145. drawtype = "plantlike",
  146. visual_scale = math.sqrt(8),
  147. paramtype = "light",
  148. tiles = {"dryplants_reedmace_height_3.png"},
  149. inventory_image = "dryplants_reedmace_top.png",
  150. walkable = false,
  151. groups = {
  152. snappy=3,
  153. flammable=2--,
  154. --not_in_creative_inventory=1
  155. },
  156. drop = 'dryplants:reedmace_sapling',
  157. sounds = default.node_sound_leaves_defaults(),
  158. selection_box = {
  159. type = "fixed",
  160. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  161. },
  162. })
  163. -----------------------------------------------------------------------------------------------
  164. -- REEDMACE height: 3 & Spikes
  165. -----------------------------------------------------------------------------------------------
  166. minetest.register_node("dryplants:reedmace_height_3_spikes", {
  167. description = S("Reedmace, height: 3 & Spikes"),
  168. drawtype = "plantlike",
  169. visual_scale = math.sqrt(8),
  170. paramtype = "light",
  171. tiles = {"dryplants_reedmace_height_3_spikes.png"},
  172. inventory_image = "dryplants_reedmace_top.png",
  173. walkable = false,
  174. groups = {
  175. snappy=3,
  176. flammable=2--,
  177. --not_in_creative_inventory=1
  178. },
  179. drop = 'dryplants:reedmace_sapling',
  180. sounds = default.node_sound_leaves_defaults(),
  181. selection_box = {
  182. type = "fixed",
  183. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  184. },
  185. })
  186. -----------------------------------------------------------------------------------------------
  187. -- REEDMACE STEMS
  188. -----------------------------------------------------------------------------------------------
  189. minetest.register_node("dryplants:reedmace", {
  190. description = S("Reedmace"),
  191. drawtype = "plantlike",
  192. paramtype = "light",
  193. tiles = {"dryplants_reedmace.png"},
  194. inventory_image = "dryplants_reedmace.png",
  195. walkable = false,
  196. groups = {
  197. snappy=3,
  198. flammable=2,
  199. not_in_creative_inventory=1
  200. },
  201. drop = 'dryplants:reedmace_sapling',
  202. sounds = default.node_sound_leaves_defaults(),
  203. selection_box = {
  204. type = "fixed",
  205. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  206. },
  207. after_destruct = function(pos,oldnode)
  208. local node = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
  209. if node.name == "dryplants:reedmace_top"
  210. or node.name == "dryplants:reedmace_spikes" then
  211. minetest.dig_node({x=pos.x,y=pos.y+1,z=pos.z})
  212. minetest.add_item(pos,"dryplants:reedmace_sapling")
  213. end
  214. end,
  215. })
  216. -----------------------------------------------------------------------------------------------
  217. -- REEDMACE BOTTOM
  218. -----------------------------------------------------------------------------------------------
  219. minetest.register_node("dryplants:reedmace_bottom", {
  220. description = S("Reedmace"),
  221. drawtype = "plantlike",
  222. paramtype = "light",
  223. tiles = {"dryplants_reedmace_bottom.png"},
  224. inventory_image = "dryplants_reedmace_bottom.png",
  225. walkable = false,
  226. groups = {
  227. snappy=3,
  228. flammable=2,
  229. not_in_creative_inventory=1
  230. },
  231. drop = 'dryplants:reedmace_sapling',
  232. sounds = default.node_sound_leaves_defaults(),
  233. selection_box = {
  234. type = "fixed",
  235. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  236. },
  237. after_destruct = function(pos,oldnode)
  238. local node = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
  239. if node.name == "dryplants:reedmace"
  240. or node.name == "dryplants:reedmace_top"
  241. or node.name == "dryplants:reedmace_spikes" then
  242. minetest.dig_node({x=pos.x,y=pos.y+1,z=pos.z})
  243. minetest.add_item(pos,"dryplants:reedmace_sapling")
  244. end
  245. end,
  246. })
  247. -----------------------------------------------------------------------------------------------
  248. -- REEDMACE "SAPLING" (the drop from the above)
  249. -----------------------------------------------------------------------------------------------
  250. minetest.register_node("dryplants:reedmace_sapling", {
  251. description = S("Reedmace"),
  252. drawtype = "plantlike",
  253. paramtype = "light",
  254. tiles = {"dryplants_reedmace_sapling.png"},
  255. inventory_image = "dryplants_reedmace_sapling.png",
  256. walkable = false,
  257. groups = {
  258. snappy=3,
  259. flammable=2,
  260. attached_node=1
  261. },
  262. sounds = default.node_sound_leaves_defaults(),
  263. selection_box = {
  264. type = "fixed",
  265. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  266. },
  267. })
  268. -- abm
  269. minetest.register_abm({
  270. nodenames = "dryplants:reedmace_sapling",
  271. interval = REEDMACE_GROWING_TIME,
  272. chance = 100/REEDMACE_GROWING_CHANCE,
  273. action = function(pos, node, _, _)
  274. if string.find(minetest.get_node({x = pos.x + 1, y = pos.y, z = pos.z }).name, "default:water")
  275. or string.find(minetest.get_node({x = pos.x, y = pos.y, z = pos.z + 1}).name, "default:water")
  276. or string.find(minetest.get_node({x = pos.x - 1, y = pos.y, z = pos.z }).name, "default:water")
  277. or string.find(minetest.get_node({x = pos.x, y = pos.y, z = pos.z - 1}).name, "default:water") then
  278. if minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name == "air" then
  279. abstract_dryplants.grow_reedmace_water({x = pos.x, y = pos.y - 1, z = pos.z})
  280. end
  281. minetest.swap_node({x=pos.x, y=pos.y, z=pos.z}, {name="default:water_source"})
  282. else
  283. abstract_dryplants.grow_reedmace({x = pos.x, y = pos.y - 1, z = pos.z})
  284. end
  285. end
  286. })
  287. -----------------------------------------------------------------------------------------------
  288. -- REEDMACE WATER (for entity)
  289. -----------------------------------------------------------------------------------------------
  290. minetest.register_node("dryplants:reedmace_water", {
  291. description = S("Reedmace"),
  292. drawtype = "plantlike",
  293. paramtype = "light",
  294. tiles = {"dryplants_reedmace_water.png"},
  295. inventory_image = "dryplants_reedmace_water.png",
  296. groups = {not_in_creative_inventory=1},
  297. selection_box = {
  298. type = "fixed",
  299. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  300. },
  301. })
  302. -----------------------------------------------------------------------------------------------
  303. -- REEDMACE WATER ENTITY
  304. -----------------------------------------------------------------------------------------------
  305. minetest.register_entity("dryplants:reedmace_water_entity",{
  306. visual = "mesh",
  307. mesh = "plantlike.obj",
  308. visual_size = {x=10, y=10},
  309. textures = {"dryplants_reedmace_water.png"},
  310. collisionbox = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3},
  311. on_punch = function(self, puncher)
  312. if puncher:is_player() and puncher:get_inventory() then
  313. if not minetest.setting_getbool("creative_mode") then
  314. puncher:get_inventory():add_item("main", "dryplants:reedmace_sapling")
  315. end
  316. self.object:remove()
  317. end
  318. end,
  319. })
  320. -----------------------------------------------------------------------------------------------
  321. -- SPAWN REEDMACE
  322. -----------------------------------------------------------------------------------------------
  323. --[[biome_lib:spawn_on_surfaces({
  324. spawn_delay = 1200,
  325. spawn_plants = {"dryplants:reedmace_sapling"},
  326. spawn_chance = 400,
  327. spawn_surfaces = {
  328. "default:dirt_with_grass",
  329. "default:desert_sand",
  330. "default:sand",
  331. "dryplants:grass_short",
  332. "stoneage:grass_with_silex"
  333. },
  334. seed_diff = 329,
  335. near_nodes = {"default:water_source"},
  336. near_nodes_size = 2,
  337. near_nodes_vertical = 1,
  338. near_nodes_count = 1,
  339. })]]
  340. -----------------------------------------------------------------------------------------------
  341. -- GENERATE REEDMACE
  342. -----------------------------------------------------------------------------------------------
  343. -- near water or swamp
  344. biome_lib:register_generate_plant({
  345. surface = {
  346. "default:dirt_with_grass",
  347. "default:desert_sand",
  348. "stoneage:grass_with_silex",
  349. "sumpf:peat",
  350. "sumpf:sumpf"
  351. },
  352. max_count = REEDMACE_NEAR_WATER_PER_MAPBLOCK,
  353. rarity = 101 - REEDMACE_NEAR_WATER_RARITY,
  354. --rarity = 60,
  355. min_elevation = 1, -- above sea level
  356. near_nodes = {"default:water_source","sumpf:dirtywater_source","sumpf:sumpf"},
  357. near_nodes_size = 2,
  358. near_nodes_vertical = 1,
  359. near_nodes_count = 1,
  360. plantlife_limit = -0.9,
  361. },
  362. abstract_dryplants.grow_reedmace
  363. )
  364. -- in water
  365. biome_lib:register_generate_plant({
  366. surface = {
  367. "default:dirt",
  368. "default:dirt_with_grass",
  369. --"default:desert_sand",
  370. --"stoneage:grass_with_silex",
  371. "stoneage:sand_with_silex",
  372. "sumpf:peat",
  373. "sumpf:sumpf"
  374. },
  375. max_count = REEDMACE_IN_WATER_PER_MAPBLOCK,
  376. rarity = 101 - REEDMACE_IN_WATER_RARITY,
  377. --rarity = 35,
  378. min_elevation = 0, -- a bit below sea level
  379. max_elevation = 0, -- ""
  380. near_nodes = {"default:water_source","sumpf:dirtywater_source"},
  381. near_nodes_size = 1,
  382. near_nodes_count = 1,
  383. plantlife_limit = -0.9,
  384. },
  385. abstract_dryplants.grow_reedmace_water
  386. )
  387. -- for oases & tropical beaches & tropical swamps
  388. biome_lib:register_generate_plant({
  389. surface = {
  390. "default:sand",
  391. "sumpf:sumpf"
  392. },
  393. max_count = REEDMACE_FOR_OASES_PER_MAPBLOCK,
  394. rarity = 101 - REEDMACE_FOR_OASES_RARITY,
  395. --rarity = 10,
  396. neighbors = {"default:water_source","sumpf:dirtywater_source","sumpf:sumpf"},
  397. ncount = 1,
  398. min_elevation = 1, -- above sea level
  399. near_nodes = {"default:desert_sand","sumpf:sumpf"},
  400. near_nodes_size = 2,
  401. near_nodes_vertical = 1,
  402. near_nodes_count = 1,
  403. plantlife_limit = -0.9,
  404. },
  405. abstract_dryplants.grow_reedmace
  406. )