prickly_pear.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. local pp_col_box_1 = {
  2. type = 'fixed',
  3. fixed = {{-.2, -.5, -.2, .2, .0, .2}}
  4. }
  5. local pp_col_box_2 = {
  6. type = 'fixed',
  7. fixed = {{-.6, -.5, -.2, .2, .2, .2}}
  8. }
  9. local pp_col_box_3 = {
  10. type = 'fixed',
  11. fixed = {{-.6, -.5, -.2, .6, .2, .2}}
  12. }
  13. local pp_col_box_4 = {
  14. type = 'fixed',
  15. fixed = {{-.6, -.5, -.2, .6, .45, .2}}
  16. }
  17. local pp_col_box_5 = {
  18. type = 'fixed',
  19. fixed = {{-.7, -.5, -.2, .7, .7, .2}}
  20. }
  21. local pp_col_box_6 = {
  22. type = 'fixed',
  23. fixed = {{-.7, -.5, -.2, .7, .7, .2}}
  24. }
  25. local pp_col_box_7 = {
  26. type = 'fixed',
  27. fixed = {{-.6, -.5, -.2, .6, .9, .2}}
  28. }
  29. local prickly_pear_table = { --number, after_dig, col_box
  30. {1, 'air', pp_col_box_1},
  31. {2, 'desert_life:prickly_pear_1', pp_col_box_2},
  32. {3, 'desert_life:prickly_pear_2', pp_col_box_3},
  33. {4, 'desert_life:prickly_pear_3', pp_col_box_4},
  34. {5, 'desert_life:prickly_pear_4', pp_col_box_5},
  35. {6, 'desert_life:prickly_pear_5', pp_col_box_6},
  36. {7, 'desert_life:prickly_pear_6', pp_col_box_7},
  37. }
  38. for i in ipairs (prickly_pear_table) do
  39. local num = prickly_pear_table[i][1]
  40. local AD = prickly_pear_table[i][2]
  41. local col = prickly_pear_table[i][3]
  42. minetest.register_node('desert_life:prickly_pear_'..num, {
  43. description = 'Prickly Pear',
  44. drawtype = 'mesh',
  45. mesh = 'dl_pp_'..num..'.obj',
  46. tiles = {'dl_prickly_pear.png'},
  47. use_texture_alpha = 'opaque',
  48. groups = {not_in_creative_inventory=1, dl_pp=1, flora=1},
  49. paramtype = 'light',
  50. paramtype2 = 'facedir',
  51. selection_box = col,
  52. collision_box = col,
  53. on_punch = function(pos, node, player, pointed_thing)
  54. minetest.set_node(pos, {name = AD, param2 = node.param2})
  55. player:get_inventory():add_item('main', 'desert_life:prickly_pear') --If inventory is full it should be dropped.
  56. -- local stack = ItemStack('desert_life:prickly_pear')
  57. -- local leftover = minetest.add_item('main', stack)
  58. -- if leftover:get_count() > 0 then
  59. -- minetest.add_item (pos, 'desert_life:prickly_pear '..leftover:get_count())
  60. -- end
  61. local damage_chance = math.random(1,15)
  62. if damage_chance == 1 then
  63. local hp = player:get_hp()
  64. player:set_hp(hp - 1)
  65. end
  66. end
  67. })
  68. end
  69. minetest.register_node('desert_life:prickly_pear', {
  70. description = 'Prickly Pear Pad',
  71. drawtype = 'mesh',
  72. mesh = 'dl_pp_1.obj',
  73. tiles = {'dl_prickly_pear.png'},
  74. use_texture_alpha = 'opaque',
  75. groups = {dig_immediate = 3, flora=1},
  76. paramtype = 'light',
  77. paramtype2 = 'facedir',
  78. selection_box = {
  79. type = 'fixed',
  80. fixed = {{-.2, -.5, -.2, .2, .0, .2}}
  81. },
  82. collision_box = {
  83. type = 'fixed',
  84. fixed = {{-.2, -.5, -.2, .2, .0, .2}} -- left bottom front right top back
  85. },
  86. drop = 'desert_life:prickly_pear',
  87. after_place_node = function(pos, placer, itemstack)
  88. local under = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
  89. local node = minetest.get_node(pos)
  90. if under.name == 'default:sand' or under.name == 'default:desert_sand' then
  91. minetest.set_node(pos, {name = 'desert_life:prickly_pear_1', param2 = node.param2})
  92. end
  93. end,
  94. })
  95. minetest.register_decoration({
  96. deco_type = "simple",
  97. place_on = {"default:desert_sand"},
  98. sidelen = 16,
  99. noise_params = {
  100. offset = .005,
  101. scale = 0.002,
  102. spread = {x = 150, y = 150, z = 150},
  103. seed = 150,
  104. octaves = 3,
  105. persist = 0.6
  106. },
  107. y_min = -10,
  108. y_max = 60,
  109. decoration = "desert_life:prickly_pear_1",
  110. param2 = 0,
  111. param2_max = 3,
  112. biomes = {'desert'},
  113. })
  114. minetest.register_abm{
  115. nodenames = {"group:dl_pp"},
  116. label = 'Prickly pear growth/spread',
  117. interval = 40,
  118. chance = 30,
  119. action = function(pos)
  120. local node = minetest.get_node(pos)
  121. if node.name == 'desert_life:prickly_pear_1' then
  122. minetest.set_node(pos, {name = "desert_life:prickly_pear_2", param2 = node.param2})
  123. elseif node.name == 'desert_life:prickly_pear_2' then
  124. minetest.set_node(pos, {name = "desert_life:prickly_pear_3", param2 = node.param2})
  125. elseif node.name == 'desert_life:prickly_pear_3' then
  126. minetest.set_node(pos, {name = "desert_life:prickly_pear_4", param2 = node.param2})
  127. elseif node.name == 'desert_life:prickly_pear_4' then
  128. minetest.set_node(pos, {name = "desert_life:prickly_pear_5", param2 = node.param2})
  129. elseif node.name == 'desert_life:prickly_pear_5' then
  130. minetest.set_node(pos, {name = "desert_life:prickly_pear_6", param2 = node.param2})
  131. elseif node.name == 'desert_life:prickly_pear_6' then
  132. minetest.set_node(pos, {name = "desert_life:prickly_pear_7", param2 = node.param2})
  133. elseif node.name == 'desert_life:prickly_pear_7' then
  134. desert_life.spread('desert_life:prickly_pear_1', pos, 1, 'default:desert_sand', 'air', 22)
  135. end
  136. end,
  137. }