beans.lua 5.9 KB

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