init.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. plants = {}
  2. function plants.register_crop(name, desc, bit1, bit2)
  3. bit1 = bit1 or 0
  4. bit2 = bit2 or 0
  5. minetest.register_node('plants:'..name..'_1', {
  6. description = desc,
  7. tiles = {'plants_'..name..'_1.png'},
  8. drawtype = 'plantlike',
  9. paramtype = 'light',
  10. paramtype2 = 'meshoptions',
  11. walkable = false,
  12. drop = 'plants:'..name..'_2',
  13. groups = {breakable=1, not_in_creative_inventory=1},
  14. selection_box = {
  15. type = 'fixed',
  16. fixed = {{-.4, -.5, -.4, .4, -.2, .4}}
  17. },
  18. on_timer = function(pos)
  19. local node = minetest.get_node(pos)
  20. minetest.set_node(pos, {name = 'plants:'..name..'_2', param2 = node.param2})
  21. end,
  22. })
  23. minetest.register_node('plants:'..name..'_2', {
  24. description = desc,
  25. tiles = {'plants_'..name..'_2.png'},
  26. inventory_image = 'plants_'..name..'_2.png',
  27. drawtype = 'plantlike',
  28. paramtype = 'light',
  29. paramtype2 = 'meshoptions',
  30. walkable = false,
  31. groups = {breakable=1},
  32. selection_box = {
  33. type = 'fixed',
  34. fixed = {{-.4, -.5, -.4, .4, .25, .4}}
  35. },
  36. after_place_node = function(pos)
  37. local bitflag = bit1 + bit2
  38. minetest.set_node(pos, {name = 'plants:'..name..'_2', param2 = bitflag})
  39. end,
  40. on_punch = function(pos, node, puncher, pointed_thing)
  41. local player_inv = puncher:get_inventory()
  42. if not player_inv:contains_item('main', {name='plants:'..name, count = 4}) then
  43. local timer = minetest.get_node_timer(pos)
  44. player_inv:add_item('main', 'plants:'..name)
  45. minetest.set_node(pos, {name = 'plants:'..name..'_1', param2 = node.param2})
  46. timer:start(300)
  47. else
  48. minetest.chat_send_player(puncher:get_player_name(), 'You have too many of these already.')
  49. end
  50. end,
  51. })
  52. minetest.register_craftitem('plants:'..name, {
  53. description = desc,
  54. inventory_image = 'plants_'..name..'.png',
  55. stack_max = 1,
  56. groups = {not_in_creative_inventory=1},
  57. on_drop = lobby.no_drop
  58. })
  59. end
  60. function plants.register_grass(name, desc)
  61. minetest.register_node('plants:'..name..'_1', {
  62. description = desc,
  63. tiles = {'plants_'..name..'_1.png'},
  64. inventory_image = 'plants_'..name..'_3.png',
  65. drawtype = 'plantlike',
  66. paramtype = 'light',
  67. paramtype2 = 'degrotate',
  68. walkable = false,
  69. groups = {breakable=1},
  70. selection_box = {
  71. type = 'fixed',
  72. fixed = {{-.3, -.5, -.3, .3, 0, .3}}
  73. },
  74. after_place_node = function(pos)
  75. local rot = math.random(0,179)
  76. local i = math.random(1,5)
  77. minetest.set_node(pos, {name = 'plants:'..name..'_'..i, param2 = rot})
  78. end,
  79. on_timer = function(pos)
  80. local node = minetest.get_node(pos)
  81. local meta = minetest.get_meta(pos)
  82. local name = meta:get_string('flower')
  83. if name ~= '' then
  84. minetest.set_node(pos, {name = 'plants:'..name, param2 = node.param2})
  85. end
  86. end,
  87. })
  88. for i = 2, 5 do
  89. minetest.register_node('plants:'..name..'_'..i, {
  90. description = desc,
  91. tiles = {'plants_'..name..'_'..i..'.png'},
  92. drawtype = 'plantlike',
  93. paramtype = 'light',
  94. paramtype2 = 'degrotate',
  95. walkable = false,
  96. groups = {breakable=1, not_in_creative_inventory=1},
  97. drop = 'plants:'..name..'_1',
  98. selection_box = {
  99. type = 'fixed',
  100. fixed = {{-.3, -.5, -.3, .3, 0, .3}}
  101. },
  102. })
  103. end
  104. end
  105. function plants.register_plant(name, desc, light)
  106. minetest.register_node('plants:'..name, {
  107. description = desc,
  108. tiles = {'plants_'..name..'.png'},
  109. inventory_image = 'plants_'..name..'.png',
  110. light_source = light,
  111. drawtype = 'plantlike',
  112. paramtype = 'light',
  113. paramtype2 = 'degrotate',
  114. walkable = false,
  115. groups = {breakable=1},
  116. selection_box = {
  117. type = 'fixed',
  118. fixed = {{-.3, -.5, -.3, .3, 0, .3}}
  119. },
  120. after_place_node = function(pos)
  121. local rot = math.random(0,179)
  122. minetest.set_node(pos, {name = 'plants:'..name, param2 = rot})
  123. end,
  124. })
  125. end
  126. function plants.register_flower(name, desc, light)
  127. minetest.register_node('plants:'..name, {
  128. description = desc,
  129. tiles = {'plants_'..name..'.png'},
  130. inventory_image = 'plants_'..name..'.png',
  131. light_source = light,
  132. drawtype = 'plantlike',
  133. paramtype = 'light',
  134. paramtype2 = 'degrotate',
  135. walkable = false,
  136. groups = {breakable=1},
  137. selection_box = {
  138. type = 'fixed',
  139. fixed = {{-.3, -.5, -.3, .3, 0, .3}}
  140. },
  141. after_place_node = function(pos)
  142. local rot = math.random(0,179)
  143. minetest.set_node(pos, {name = 'plants:'..name, param2 = rot})
  144. end,
  145. on_punch = function(pos, node, puncher, pointed_thing)
  146. local player = puncher:get_player_name()
  147. local wield = puncher:get_wielded_item()
  148. local wield_name = wield:get_name()
  149. if wield_name == 'creative:tool_breaking' then
  150. return
  151. else
  152. local player_inv = puncher:get_inventory()
  153. if not player_inv:contains_item('main', {name='plants:'..name, count = 4}) then
  154. local timer = minetest.get_node_timer(pos)
  155. local meta = minetest.get_meta(pos)
  156. player_inv:add_item('main', 'plants:'..name)
  157. minetest.set_node(pos, {name = 'plants:grass_1', param2 = node.param2})
  158. meta:set_string('flower', name)
  159. timer:start(300)
  160. else
  161. minetest.chat_send_player(puncher:get_player_name(), 'You have too many of these already.')
  162. end
  163. end
  164. end,
  165. on_drop = lobby.no_drop,
  166. })
  167. end
  168. dofile(minetest.get_modpath('plants')..'/bushes.lua')
  169. dofile(minetest.get_modpath('plants')..'/crops.lua')
  170. dofile(minetest.get_modpath('plants')..'/flowers.lua')
  171. dofile(minetest.get_modpath('plants')..'/fungi.lua')
  172. dofile(minetest.get_modpath('plants')..'/grass.lua')
  173. dofile(minetest.get_modpath('plants')..'/misc.lua')
  174. dofile(minetest.get_modpath('plants')..'/sapling.lua')