onion.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. local S = ethereal.intllib
  2. -- wild onion
  3. minetest.register_craftitem("ethereal:wild_onion_plant", {
  4. description = S("Wild Onion"),
  5. inventory_image = "ethereal_wild_onion.png",
  6. wield_image = "ethereal_wild_onion.png",
  7. groups = {food_onion = 1, flammable = 2},
  8. on_use = minetest.item_eat(2),
  9. on_place = function(itemstack, placer, pointed_thing)
  10. return farming.place_seed(itemstack, placer, pointed_thing, "ethereal:wild_onion_1")
  11. end
  12. })
  13. -- Define Onion growth stages
  14. local def = {
  15. drawtype = "plantlike",
  16. tiles = {"ethereal_wild_onion_1.png"},
  17. paramtype = "light",
  18. sunlight_propagates = true,
  19. walkable = false,
  20. buildable_to = true,
  21. drop = "",
  22. selection_box = {
  23. type = "fixed",
  24. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
  25. },
  26. groups = {
  27. snappy = 3, flammable = 2, plant = 1, attached_node = 1,
  28. growing = 1, not_in_creative_inventory = 1
  29. },
  30. sounds = default.node_sound_leaves_defaults()
  31. }
  32. --stage 1
  33. minetest.register_node("ethereal:onion_1", table.copy(def))
  34. --stage 2
  35. def.tiles = {"ethereal_wild_onion_2.png"}
  36. minetest.register_node("ethereal:onion_2", table.copy(def))
  37. --stage 3
  38. def.tiles = {"ethereal_wild_onion_3.png"}
  39. minetest.register_node("ethereal:onion_3", table.copy(def))
  40. --stage 4
  41. def.tiles = {"ethereal_wild_onion_4.png"}
  42. def.drop = {
  43. items = {
  44. {items = {"ethereal:wild_onion_plant"}, rarity = 1},
  45. {items = {"ethereal:wild_onion_plant 2"}, rarity = 3},
  46. }
  47. }
  48. minetest.register_node("ethereal:onion_4", table.copy(def))
  49. --stage 5
  50. def.tiles = {"ethereal_wild_onion_5.png"}
  51. def.groups.growing = nil
  52. def.selection_box = {
  53. type = "fixed",
  54. fixed = {-0.5, -0.5, -0.5, 0.5, -2.5/16, 0.5}
  55. }
  56. def.drop = {
  57. items = {
  58. {items = {"ethereal:wild_onion_plant 2"}, rarity = 1},
  59. {items = {"ethereal:wild_onion_plant 3"}, rarity = 2},
  60. }
  61. }
  62. minetest.register_node("ethereal:onion_5", table.copy(def))
  63. -- growing routine if farming redo isn't present
  64. if farming and farming.mod and farming.mod == "redo" then
  65. -- add to registered_plants
  66. farming.registered_plants["ethereal:wild_onion_plant"] = {
  67. crop = "ethereal:onion",
  68. seed = "ethereal:wild_onion_plant",
  69. minlight = farming.min_light,
  70. maxlight = farming.max_light,
  71. steps = 5
  72. }
  73. else
  74. minetest.register_abm({
  75. label = "Ethereal grow onion",
  76. nodenames = {
  77. "ethereal:onion_1", "ethereal:onion_2", "ethereal:onion_3",
  78. "ethereal:onion_4"
  79. },
  80. neighbors = {"farming:soil_wet"},
  81. interval = 11,
  82. chance = 20,
  83. catch_up = false,
  84. action = function(pos, node)
  85. -- are we on wet soil?
  86. pos.y = pos.y - 1
  87. if minetest.get_item_group(minetest.get_node(pos).name, "soil") < 3 then
  88. return
  89. end
  90. pos.y = pos.y + 1
  91. -- do we have enough light?
  92. local light = minetest.get_node_light(pos)
  93. if not light or light < 13 then
  94. return
  95. end
  96. -- grow to next stage
  97. local num = node.name:split("_")[2]
  98. node.name = "ethereal:onion_" .. tonumber(num + 1)
  99. minetest.swap_node(pos, node)
  100. end
  101. })
  102. end