onion.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. local S = ethereal.intllib
  2. -- wild onion
  3. minetest.register_craftitem("ethereal:wild_onion_plant", {
  4. description = S("Wild Onion"),
  5. inventory_image = "wild_onion.png",
  6. wield_image = "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 = 0
  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 not farming or not farming.mod or farming.mod ~= "redo" then
  61. minetest.register_abm({
  62. label = "Ethereal grow onion",
  63. nodenames = {"ethereal:onion_1", "ethereal:onion_2", "ethereal:onion_3", "ethereal:onion_4"},
  64. neighbors = {"farming:soil_wet"},
  65. interval = 9,
  66. chance = 20,
  67. catch_up = false,
  68. action = function(pos, node)
  69. -- are we on wet soil?
  70. pos.y = pos.y - 1
  71. if minetest.get_item_group(minetest.get_node(pos).name, "soil") < 3 then
  72. return
  73. end
  74. pos.y = pos.y + 1
  75. -- do we have enough light?
  76. local light = minetest.get_node_light(pos)
  77. if not light
  78. or light < 13 then
  79. return
  80. end
  81. -- grow to next stage
  82. local num = node.name:split("_")[2]
  83. node.name = "ethereal:onion_" .. tonumber(num + 1)
  84. minetest.swap_node(pos, node)
  85. end
  86. })
  87. end -- END IF