Vanessa's plantlife modpack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.2KB

  1. vines.register_vine = function( name, defs, biome )
  2. local biome = biome
  3. local groups = { vines=1, snappy=3, flammable=2 }
  4. local vine_name_end = 'vines:'..name..'_end'
  5. local vine_name_middle = 'vines:'..name..'_middle'
  6. local vine_image_end = "vines_"..name.."_end.png"
  7. local vine_image_middle = "vines_"..name.."_middle.png"
  8. local drop_node = vine_name_end
  9. biome.spawn_plants = { vine_name_end }
  10. local vine_group = 'group:'..name..'_vines'
  11. biome.spawn_surfaces[ #biome.spawn_surfaces + 1 ] = vine_group
  12. local selection_box = { type = "wallmounted", }
  13. local drawtype = 'signlike'
  14. if ( not biome.spawn_on_side ) then
  15. --different properties for bottom and side vines.
  16. selection_box = { type = "fixed", fixed = { -0.4, -1/2, -0.4, 0.4, 1/2, 0.4 }, }
  17. drawtype = 'plantlike'
  18. end
  19. minetest.register_node( vine_name_end, {
  20. description = defs.description,
  21. walkable = false,
  22. climbable = true,
  23. wield_image = vine_image_end,
  24. drop = "",
  25. sunlight_propagates = true,
  26. paramtype = "light",
  27. paramtype2 = "wallmounted",
  28. buildable_to = true,
  29. tile_images = { vine_image_end },
  30. drawtype = drawtype,
  31. inventory_image = vine_image_end,
  32. groups = groups,
  33. sounds = default.node_sound_leaves_defaults(),
  34. selection_box = selection_box,
  35. on_construct = function( pos )
  36. local timer = minetest.get_node_timer( pos )
  37. timer:start( math.random(5, 10) )
  38. end,
  39. on_timer = function( pos )
  40. local node = minetest.get_node( pos )
  41. local bottom = {x=pos.x, y=pos.y-1, z=pos.z}
  42. local bottom_node = minetest.get_node( bottom )
  43. if bottom_node.name == "air" then
  44. if not ( math.random( defs.average_length ) == 1 ) then
  45. minetest.set_node( pos, { name = vine_name_middle, param2 = node.param2 } )
  46. minetest.set_node( bottom, { name = node.name, param2 = node.param2 } )
  47. local timer = minetest.get_node_timer( bottom_node )
  48. timer:start( math.random(5, 10) )
  49. end
  50. end
  51. end,
  52. after_dig_node = function(pos, node, oldmetadata, user)
  53. vines.dig_vine( pos, drop_node, user )
  54. end
  55. })
  56. minetest.register_node( vine_name_middle, {
  57. description = "Matured "..defs.description,
  58. walkable = false,
  59. climbable = true,
  60. drop = "",
  61. sunlight_propagates = true,
  62. paramtype = "light",
  63. paramtype2 = "wallmounted",
  64. buildable_to = true,
  65. tile_images = { vine_image_middle },
  66. wield_image = vine_image_middle,
  67. drawtype = drawtype,
  68. inventory_image = vine_image_middle,
  69. groups = groups,
  70. sounds = default.node_sound_leaves_defaults(),
  71. selection_box = selection_box,
  72. on_destruct = function( pos )
  73. local node = minetest.get_node( pos )
  74. local bottom = {x=pos.x, y=pos.y-1, z=pos.z}
  75. local bottom_node = minetest.get_node( bottom )
  76. if minetest.get_item_group( bottom_node.name, "vines") then
  77. minetest.remove_node( bottom )
  78. end
  79. end,
  80. after_dig_node = function( pos, node, oldmetadata, user )
  81. vines.dig_vine( pos, drop_node, user )
  82. end
  83. })
  84. biome_lib:spawn_on_surfaces( biome )
  85. local override_nodes = function( nodes, defs )
  86. function override( index, registered )
  87. local node = nodes[ index ]
  88. if index > #nodes then return registered end
  89. if minetest.registered_nodes[node] then
  90. minetest.override_item( node, defs )
  91. registered[#registered+1] = node
  92. end
  93. override( index+1, registered )
  94. end
  95. override( 1, {} )
  96. end
  97. override_nodes( biome.spawn_surfaces,{
  98. after_destruct = function( pos )
  99. local pos_min = { x = pos.x -1, y = pos.y - 1, z = pos.z - 1 }
  100. local pos_max = { x = pos.x +1, y = pos.y + 1, z = pos.z + 1 }
  101. local positions = minetest.find_nodes_in_area( pos_min, pos_max, "group:vines" )
  102. for index, position in pairs(positions) do
  103. minetest.remove_node( position )
  104. end
  105. end
  106. })
  107. end
  108. vines.dig_vine = function( pos, node_name, user )
  109. --only dig give the vine if shears are used
  110. if not user then return false end
  111. local wielded = user:get_wielded_item()
  112. if 'vines:shears' == wielded:get_name() then
  113. local inv = user:get_inventory()
  114. if inv then
  115. inv:add_item("main", ItemStack( node_name ))
  116. end
  117. end
  118. end