init.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. vines = {
  2. name = 'vines',
  3. recipes = {}
  4. }
  5. local enable_roots = minetest.settings:get_bool("vines_enable_roots")
  6. -- support for i18n
  7. local S = minetest.get_translator("vines")
  8. -- ITEMS
  9. minetest.register_craftitem("vines:vines", {
  10. description = S("Vines"),
  11. inventory_image = "vines_item.png",
  12. groups = {vines = 1, flammable = 2}
  13. })
  14. -- FUNCTIONS
  15. local function dig_down(pos, node, digger)
  16. if digger == nil then return end
  17. local np = {x = pos.x, y = pos.y - 1, z = pos.z}
  18. local nn = minetest.get_node(np)
  19. if minetest.get_item_group(nn.name, "vines") > 0 then
  20. minetest.node_dig(np, nn, digger)
  21. end
  22. end
  23. vines.register_vine = function( name, defs, biome )
  24. local groups = {vines = 1, snappy = 3, flammable = 2, attached_node = 1}
  25. local vine_name_end = 'vines:' .. name .. '_end'
  26. local vine_name_middle = 'vines:' .. name .. '_middle'
  27. local vine_image_end = "vines_" .. name .. "_end.png"
  28. local vine_image_middle = "vines_" .. name .. "_middle.png"
  29. local drop_node = vine_name_end
  30. biome.spawn_plants = {vine_name_end}
  31. local vine_group = 'group:' .. name .. '_vines'
  32. biome.spawn_surfaces[#biome.spawn_surfaces + 1] = vine_group
  33. local selection_box = {type = "wallmounted",}
  34. local drawtype = 'signlike'
  35. -- different properties for bottom and side vines.
  36. if not biome.spawn_on_side then
  37. selection_box = {
  38. type = "fixed", fixed = { -0.4, -1/2, -0.4, 0.4, 1/2, 0.4 }
  39. }
  40. drawtype = 'plantlike'
  41. end
  42. minetest.register_node(vine_name_end, {
  43. description = defs.description,
  44. walkable = false,
  45. climbable = true,
  46. wield_image = vine_image_end,
  47. drop = "vines:vines",
  48. sunlight_propagates = true,
  49. paramtype = "light",
  50. paramtype2 = "wallmounted",
  51. buildable_to = false,
  52. tiles = {vine_image_end},
  53. drawtype = drawtype,
  54. inventory_image = vine_image_end,
  55. groups = groups,
  56. sounds = default.node_sound_leaves_defaults(),
  57. selection_box = selection_box,
  58. on_construct = function(pos)
  59. local timer = minetest.get_node_timer(pos)
  60. timer:start(math.random(5, 10))
  61. end,
  62. on_timer = function(pos)
  63. local node = minetest.get_node(pos)
  64. local bottom = {x = pos.x, y = pos.y - 1, z = pos.z}
  65. local bottom_node = minetest.get_node( bottom )
  66. if bottom_node.name == "air" then
  67. if not math.random(defs.average_length) == 1 then
  68. minetest.set_node(pos, {
  69. name = vine_name_middle, param2 = node.param2})
  70. minetest.set_node(bottom, {
  71. name = node.name, param2 = node.param2})
  72. local timer = minetest.get_node_timer(bottom_node)
  73. timer:start(math.random(5, 10))
  74. end
  75. end
  76. end,
  77. after_dig_node = function(pos, node, metadata, digger)
  78. dig_down(pos, node, digger)
  79. end,
  80. })
  81. minetest.register_node( vine_name_middle, {
  82. description = S("Matured") .. " " .. defs.description,
  83. walkable = false,
  84. climbable = true,
  85. drop = "vines:vines",
  86. sunlight_propagates = true,
  87. paramtype = "light",
  88. paramtype2 = "wallmounted",
  89. buildable_to = false,
  90. tiles = {vine_image_middle},
  91. wield_image = vine_image_middle,
  92. drawtype = drawtype,
  93. inventory_image = vine_image_middle,
  94. groups = groups,
  95. sounds = default.node_sound_leaves_defaults(),
  96. selection_box = selection_box,
  97. after_dig_node = function(pos, node, metadata, digger)
  98. dig_down(pos, node, digger)
  99. end,
  100. })
  101. biome_lib:spawn_on_surfaces(biome)
  102. end
  103. -- ALIASES
  104. -- used to remove the old vine nodes and give room for the new.
  105. minetest.register_alias( 'vines:root', 'air' )
  106. minetest.register_alias( 'vines:root_rotten', 'air' )
  107. minetest.register_alias( 'vines:vine', 'air' )
  108. minetest.register_alias( 'vines:vine_rotten', 'air' )
  109. minetest.register_alias( 'vines:side', 'air' )
  110. minetest.register_alias( 'vines:side_rotten', 'air' )
  111. minetest.register_alias( 'vines:jungle', 'air' )
  112. minetest.register_alias( 'vines:jungle_rotten', 'air' )
  113. minetest.register_alias( 'vines:willow', 'air' )
  114. minetest.register_alias( 'vines:willow_rotten', 'air' )
  115. -- CRAFTS
  116. minetest.register_craft({
  117. output = 'vines:rope_block',
  118. recipe = {
  119. {'group:vines', 'group:vines', 'group:vines'},
  120. {'group:vines', 'group:wood', 'group:vines'},
  121. {'group:vines', 'group:vines', 'group:vines'},
  122. }
  123. })
  124. if minetest.get_modpath("moreblocks") then
  125. minetest.register_craft({
  126. output = 'vines:rope_block',
  127. recipe = {
  128. {'moreblocks:rope', 'moreblocks:rope', 'moreblocks:rope'},
  129. {'moreblocks:rope', 'group:wood', 'moreblocks:rope'},
  130. {'moreblocks:rope', 'moreblocks:rope', 'moreblocks:rope'},
  131. }
  132. })
  133. end
  134. minetest.register_craft({
  135. output = 'vines:shears',
  136. recipe = {
  137. {'', 'default:steel_ingot', ''},
  138. {'group:stick', 'group:wood', 'default:steel_ingot'},
  139. {'', '', 'group:stick'}
  140. }
  141. })
  142. -- NODES
  143. minetest.register_node("vines:rope_block", {
  144. description = S("Rope"),
  145. sunlight_propagates = true,
  146. paramtype = "light",
  147. tiles = {
  148. "default_wood.png^vines_rope.png",
  149. "default_wood.png^vines_rope.png",
  150. "default_wood.png",
  151. "default_wood.png",
  152. "default_wood.png^vines_rope.png",
  153. "default_wood.png^vines_rope.png",
  154. },
  155. groups = {flammable = 2, choppy = 2, oddly_breakable_by_hand = 1},
  156. after_place_node = function(pos)
  157. local p = {x = pos.x, y = pos.y - 1, z = pos.z}
  158. local n = minetest.get_node(p)
  159. if n.name == "air" then
  160. minetest.add_node(p, {name = "vines:rope_end"})
  161. end
  162. end,
  163. after_dig_node = function(pos, node, digger)
  164. local p = {x = pos.x, y = pos.y - 1, z = pos.z}
  165. local n = minetest.get_node(p)
  166. while n.name == 'vines:rope' or n.name == 'vines:rope_end' do
  167. minetest.remove_node(p)
  168. p = {x = p.x, y = p.y - 1, z = p.z}
  169. n = minetest.get_node(p)
  170. end
  171. end
  172. })
  173. minetest.register_node("vines:rope", {
  174. description = S("Rope"),
  175. walkable = false,
  176. climbable = true,
  177. sunlight_propagates = true,
  178. paramtype = "light",
  179. drop = {},
  180. tiles = {"vines_rope.png"},
  181. drawtype = "plantlike",
  182. groups = {flammable = 2, not_in_creative_inventory = 1},
  183. sounds = default.node_sound_leaves_defaults(),
  184. selection_box = {
  185. type = "fixed",
  186. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  187. },
  188. })
  189. minetest.register_node("vines:rope_end", {
  190. description = S("Rope"),
  191. walkable = false,
  192. climbable = true,
  193. sunlight_propagates = true,
  194. paramtype = "light",
  195. drop = {},
  196. tiles = {"vines_rope_end.png"},
  197. drawtype = "plantlike",
  198. groups = {flammable = 2, not_in_creative_inventory = 1},
  199. sounds = default.node_sound_leaves_defaults(),
  200. after_place_node = function(pos)
  201. local yesh = {x = pos.x, y = pos.y - 1, z = pos.z}
  202. minetest.add_node(yesh, {name = "vines:rope"})
  203. end,
  204. selection_box = {
  205. type = "fixed",
  206. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  207. },
  208. on_construct = function(pos)
  209. local timer = minetest.get_node_timer(pos)
  210. timer:start(1)
  211. end,
  212. on_timer = function( pos, elapsed )
  213. local p = {x = pos.x, y = pos.y - 1, z = pos.z}
  214. local n = minetest.get_node(p)
  215. if n.name == "air" then
  216. minetest.set_node(pos, {name = "vines:rope"})
  217. minetest.add_node(p, {name = "vines:rope_end"})
  218. else
  219. local timer = minetest.get_node_timer(pos)
  220. timer:start(1)
  221. end
  222. end
  223. })
  224. -- SHEARS
  225. minetest.register_tool("vines:shears", {
  226. description = S("Shears"),
  227. inventory_image = "vines_shears.png",
  228. wield_image = "vines_shears.png",
  229. stack_max = 1,
  230. max_drop_level = 3,
  231. tool_capabilities = {
  232. full_punch_interval = 1.0,
  233. max_drop_level = 1,
  234. groupcaps = {
  235. snappy = {times = {[3] = 0.2}, uses = 60, maxlevel = 3},
  236. }
  237. },
  238. })
  239. -- VINES
  240. local spawn_root_surfaces = {}
  241. if enable_roots ~= false then
  242. spawn_root_surfaces = {
  243. "default:dirt_with_grass",
  244. "default:dirt"
  245. }
  246. end
  247. vines.register_vine('root',
  248. {description = S("Roots"), average_length = 9}, {
  249. choose_random_wall = true,
  250. avoid_nodes = {"vines:root_middle"},
  251. avoid_radius = 5,
  252. spawn_delay = 500,
  253. spawn_chance = 10,
  254. spawn_surfaces = spawn_root_surfaces,
  255. spawn_on_bottom = true,
  256. plantlife_limit = -0.6,
  257. humidity_min = 0.4,
  258. })
  259. vines.register_vine('vine',
  260. {description = S("Vines"), average_length = 5}, {
  261. choose_random_wall = true,
  262. avoid_nodes = {"group:vines"},
  263. avoid_radius = 5,
  264. spawn_delay = 500,
  265. spawn_chance = 100,
  266. spawn_surfaces = {
  267. -- "default:leaves",
  268. "default:jungleleaves",
  269. "moretrees:jungletree_leaves_red",
  270. "moretrees:jungletree_leaves_yellow",
  271. "moretrees:jungletree_leaves_green"
  272. },
  273. spawn_on_bottom = true,
  274. plantlife_limit = -0.9,
  275. humidity_min = 0.7,
  276. })
  277. vines.register_vine('side',
  278. {description = S("Vines"), average_length = 6}, {
  279. choose_random_wall = true,
  280. avoid_nodes = {"group:vines", "default:apple"},
  281. avoid_radius = 3,
  282. spawn_delay = 500,
  283. spawn_chance = 100,
  284. spawn_surfaces = {
  285. -- "default:leaves",
  286. "default:jungleleaves",
  287. "moretrees:jungletree_leaves_red",
  288. "moretrees:jungletree_leaves_yellow",
  289. "moretrees:jungletree_leaves_green"
  290. },
  291. spawn_on_side = true,
  292. plantlife_limit = -0.9,
  293. humidity_min = 0.4,
  294. })
  295. vines.register_vine("jungle",
  296. {description = S("Jungle Vines"), average_length = 7}, {
  297. choose_random_wall = true,
  298. neighbors = {
  299. "default:jungleleaves",
  300. "moretrees:jungletree_leaves_red",
  301. "moretrees:jungletree_leaves_yellow",
  302. "moretrees:jungletree_leaves_green"
  303. },
  304. avoid_nodes = {
  305. "vines:jungle_middle",
  306. "vines:jungle_end",
  307. },
  308. avoid_radius = 5,
  309. spawn_delay = 500,
  310. spawn_chance = 100,
  311. spawn_surfaces = {
  312. "default:jungletree",
  313. "moretrees:jungletree_trunk"
  314. },
  315. spawn_on_side = true,
  316. plantlife_limit = -0.9,
  317. humidity_min = 0.2,
  318. })
  319. vines.register_vine( 'willow',
  320. {description = S("Willow Vines"), average_length = 9}, {
  321. choose_random_wall = true,
  322. avoid_nodes = {"vines:willow_middle"},
  323. avoid_radius = 5,
  324. near_nodes = {'default:water_source'},
  325. near_nodes_size = 1,
  326. near_nodes_count = 1,
  327. near_nodes_vertical = 7,
  328. plantlife_limit = -0.8,
  329. spawn_chance = 10,
  330. spawn_delay = 500,
  331. spawn_on_side = true,
  332. spawn_surfaces = {"moretrees:willow_leaves"},
  333. humidity_min = 0.5
  334. })
  335. print("[Vines] Loaded!")