strawberry.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_use = minetest.item_eat(1),
  9. on_place = function(itemstack, placer, pointed_thing)
  10. return farming.place_seed(itemstack, placer, pointed_thing, "ethereal:strawberry_1")
  11. end
  12. })
  13. -- Define Strawberry Bush growth stages
  14. local 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(def))
  35. -- stage 2
  36. def.tiles = {"ethereal_strawberry_2.png"}
  37. minetest.register_node("ethereal:strawberry_2", table.copy(def))
  38. -- stage 3
  39. def.tiles = {"ethereal_strawberry_3.png"}
  40. minetest.register_node("ethereal:strawberry_3", table.copy(def))
  41. -- stage 4
  42. def.tiles = {"ethereal_strawberry_4.png"}
  43. minetest.register_node("ethereal:strawberry_4", table.copy(def))
  44. -- stage 5
  45. def.tiles = {"ethereal_strawberry_5.png"}
  46. minetest.register_node("ethereal:strawberry_5", table.copy(def))
  47. -- stage 6
  48. def.tiles = {"ethereal_strawberry_6.png"}
  49. 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(def))
  56. -- stage 7
  57. def.tiles = {"ethereal_strawberry_7.png"}
  58. 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(def))
  65. -- stage 8 (final)
  66. def.tiles = {"ethereal_strawberry_8.png"}
  67. def.groups.growing = nil
  68. def.selection_box = {
  69. type = "fixed",
  70. fixed = {-0.5, -0.5, -0.5, 0.5, -2.5/16, 0.5}
  71. }
  72. def.drop = {
  73. items = {
  74. {items = {"ethereal:strawberry 2"}, rarity = 1},
  75. {items = {"ethereal:strawberry 3"}, rarity = 3}
  76. }
  77. }
  78. minetest.register_node("ethereal:strawberry_8", table.copy(def))
  79. -- growing routine if farming redo isn't present
  80. if farming and farming.mod and farming.mod == "redo" then
  81. -- add to registered_plants
  82. farming.registered_plants["ethereal:strawberry"] = {
  83. crop = "ethereal:strawberry",
  84. seed = "ethereal:strawberry",
  85. minlight = farming.min_light,
  86. maxlight = farming.max_light,
  87. steps = 8
  88. }
  89. else
  90. minetest.register_abm({
  91. label = "Ethereal grow strawberry",
  92. nodenames = {
  93. "ethereal:strawberry_1", "ethereal:strawberry_2", "ethereal:strawberry_3",
  94. "ethereal:strawberry_4", "ethereal:strawberry_5", "ethereal:strawberry_6",
  95. "ethereal:strawberry_7"
  96. },
  97. neighbors = {"farming:soil_wet"},
  98. interval = 9,
  99. chance = 20,
  100. catch_up = false,
  101. action = function(pos, node)
  102. -- are we on wet soil?
  103. pos.y = pos.y - 1
  104. if minetest.get_item_group(minetest.get_node(pos).name, "soil") < 3 then
  105. return
  106. end
  107. pos.y = pos.y + 1
  108. -- do we have enough light?
  109. local light = minetest.get_node_light(pos)
  110. if not light or light < 13 then
  111. return
  112. end
  113. -- grow to next stage
  114. local num = node.name:split("_")[2]
  115. node.name = "ethereal:strawberry_" .. tonumber(num + 1)
  116. minetest.swap_node(pos, node)
  117. end
  118. })
  119. end