init.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. local math_random = math.random
  2. -- This is both seed and edible Bean.
  3. minetest.register_node("coffee_bush:seeds", {
  4. description = "Coffee Beans",
  5. tiles = {"coffeebeans.png"},
  6. wield_image = "coffeebeans.png",
  7. inventory_image = "coffeebeans.png",
  8. drawtype = "signlike",
  9. paramtype = "light",
  10. paramtype2 = "wallmounted",
  11. walkable = false,
  12. sunlight_propagates = true,
  13. selection_box = {
  14. type = "fixed",
  15. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
  16. },
  17. groups = utility.dig_groups("seeds", {seed = 1, attached_node = 1, flammable = 2, foodrot = 1, notify_destruct = 1}),
  18. on_place = function(itemstack, placer, pointed_thing)
  19. return farming.place_seed(itemstack, placer, pointed_thing, "coffee_bush:seeds")
  20. end,
  21. on_timer = farming.grow_plant,
  22. minlight = 13,
  23. maxlight = 15,
  24. next_plant = "coffee_bush:plant_1",
  25. fertility = {"grassland"},
  26. sounds = default.node_sound_dirt_defaults({
  27. dug = {name = "default_grass_footstep", gain = 0.2},
  28. place = {name = "default_place_node", gain = 0.25},
  29. }),
  30. on_use = minetest.item_eat(4),
  31. })
  32. local crop_def = {
  33. drawtype = "plantlike",
  34. paramtype = "light",
  35. paramtype2 = "meshoptions",
  36. place_param2 = 2,
  37. sunlight_propagates = true,
  38. waving = 1,
  39. walkable = false,
  40. buildable_to = true,
  41. drop = "",
  42. selection_box = {
  43. type = "fixed",
  44. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
  45. },
  46. groups = utility.dig_groups("crop", {
  47. flammable = 2, plant = 1, attached_node = 1,
  48. not_in_creative_inventory = 1, notify_destruct = 1,
  49. }),
  50. sounds = default.node_sound_leaves_defaults(),
  51. on_timer = farming.grow_plant,
  52. minlight = 13,
  53. maxlight = default.LIGHT_MAX,
  54. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  55. }
  56. crop_def.next_plant = "coffee_bush:plant_2"
  57. crop_def.tiles = {"coffee_bush1.png"}
  58. minetest.register_node("coffee_bush:plant_1", table.copy(crop_def))
  59. crop_def.description = "Coffee Bush"
  60. crop_def.inventory_image = "coffee_bush2.png"
  61. crop_def.next_plant = "coffee_bush:plant_3"
  62. crop_def.tiles = {"coffee_bush2.png"}
  63. crop_def.after_dig_node =
  64. function(pos, oldnode, oldmetadata, digger)
  65. if digger and digger:is_player() then
  66. local wielditem = digger:get_wielded_item()
  67. if string.find(wielditem:get_name(), "shovel") then
  68. -- If player digs with a shovel, then the bush is removed.
  69. -- The player gets 1 bush, which can be used for decoration.
  70. local inv = digger:get_inventory()
  71. local leftover = inv:add_item("main", ItemStack(oldnode.name))
  72. minetest.add_item(pos, leftover)
  73. else
  74. -- Restore bush. Player did not actually dig it up yet.
  75. minetest.after(0, function()
  76. minetest.set_node(pos, {name="coffee_bush:plant_2", param2=2})
  77. local timer = minetest.get_node_timer(pos)
  78. timer:start(math_random(300, 700))
  79. end)
  80. end
  81. end
  82. end
  83. minetest.register_node("coffee_bush:plant_2", table.copy(crop_def))
  84. crop_def.description = "Coffee Bush With Blossoms"
  85. crop_def.inventory_image = "coffee_bush3.png"
  86. crop_def.next_plant = "coffee_bush:plant_4"
  87. crop_def.tiles = {"coffee_bush3.png"}
  88. minetest.register_node("coffee_bush:plant_3", table.copy(crop_def))
  89. crop_def.description = "Coffee Bush With Beans"
  90. crop_def.inventory_image = "coffee_bush4.png"
  91. crop_def.next_plant = nil
  92. crop_def.tiles = {"coffee_bush4.png"}
  93. crop_def.after_dig_node =
  94. function(pos, oldnode, oldmetadata, digger)
  95. if digger and digger:is_player() then
  96. local wielditem = digger:get_wielded_item()
  97. if string.find(wielditem:get_name(), "shovel") then
  98. -- If player digs with a shovel, then the bush is removed.
  99. -- The player gets 1 bush, which can be used for decoration.
  100. local inv = digger:get_inventory()
  101. local leftover = inv:add_item("main", ItemStack("coffee_bush:plant_4"))
  102. minetest.add_item(pos, leftover)
  103. else
  104. local inv = digger:get_inventory()
  105. local leftover = inv:add_item("main", ItemStack("coffee_bush:seeds " .. math_random(1, 5)))
  106. minetest.add_item(pos, leftover)
  107. -- Restore bush. Player did not actually dig it up.
  108. minetest.after(0, function()
  109. minetest.set_node(pos, {name="coffee_bush:plant_2", param2=2})
  110. local timer = minetest.get_node_timer(pos)
  111. timer:start(math_random(300, 700))
  112. end)
  113. end
  114. end
  115. end
  116. minetest.register_node("coffee_bush:plant_4", table.copy(crop_def))