grains.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. morecrops.register_grain = function(opts)
  2. local name = opts.name
  3. local desc = opts.description
  4. local foodvalue = opts.foodvalue
  5. local stagecnt = opts.stages
  6. local seed_1 = opts.seedchance[0]
  7. local seed_2 = opts.seedchance[1]
  8. local fruit_1 = opts.fruitchance[0]
  9. local fruit_2 = opts.fruitchance[1]
  10. local maxdrops = opts.maxdrops
  11. -- seeds
  12. minetest.register_craftitem("morecrops:"..name.."_seed", {
  13. description = desc.." Seeds",
  14. inventory_image = "morecrops_"..name.."_seed.png",
  15. on_place = function(itemstack, placer, pointed_thing)
  16. local above = minetest.env:get_node(pointed_thing.above)
  17. if above.name == "air" then
  18. above.name = "morecrops:"..name.."_1"
  19. minetest.env:set_node(pointed_thing.above, above)
  20. itemstack:take_item(1)
  21. return itemstack
  22. end
  23. end
  24. })
  25. -- produce
  26. minetest.register_craftitem("morecrops:"..name.."_item", {
  27. description = desc,
  28. inventory_image = "morecrops_"..name.."_item.png",
  29. on_use = minetest.item_eat(foodvalue),
  30. })
  31. -- ripe plant
  32. minetest.register_node("morecrops:"..name, {
  33. paramtype = "light",
  34. walkable = false,
  35. drawtype = "plantlike",
  36. drop = "",
  37. tiles = {"morecrops_"..name..".png"},
  38. selection_box = {
  39. type = "fixed",
  40. fixed = {
  41. -- need to fix nodebox adjusting
  42. {-0.5, -0.5, -0.5, 0.5, -0.5+5/16, 0.5}
  43. },
  44. },
  45. drop = {
  46. max_items = maxdrops,
  47. items = {
  48. { items = {'morecrops:'..name..'_seed'} },
  49. { items = {'morecrops:'..name..'_seed'}, rarity = seed_1},
  50. { items = {'morecrops:'..name..'_seed'}, rarity = seed_2},
  51. { items = {'morecrops:'..name..'_item'} },
  52. { items = {'morecrops:'..name..'_item'}, rarity = fruit_1 },
  53. { items = {'morecrops:'..name..'_item'}, rarity = fruit_2 }
  54. }
  55. },
  56. groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1,ripeplant=1 },
  57. sounds = default.node_sound_leaves_defaults(),
  58. })
  59. -- growth stages
  60. for lvl = 1, stagecnt, 1 do
  61. minetest.register_node("morecrops:rhubarb_"..stagecnt, {
  62. paramtype = "light",
  63. walkable = false,
  64. drawtype = "plantlike",
  65. drop = "",
  66. tiles = {"morecrops_"..name.."_"..stagecnt..".png"},
  67. selection_box = {
  68. type = "fixed",
  69. fixed = {
  70. -- need to fix nodebox adjusting
  71. {-0.5, -0.5, -0.5, 0.5, -0.5+5/16, 0.5}
  72. },
  73. },
  74. groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1,growingcrop=1 },
  75. sounds = default.node_sound_leaves_defaults(),
  76. })
  77. end
  78. end