onion.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_place = function(itemstack, placer, pointed_thing)
  9. return farming.place_seed(itemstack, placer, pointed_thing, "ethereal:wild_onion_1")
  10. end,
  11. on_use = minetest.item_eat(2)
  12. })
  13. -- Define Onion growth stages
  14. local crop_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(crop_def))
  34. --stage 2
  35. crop_def.tiles = {"ethereal_wild_onion_2.png"}
  36. minetest.register_node("ethereal:onion_2", table.copy(crop_def))
  37. --stage 3
  38. crop_def.tiles = {"ethereal_wild_onion_3.png"}
  39. minetest.register_node("ethereal:onion_3", table.copy(crop_def))
  40. --stage 4
  41. crop_def.tiles = {"ethereal_wild_onion_4.png"}
  42. crop_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(crop_def))
  49. --stage 5
  50. crop_def.tiles = {"ethereal_wild_onion_5.png"}
  51. crop_def.groups.growing = nil
  52. crop_def.drop = {
  53. items = {
  54. {items = {"ethereal:wild_onion_plant 2"}, rarity = 1},
  55. {items = {"ethereal:wild_onion_plant 3"}, rarity = 2},
  56. }
  57. }
  58. minetest.register_node("ethereal:onion_5", table.copy(crop_def))
  59. -- growing routine if farming redo isn't present
  60. if farming and farming.mod and farming.mod == "redo" then
  61. -- add to registered_plants
  62. farming.registered_plants["ethereal:wild_onion_plant"] = {
  63. crop = "ethereal:onion",
  64. seed = "ethereal:wild_onion_plant",
  65. minlight = farming.min_light,
  66. maxlight = farming.max_light,
  67. steps = 5
  68. }
  69. else
  70. minetest.register_abm({
  71. label = "Ethereal grow onion",
  72. nodenames = {
  73. "ethereal:onion_1", "ethereal:onion_2", "ethereal:onion_3",
  74. "ethereal:onion_4"
  75. },
  76. neighbors = {"farming:soil_wet"},
  77. interval = 11,
  78. chance = 20,
  79. catch_up = false,
  80. action = function(pos, node)
  81. -- are we on wet soil?
  82. pos.y = pos.y - 1
  83. if minetest.get_item_group(minetest.get_node(pos).name, "soil") < 3 then
  84. return
  85. end
  86. pos.y = pos.y + 1
  87. -- do we have enough light?
  88. local light = minetest.get_node_light(pos)
  89. if not light or light < 13 then
  90. return
  91. end
  92. -- grow to next stage
  93. local num = node.name:split("_")[2]
  94. node.name = "ethereal:onion_" .. tonumber(num + 1)
  95. minetest.swap_node(pos, node)
  96. end
  97. })
  98. end