crops.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. --[[
  2. Loading of crop definition stored in a csv file.
  3. The import is extendable, so new columns in the config file are imported to new field in the table.
  4. First line: Header
  5. Second line should be default crop, where several default values are stored.
  6. Actual columns:
  7. Name Name of the crop. Is used for registering all nodes and craftitems
  8. Enabled void crop is not registered in the game
  9. an value crop is registered with configured features
  10. hijack text Which crop of other mod should be hijacked (not to use in mod:farming)
  11. next_plant text For wild crop the name of the cultured crop. By change you get the seed or harvest of the cultured one
  12. Should be a name of another crop in this list
  13. Rarety How often the crop spawn in the wild
  14. Rarety_grass_drop Change to get crop as drop item when digging grass
  15. Rarety_junglegrass_drop Change to get crop as drop item when digging jungle grass
  16. Steps Amount of steps the growing needs till full grown plant. Must be set
  17. harvest_max Max. amount of harvest or seed you can dig out of full grown plant
  18. eat_hp eat health point: How many HP you get by eating the seed.
  19. to_culture void crop can be generated during mapgen and spawn randomly on grassland
  20. any value crop can not be find randomly on the map. The seed has to be found in the wild form or crafted.
  21. to_dig void
  22. any value
  23. has_harvest void drops seed which can be used for planting new crops
  24. any value drops harvest, where the seed has to be crafted out of the harvest
  25. on_soil void can be planted everywhere where the conditions are met (temperature etc.)
  26. any value crap can be found in the wild, but planted only on wet soil,
  27. without checking for temperature etc.
  28. punchable void the plant has to be dug to get harvest or seed
  29. any value by punching the last step of the crop, you get one seed and the plant change
  30. to second last stage
  31. infectable void
  32. any value the plant can be infected, where the crop does not give any seed or harvest
  33. and may infect other crops nearby
  34. Higher values means more infectable
  35. wiltable void
  36. 1 Wilt is going one step back, like Berries: They loose the fruits, but grow again
  37. 2 Plant wilt and remove itself after time. During wilt you can harvest straw if defined.
  38. For grain
  39. 3 crop is spreading seed around and go one step back or dies like nettles
  40. is_bush void
  41. any value define a bush with a mesh instead of tiles
  42. infection_defense
  43. any value can protect nearby crop against infection. value give range of protection
  44. seed_extractable
  45. any value crop gives normally only harvest, out of which no seeds can be crafted, like tea.
  46. no_seed void
  47. any value
  48. use_flail void
  49. any value extension to define crafting recipe: With flail you get the seeds out of harvest
  50. and kind of fibres/straw
  51. use_trellis void
  52. any value the crop needs kind of trellis for growing. the trellis is recyclable:
  53. You get the trellis back by digging the plant at any stage.
  54. for_coffee void
  55. any value extension to define crafting recipes to brew coffee out of seed
  56. for_flour void
  57. any value extension to define crafting recipes to craft normal flour out of seed
  58. seed_roastable
  59. any value seed can be roasted in a oven, needs "crop_roasted.png"
  60. value is used as roast time
  61. seed_grindable
  62. any value seed can be grinded, e.g. in a coffee grinder, needs "crop_grind.png" or value in grind
  63. damage_per_second
  64. any value damage a player get while in a node with this crop, e.g. thorns of raspberries
  65. liquid_viscosity
  66. any value resistance a player sees while walking through a field
  67. temperature_min/_max Range of temperature inside the crop can grow.
  68. humidity_min/_max Range of humidity
  69. elevation_min/_max Height range the crop can be found
  70. light_min Minimun amount of light needed for growing. Crop can be planted only on placed
  71. where light_min is reached at midday. It is also needed for calculating the grow_time.
  72. With more light at midday the crop grows faster.
  73. light_max If node light exceed this value after grow time, the timer starts again without growing.
  74. infect_rate_base Normal infect rate for crops
  75. infect_rate_monoculture Infect rate if many crops are standing nearby.
  76. spread_rate Full grown crops can spread to neighbor block
  77. grow_time_mean mean grow time to next step
  78. wilt_time Time for wilt of a crop
  79. straw text extension for using flail: item name of fibre to craft out of harvest beside seeds
  80. culture_rate rate to get cultured variant out of wild form.
  81. seed_drop name of seed you get from plant: grapes drops seed which normally lead to wild wine.
  82. Only with a trellis you get cultured whine with higher harvest.
  83. With normal grapes and a trellis you get the "seed" for cultured wine.
  84. grind name of item for grinded seed
  85. ]]
  86. local S = farming.intllib
  87. farming.path = minetest.get_modpath("farming")
  88. local has_value = basic_functions.has_value
  89. local crop_cols={
  90. col_num={"rarety","steps","harvest_max","eat_hp",
  91. "temperature_min","temperature_max","humidity_min","humidity_max",
  92. "elevation_min","elevation_max","light_min","light_max",
  93. "infect_rate_base","infect_rate_monoculture","spread_rate","grow_time_mean","roast_time","wilt_time","rarety_grass_drop"},
  94. groups_num={"to_culture","to_dig","has_harvest","on_soil","punchable","infectable","is_bush",
  95. "seed_extractable","use_flail","use_trellis","snappy","infection_defence","seed_roastable",
  96. "seed_grindable","for_flour","for_coffee","damage_per_second","liquid_viscosity","wiltable"}}
  97. local crop_definition = basic_functions.import_csv(farming.path.."/crops.txt",crop_cols)
  98. -- for the default entry is checked, which numeric values are filled
  99. -- this values are copied into void fields of the crops
  100. if crop_definition["default"] ~= nil then
  101. default_crop = crop_definition["default"]
  102. local test_values = {}
  103. -- check, which numeric columns exist in default entry
  104. for i,d in pairs(crop_cols.col_num) do
  105. if default_crop[d] ~= nil then
  106. table.insert(test_values,1,d)
  107. end
  108. end
  109. -- check for each crop, if value can be copied from default entry
  110. for i,tdef in pairs(crop_definition) do
  111. if tdef.name ~= default_crop.name then
  112. for j,colu in pairs(test_values) do
  113. if tdef[colu] == nil then
  114. crop_definition[tdef.name][colu] = default_crop[colu]
  115. end
  116. end
  117. end
  118. end
  119. end
  120. -- register crops
  121. for i,tdef in pairs(crop_definition) do
  122. if i ~= "default" then
  123. -- only register when crop is enabled
  124. if tdef.enabled then
  125. local starttime=os.clock()
  126. farming.register_plant(tdef)
  127. print("farming registering "..tdef.name.." in "..(math.floor(1000000*(os.clock()-starttime))/1000).." milliseconds")
  128. else
  129. print("farming "..tdef.name.." disabled")
  130. end
  131. end
  132. end
  133. local no_items=tonumber(#farming.grass_drop.items)
  134. local tgd={items={}}
  135. for i,gdrop in pairs(farming.grass_drop.items) do
  136. if gdrop.rarity ~= nil then
  137. gdrop.rarity=gdrop.rarity * (1 + no_items - tonumber(i))
  138. end
  139. table.insert(tgd.items,gdrop)
  140. end
  141. minetest.override_item("default:grass_5",{drop=tgd})
  142. minetest.override_item("default:grass_4",{drop=tgd})
  143. local no_items=tonumber(#farming.junglegrass_drop.items)
  144. local tgd={items={}}
  145. for i,gdrop in pairs(farming.junglegrass_drop.items) do
  146. if gdrop.rarity ~= nil then
  147. gdrop.rarity=gdrop.rarity * (1 + no_items - tonumber(i))
  148. end
  149. table.insert(tgd.items,gdrop)
  150. end
  151. minetest.override_item("default:junglegrass",{drop=tgd})