crops.lua 7.6 KB

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