barrel_cacti.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. local bc_col_box_1 = {
  2. type = 'fixed',
  3. fixed = {{-.3, -.5, -.3, .3, .0, .3}}
  4. }
  5. local bc_col_box_2 = {
  6. type = 'fixed',
  7. fixed = {{-.3, -.5, -.3, .3, .45, .3}}
  8. }
  9. local bc_col_box_3 = {
  10. type = 'fixed',
  11. fixed = {{-.3, -.5, -.3, .3, .8, .3}}
  12. }
  13. local barrel_cacti_table = { --number, desc, col_box
  14. {1, 'Small Barrel Cacti' ,bc_col_box_1},
  15. {2, 'Medium Barrel Cacti' ,bc_col_box_2},
  16. {3, 'Large Barrel Cacti' ,bc_col_box_3}
  17. }
  18. for i in ipairs (barrel_cacti_table) do
  19. local num = barrel_cacti_table[i][1]
  20. local desc = barrel_cacti_table[i][2]
  21. local col = barrel_cacti_table[i][3]
  22. minetest.register_node('desert_life:barrel_cacti_'..num, {
  23. description = desc,
  24. drawtype = 'mesh',
  25. mesh = 'dl_barrel_cacti_'..num..'.obj',
  26. tiles = {'dl_barrel_cacti.png'},
  27. use_texture_alpha = 'clip',
  28. groups = {oddly_breakable_by_hand=3, choppy=1, flora=1},
  29. paramtype = 'light',
  30. paramtype2 = 'facedir',
  31. selection_box = col,
  32. collision_box = col,
  33. after_place_node = function(pos, placer, itemstack)
  34. local under = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
  35. local node = minetest.get_node(pos)
  36. if under.name == 'default:sand' or under.name == 'default:desert_sand' then
  37. minetest.set_node(pos, {name = 'desert_life:barrel_cacti_'..num..'_sp', param2 = node.param2})
  38. end
  39. end,
  40. })
  41. minetest.register_node('desert_life:barrel_cacti_'..num..'_sp', {
  42. description = desc,
  43. drawtype = 'mesh',
  44. mesh = 'dl_barrel_cacti_'..num..'.obj',
  45. tiles = {'dl_barrel_cacti.png'},
  46. use_texture_alpha = 'clip',
  47. drop = 'desert_life:barrel_cacti_'..num,
  48. groups = {oddly_breakable_by_hand=3, choppy=1, dl_bc=1, not_in_creative_inventory=1},
  49. paramtype = 'light',
  50. paramtype2 = 'facedir',
  51. selection_box = col,
  52. collision_box = col,
  53. })
  54. end
  55. minetest.register_decoration({
  56. deco_type = "simple",
  57. place_on = {"default:desert_sand"},
  58. sidelen = 16,
  59. noise_params = {
  60. offset = .005,
  61. scale = 0.002,
  62. spread = {x = 150, y = 150, z = 150},
  63. seed = 35746584,
  64. octaves = 3,
  65. persist = 0.6
  66. },
  67. y_min = -10,
  68. y_max = 60,
  69. decoration = "desert_life:barrel_cacti_1_sp",
  70. param2 = 0,
  71. param2_max = 3,
  72. biomes = {'desert'},
  73. })
  74. minetest.register_abm{
  75. label = 'Barrel Cacti growth/spread',
  76. nodenames = {"group:dl_bc"},
  77. interval = 40,
  78. chance = 30,
  79. action = function(pos)
  80. local node = minetest.get_node(pos)
  81. if node.name == 'desert_life:barrel_cacti_1_sp' then
  82. minetest.set_node(pos, {name = "desert_life:barrel_cacti_2_sp", param2 = node.param2})
  83. elseif node.name == 'desert_life:barrel_cacti_2_sp' then
  84. minetest.set_node(pos, {name = "desert_life:barrel_cacti_3_sp", param2 = node.param2})
  85. elseif node.name == 'desert_life:barrel_cacti_3_sp' then
  86. desert_life.spread('desert_life:barrel_cacti_1_sp', pos, 2, 'default:desert_sand', 'air', 48)
  87. end
  88. end,
  89. }