init.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. _farming_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\nEnergy drink. Quaff to improve 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._farming_next_plant = "raspberries:plant_2"
  77. crop_def._farming_prev_plant = "raspberries:plant_1" -- No specific seed.
  78. crop_def.tiles = {"raspberries_plant_1.png"}
  79. minetest.register_node("raspberries:plant_1", table.copy(crop_def))
  80. crop_def._farming_next_plant = "raspberries:plant_3"
  81. crop_def._farming_prev_plant = "raspberries:plant_1"
  82. crop_def.tiles = {"raspberries_plant_2.png"}
  83. crop_def.description = "Raspberry Bush"
  84. crop_def.inventory_image = "raspberries_plant_2.png"
  85. crop_def.after_dig_node =
  86. function(pos, oldnode, oldmetadata, digger)
  87. if digger and digger:is_player() then
  88. local wielditem = digger:get_wielded_item()
  89. if string.find(wielditem:get_name(), "shovel") then
  90. -- If player digs with a shovel, then the bush is removed.
  91. -- The player gets 1 bush, which can be used for decoration.
  92. local inv = digger:get_inventory()
  93. local leftover = inv:add_item("main", ItemStack(oldnode.name))
  94. minetest.add_item(pos, leftover)
  95. else
  96. -- Restore bush. Player did not actually dig it up.
  97. minetest.after(0, function()
  98. minetest.set_node(pos, {name="raspberries:plant_2", param2=2})
  99. local timer = minetest.get_node_timer(pos)
  100. timer:start(math_random(300, 700))
  101. end)
  102. end
  103. end
  104. end
  105. minetest.register_node("raspberries:plant_2", table.copy(crop_def))
  106. crop_def.description = "Raspberry Bush with Blossoms"
  107. crop_def.inventory_image = "raspberries_plant_3.png"
  108. crop_def._farming_next_plant = "raspberries:plant_4"
  109. crop_def._farming_prev_plant = "raspberries:plant_2"
  110. crop_def.tiles = {"raspberries_plant_3.png"}
  111. minetest.register_node("raspberries:plant_3", table.copy(crop_def))
  112. crop_def.description = "Raspberry Bush with Raspberries"
  113. crop_def.inventory_image = "raspberries_plant_4.png"
  114. crop_def._farming_next_plant = nil
  115. crop_def._farming_prev_plant = "raspberries:plant_3"
  116. crop_def.tiles = {"raspberries_plant_4.png"}
  117. crop_def.after_dig_node =
  118. function(pos, oldnode, oldmetadata, digger)
  119. if digger and digger:is_player() then
  120. local wielditem = digger:get_wielded_item()
  121. if string.find(wielditem:get_name(), "shovel") then
  122. -- If player digs with a shovel, then the bush is removed.
  123. -- The player gets 1 bush, which can be used for decoration.
  124. local inv = digger:get_inventory()
  125. local leftover = inv:add_item("main", ItemStack("raspberries:plant_4"))
  126. minetest.add_item(pos, leftover)
  127. else
  128. local inv = digger:get_inventory()
  129. local leftover = inv:add_item("main", ItemStack("raspberries:fruit " .. math_random(1, 5)))
  130. minetest.add_item(pos, leftover)
  131. -- Restore bush. Player did not actually dig it up.
  132. minetest.after(0, function()
  133. minetest.set_node(pos, {name="raspberries:plant_2", param2=2})
  134. local timer = minetest.get_node_timer(pos)
  135. timer:start(math_random(300, 700))
  136. end)
  137. end
  138. end
  139. end
  140. minetest.register_node("raspberries:plant_4", table.copy(crop_def))