grapes.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 = {{"farming:grapes"}}
  61. })
  62. -- trellis
  63. minetest.register_node("farming:trellis", {
  64. description = S("Trellis (place on soil before planting grapes)"),
  65. drawtype = "plantlike",
  66. tiles = {"farming_trellis.png"},
  67. inventory_image = "farming_trellis.png",
  68. visual_scale = 1.9,
  69. paramtype = "light",
  70. walkable = false,
  71. buildable_to = true,
  72. sunlight_propagates = true,
  73. drop = "farming:trellis",
  74. selection_box = farming.select,
  75. groups = {snappy = 3, flammable = 2, attached_node = 1},
  76. sounds = default.node_sound_leaves_defaults(),
  77. on_place = function(itemstack, placer, pointed_thing)
  78. local pt = pointed_thing
  79. -- check if pointing at a node
  80. if not pt or pt.type ~= "node" then
  81. return
  82. end
  83. local under = minetest.get_node(pt.under)
  84. -- return if any of the nodes are not registered
  85. if not minetest.registered_nodes[under.name] then
  86. return
  87. end
  88. -- am I right-clicking on something that has a custom on_place set?
  89. -- thanks to Krock for helping with this issue :)
  90. local def = minetest.registered_nodes[under.name]
  91. if def and def.on_rightclick then
  92. return def.on_rightclick(pt.under, under, placer, itemstack)
  93. end
  94. if minetest.is_protected(pt.above, placer:get_player_name()) then
  95. return
  96. end
  97. local nodename = under.name
  98. if minetest.get_item_group(nodename, "soil") < 2 then
  99. return
  100. end
  101. local top = {
  102. x = pointed_thing.above.x,
  103. y = pointed_thing.above.y + 1,
  104. z = pointed_thing.above.z
  105. }
  106. nodename = minetest.get_node(top).name
  107. if nodename ~= "air" then
  108. return
  109. end
  110. minetest.set_node(pointed_thing.above, {name = "farming:trellis"})
  111. if not farming.is_creative(placer:get_player_name()) then
  112. itemstack:take_item()
  113. end
  114. return itemstack
  115. end
  116. })
  117. minetest.register_craft({
  118. output = "farming:trellis",
  119. recipe = {
  120. {"default:stick", "default:stick", "default:stick"},
  121. {"default:stick", "default:stick", "default:stick"},
  122. {"default:stick", "default:stick", "default:stick"}
  123. }
  124. })
  125. minetest.register_craft({
  126. type = "fuel",
  127. recipe = "farming:trellis",
  128. burntime = 15
  129. })
  130. -- grapes definition
  131. local def = {
  132. drawtype = "plantlike",
  133. tiles = {"farming_grapes_1.png"},
  134. visual_scale = 1.9,
  135. paramtype = "light",
  136. walkable = false,
  137. buildable_to = true,
  138. sunlight_propagates = true,
  139. drop = {
  140. items = {
  141. {items = {"farming:trellis"}, rarity = 1},
  142. }
  143. },
  144. selection_box = farming.select,
  145. groups = {
  146. snappy = 3, flammable = 3, not_in_creative_inventory = 1,
  147. attached_node = 1, growing = 1, plant = 1
  148. },
  149. sounds = default.node_sound_leaves_defaults()
  150. }
  151. -- stage 1
  152. minetest.register_node("farming:grapes_1", table.copy(def))
  153. -- stage2
  154. def.tiles = {"farming_grapes_2.png"}
  155. minetest.register_node("farming:grapes_2", table.copy(def))
  156. -- stage 3
  157. def.tiles = {"farming_grapes_3.png"}
  158. minetest.register_node("farming:grapes_3", table.copy(def))
  159. -- stage 4
  160. def.tiles = {"farming_grapes_4.png"}
  161. minetest.register_node("farming:grapes_4", table.copy(def))
  162. -- stage 5
  163. def.tiles = {"farming_grapes_5.png"}
  164. minetest.register_node("farming:grapes_5", table.copy(def))
  165. -- stage 6
  166. def.tiles = {"farming_grapes_6.png"}
  167. minetest.register_node("farming:grapes_6", table.copy(def))
  168. -- stage 7
  169. def.tiles = {"farming_grapes_7.png"}
  170. minetest.register_node("farming:grapes_7", table.copy(def))
  171. -- stage 8 (final)
  172. def.tiles = {"farming_grapes_8.png"}
  173. def.groups.growing = nil
  174. def.drop = {
  175. items = {
  176. {items = {"farming:trellis"}, rarity = 1},
  177. {items = {"farming:grapes 3"}, rarity = 1},
  178. {items = {"farming:grapes 1"}, rarity = 2},
  179. {items = {"farming:grapes 1"}, rarity = 3}
  180. }
  181. }
  182. minetest.register_node("farming:grapes_8", table.copy(def))
  183. -- add to registered_plants
  184. farming.registered_plants["farming:grapes"] = {
  185. crop = "farming:grapes",
  186. seed = "farming:grapes",
  187. minlight = farming.min_light,
  188. maxlight = farming.max_light,
  189. steps = 8
  190. }
  191. -- wild grape vine (this is what you find on the map)
  192. minetest.register_node("farming:grapebush", {
  193. drawtype = "plantlike",
  194. tiles = {"farming_grapebush.png"},
  195. paramtype = "light",
  196. waving = 1,
  197. walkable = false,
  198. buildable_to = true,
  199. sunlight_propagates = true,
  200. drop = {
  201. items = {
  202. {items = {"farming:grapes 1"}, rarity = 1},
  203. {items = {"farming:grapes 1"}, rarity = 2},
  204. {items = {"farming:grapes 1"}, rarity = 3}
  205. }
  206. },
  207. selection_box = farming.select,
  208. groups = {
  209. snappy = 3, flammable = 2, plant = 1, attached_node = 1,
  210. not_in_creative_inventory = 1
  211. },
  212. sounds = default.node_sound_leaves_defaults()
  213. })