grapes.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. local S = farming.intllib
  2. -- place trellis
  3. local function place_grapes(itemstack, placer, pointed_thing, plantname)
  4. local pt = pointed_thing
  5. -- check if pointing at a node
  6. if not pt or pt.type ~= "node" then
  7. return
  8. end
  9. local under = minetest.get_node(pt.under)
  10. -- return if any of the nodes are not registered
  11. if not minetest.registered_nodes[under.name] then
  12. return
  13. end
  14. -- am I right-clicking on something that has a custom on_place set?
  15. -- thanks to Krock for helping with this issue :)
  16. local def = minetest.registered_nodes[under.name]
  17. if placer and itemstack and def and def.on_rightclick then
  18. return def.on_rightclick(pt.under, under, placer, itemstack)
  19. end
  20. -- is player planting seed?
  21. local name = placer and placer:get_player_name() or ""
  22. -- check for protection
  23. if minetest.is_protected(pt.under, name) then
  24. return
  25. end
  26. -- check if pointing at trellis
  27. if under.name ~= "farming:trellis" then
  28. return
  29. end
  30. -- add the node and remove 1 item from the itemstack
  31. minetest.set_node(pt.under, {name = plantname})
  32. minetest.sound_play("default_place_node", {pos = pt.under, gain = 1.0})
  33. if placer and not farming.is_creative(placer:get_player_name()) then
  34. itemstack:take_item()
  35. -- check for refill
  36. if itemstack:get_count() == 0 then
  37. minetest.after(0.20,
  38. farming.refill_plant,
  39. placer,
  40. "farming:grapes",
  41. placer:get_wield_index()
  42. )
  43. end
  44. end
  45. return itemstack
  46. end
  47. -- grapes
  48. minetest.register_craftitem("farming:grapes", {
  49. description = S("Grapes"),
  50. inventory_image = "farming_grapes.png",
  51. on_use = minetest.item_eat(2),
  52. groups = {seed = 2, food_grapes = 1, flammable = 3},
  53. on_place = function(itemstack, placer, pointed_thing)
  54. return place_grapes(itemstack, placer, pointed_thing, "farming:grapes_1")
  55. end,
  56. })
  57. -- grapes can be used for violet dye
  58. minetest.register_craft({
  59. output = "dye:violet",
  60. recipe = {
  61. {"farming:grapes"},
  62. }
  63. })
  64. -- trellis
  65. minetest.register_node("farming:trellis", {
  66. description = S("Trellis (place on soil before planting grapes)"),
  67. drawtype = "plantlike",
  68. tiles = {"farming_trellis.png"},
  69. inventory_image = "farming_trellis.png",
  70. visual_scale = 1.9, -- 1.45,
  71. paramtype = "light",
  72. walkable = false,
  73. buildable_to = true,
  74. sunlight_propagates = true,
  75. drop = "farming:trellis",
  76. selection_box = farming.select,
  77. groups = {snappy = 3, flammable = 2, attached_node = 1},
  78. sounds = default.node_sound_leaves_defaults(),
  79. on_place = function(itemstack, placer, pointed_thing)
  80. local pt = pointed_thing
  81. -- check if pointing at a node
  82. if not pt or pt.type ~= "node" then
  83. return
  84. end
  85. local under = minetest.get_node(pt.under)
  86. -- return if any of the nodes are not registered
  87. if not minetest.registered_nodes[under.name] then
  88. return
  89. end
  90. -- am I right-clicking on something that has a custom on_place set?
  91. -- thanks to Krock for helping with this issue :)
  92. local def = minetest.registered_nodes[under.name]
  93. if def and def.on_rightclick then
  94. return def.on_rightclick(pt.under, under, placer, itemstack)
  95. end
  96. if minetest.is_protected(pt.above, placer:get_player_name()) then
  97. return
  98. end
  99. local nodename = under.name
  100. if minetest.get_item_group(nodename, "soil") < 2 then
  101. return
  102. end
  103. local top = {
  104. x = pointed_thing.above.x,
  105. y = pointed_thing.above.y + 1,
  106. z = pointed_thing.above.z
  107. }
  108. nodename = minetest.get_node(top).name
  109. if nodename ~= "air" then
  110. return
  111. end
  112. minetest.set_node(pointed_thing.above, {name = "farming:trellis"})
  113. if not farming.is_creative(placer:get_player_name()) then
  114. itemstack:take_item()
  115. end
  116. return itemstack
  117. end
  118. })
  119. minetest.register_craft({
  120. output = "farming:trellis",
  121. recipe = {
  122. {"default:stick", "default:stick", "default:stick"},
  123. {"default:stick", "default:stick", "default:stick"},
  124. {"default:stick", "default:stick", "default:stick"},
  125. }
  126. })
  127. minetest.register_craft({
  128. type = "fuel",
  129. recipe = "farming:trellis",
  130. burntime = 15,
  131. })
  132. -- grapes definition
  133. local crop_def = {
  134. drawtype = "plantlike",
  135. tiles = {"farming_grapes_1.png"},
  136. visual_scale = 1.9, -- 1.45,
  137. paramtype = "light",
  138. walkable = false,
  139. buildable_to = true,
  140. sunlight_propagates = true,
  141. drop = {
  142. items = {
  143. {items = {"farming:trellis"}, rarity = 1},
  144. }
  145. },
  146. selection_box = farming.select,
  147. groups = {
  148. snappy = 3, flammable = 3, not_in_creative_inventory = 1,
  149. attached_node = 1, growing = 1, plant = 1
  150. },
  151. sounds = default.node_sound_leaves_defaults()
  152. }
  153. -- stage 1
  154. minetest.register_node("farming:grapes_1", table.copy(crop_def))
  155. -- stage2
  156. crop_def.tiles = {"farming_grapes_2.png"}
  157. minetest.register_node("farming:grapes_2", table.copy(crop_def))
  158. -- stage 3
  159. crop_def.tiles = {"farming_grapes_3.png"}
  160. minetest.register_node("farming:grapes_3", table.copy(crop_def))
  161. -- stage 4
  162. crop_def.tiles = {"farming_grapes_4.png"}
  163. minetest.register_node("farming:grapes_4", table.copy(crop_def))
  164. -- stage 5
  165. crop_def.tiles = {"farming_grapes_5.png"}
  166. minetest.register_node("farming:grapes_5", table.copy(crop_def))
  167. -- stage 6
  168. crop_def.tiles = {"farming_grapes_6.png"}
  169. minetest.register_node("farming:grapes_6", table.copy(crop_def))
  170. -- stage 7
  171. crop_def.tiles = {"farming_grapes_7.png"}
  172. minetest.register_node("farming:grapes_7", table.copy(crop_def))
  173. -- stage 8 (final)
  174. crop_def.tiles = {"farming_grapes_8.png"}
  175. crop_def.groups.growing = 0
  176. crop_def.drop = {
  177. items = {
  178. {items = {"farming:trellis"}, rarity = 1},
  179. {items = {"farming:grapes 3"}, rarity = 1},
  180. {items = {"farming:grapes 1"}, rarity = 2},
  181. {items = {"farming:grapes 1"}, rarity = 3},
  182. }
  183. }
  184. minetest.register_node("farming:grapes_8", table.copy(crop_def))
  185. -- add to registered_plants
  186. farming.registered_plants["farming:grapes"] = {
  187. crop = "farming:grapes",
  188. seed = "farming:grapes",
  189. minlight = 13,
  190. maxlight = 15,
  191. steps = 8
  192. }
  193. -- wild grape vine (this is what you find on the map)
  194. minetest.register_node("farming:grapebush", {
  195. drawtype = "plantlike",
  196. tiles = {"farming_grapebush.png"},
  197. paramtype = "light",
  198. waving = 1,
  199. walkable = false,
  200. buildable_to = true,
  201. sunlight_propagates = true,
  202. drop = {
  203. items = {
  204. {items = {"farming:grapes 1"}, rarity = 1},
  205. {items = {"farming:grapes 1"}, rarity = 2},
  206. {items = {"farming:grapes 1"}, rarity = 3},
  207. }
  208. },
  209. selection_box = farming.select,
  210. groups = {
  211. snappy = 3, flammable = 2, plant = 1, attached_node = 1,
  212. not_in_creative_inventory=1
  213. },
  214. sounds = default.node_sound_leaves_defaults(),
  215. })