init.lua 4.7 KB

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