beans.lua 6.0 KB

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