init.lua 4.9 KB

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