strawberry.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. local S = ethereal.intllib
  2. -- Strawberry (can also be planted as seed)
  3. minetest.register_craftitem("ethereal:strawberry", {
  4. description = S("Strawberry"),
  5. inventory_image = "ethereal_strawberry.png",
  6. wield_image = "ethereal_strawberry.png",
  7. groups = {food_strawberry = 1, food_berry = 1, flammable = 2},
  8. on_place = function(itemstack, placer, pointed_thing)
  9. return farming.place_seed(itemstack, placer, pointed_thing, "ethereal:strawberry_1")
  10. end,
  11. on_use = minetest.item_eat(1)
  12. })
  13. -- Define Strawberry Bush growth stages
  14. local crop_def = {
  15. drawtype = "plantlike",
  16. tiles = {"ethereal_strawberry_1.png"},
  17. paramtype = "light",
  18. sunlight_propagates = true,
  19. waving = 1,
  20. walkable = false,
  21. buildable_to = true,
  22. drop = "",
  23. selection_box = {
  24. type = "fixed",
  25. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
  26. },
  27. groups = {
  28. snappy = 3, flammable = 2, plant = 1, attached_node = 1,
  29. not_in_creative_inventory = 1, growing = 1
  30. },
  31. sounds = default.node_sound_leaves_defaults()
  32. }
  33. --stage 1
  34. minetest.register_node("ethereal:strawberry_1", table.copy(crop_def))
  35. -- stage 2
  36. crop_def.tiles = {"ethereal_strawberry_2.png"}
  37. minetest.register_node("ethereal:strawberry_2", table.copy(crop_def))
  38. -- stage 3
  39. crop_def.tiles = {"ethereal_strawberry_3.png"}
  40. minetest.register_node("ethereal:strawberry_3", table.copy(crop_def))
  41. -- stage 4
  42. crop_def.tiles = {"ethereal_strawberry_4.png"}
  43. minetest.register_node("ethereal:strawberry_4", table.copy(crop_def))
  44. -- stage 5
  45. crop_def.tiles = {"ethereal_strawberry_5.png"}
  46. minetest.register_node("ethereal:strawberry_5", table.copy(crop_def))
  47. -- stage 6
  48. crop_def.tiles = {"ethereal_strawberry_6.png"}
  49. crop_def.drop = {
  50. items = {
  51. {items = {"ethereal:strawberry 1"},rarity = 2},
  52. {items = {"ethereal:strawberry 2"},rarity = 3}
  53. }
  54. }
  55. minetest.register_node("ethereal:strawberry_6", table.copy(crop_def))
  56. -- stage 7
  57. crop_def.tiles = {"ethereal_strawberry_7.png"}
  58. crop_def.drop = {
  59. items = {
  60. {items = {"ethereal:strawberry 1"},rarity = 1},
  61. {items = {"ethereal:strawberry 2"},rarity = 3}
  62. }
  63. }
  64. minetest.register_node("ethereal:strawberry_7", table.copy(crop_def))
  65. -- stage 8
  66. crop_def.tiles = {"ethereal_strawberry_8.png"}
  67. crop_def.groups.growing = nil
  68. crop_def.drop = {
  69. items = {
  70. {items = {"ethereal:strawberry 2"},rarity = 1},
  71. {items = {"ethereal:strawberry 3"},rarity = 3}
  72. }
  73. }
  74. minetest.register_node("ethereal:strawberry_8", table.copy(crop_def))
  75. -- growing routine if farming redo isn't present
  76. if farming and farming.mod and farming.mod == "redo" then
  77. -- add to registered_plants
  78. farming.registered_plants["ethereal:strawberry"] = {
  79. crop = "ethereal:strawberry",
  80. seed = "ethereal:strawberry",
  81. minlight = farming.min_light,
  82. maxlight = farming.max_light,
  83. steps = 8
  84. }
  85. else
  86. minetest.register_abm({
  87. label = "Ethereal grow strawberry",
  88. nodenames = {
  89. "ethereal:strawberry_1", "ethereal:strawberry_2", "ethereal:strawberry_3",
  90. "ethereal:strawberry_4", "ethereal:strawberry_5", "ethereal:strawberry_6",
  91. "ethereal:strawberry_7"
  92. },
  93. neighbors = {"farming:soil_wet"},
  94. interval = 9,
  95. chance = 20,
  96. catch_up = false,
  97. action = function(pos, node)
  98. -- are we on wet soil?
  99. pos.y = pos.y - 1
  100. if minetest.get_item_group(minetest.get_node(pos).name, "soil") < 3 then
  101. return
  102. end
  103. pos.y = pos.y + 1
  104. -- do we have enough light?
  105. local light = minetest.get_node_light(pos)
  106. if not light or light < 13 then
  107. return
  108. end
  109. -- grow to next stage
  110. local num = node.name:split("_")[2]
  111. node.name = "ethereal:strawberry_" .. tonumber(num + 1)
  112. minetest.swap_node(pos, node)
  113. end
  114. })
  115. end