init.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. -- This is both seed and edible fruit.
  2. minetest.register_node("raspberries:fruit", {
  3. description = "Raspberries",
  4. tiles = {"raspberries_raspberries.png"},
  5. wield_image = "raspberries_raspberries.png",
  6. inventory_image = "raspberries_raspberries.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, "raspberries:fruit")
  19. end,
  20. on_timer = farming.grow_plant,
  21. minlight = 13,
  22. maxlight = 15,
  23. next_plant = "raspberries: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. minetest.register_craftitem("raspberries:smoothie", {
  32. description = "Raspberry Smoothie\n\nAn energy drink.\nConsume to refresh stamina.",
  33. inventory_image = "raspberries_smoothie.png",
  34. on_use = function(itemstack, user, pointed_thing)
  35. sprint.add_stamina(user, 4)
  36. user:get_inventory():add_item("main", ItemStack("vessels:drinking_glass"))
  37. local func = minetest.item_eat(1)
  38. return func(itemstack, user, pointed_thing)
  39. end,
  40. -- Stored in glass, so does not rot.
  41. })
  42. minetest.register_craft({
  43. output = "raspberries:smoothie",
  44. recipe = {
  45. {"default:snow"},
  46. {"raspberries:fruit"},
  47. {"vessels:drinking_glass"},
  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 = "raspberries:plant_2"
  75. crop_def.tiles = {"raspberries_plant_1.png"}
  76. minetest.register_node("raspberries:plant_1", table.copy(crop_def))
  77. crop_def.next_plant = "raspberries:plant_3"
  78. crop_def.tiles = {"raspberries_plant_2.png"}
  79. crop_def.description = "Raspberry Bush"
  80. crop_def.inventory_image = "raspberries_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="raspberries: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("raspberries:plant_2", table.copy(crop_def))
  102. crop_def.description = "Raspberry Bush with Blossoms"
  103. crop_def.inventory_image = "raspberries_plant_3.png"
  104. crop_def.next_plant = "raspberries:plant_4"
  105. crop_def.tiles = {"raspberries_plant_3.png"}
  106. minetest.register_node("raspberries:plant_3", table.copy(crop_def))
  107. crop_def.description = "Raspberry Bush with Raspberries"
  108. crop_def.inventory_image = "raspberries_plant_4.png"
  109. crop_def.next_plant = nil
  110. crop_def.tiles = {"raspberries_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("raspberries:plant_4"))
  120. minetest.add_item(pos, leftover)
  121. else
  122. local inv = digger:get_inventory()
  123. local leftover = inv:add_item("main", ItemStack("raspberries: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="raspberries: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("raspberries:plant_4", table.copy(crop_def))