init.lua 5.0 KB

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