Activated plants API
This commit is contained in:
parent
34515907c2
commit
79d178bc57
21
README.md
21
README.md
@ -56,4 +56,23 @@ Mod created by Gael-de-Sailly and now mainly developed by duane-r.
|
|||||||
* Added… this changelog :-D
|
* Added… this changelog :-D
|
||||||
|
|
||||||
### 1.0 (Saturday March 7, 2015)
|
### 1.0 (Saturday March 7, 2015)
|
||||||
* Created mapgen (using 7 noises at the moment).
|
* Created mapgen (using 7 noises at the moment).
|
||||||
|
|
||||||
|
## Plants API
|
||||||
|
The Plants API has been introduced on October 24th, 2015. It allow mods to generate plants directly on the map.
|
||||||
|
|
||||||
|
### How to use it ?
|
||||||
|
First, make sure that you've added the `valleys_mapgen` dependancy in your depends.txt (followed by a quotation mark if optionnal)
|
||||||
|
The only function is `vmg.register_plant`. It registers a plant that will be generated during mapgen.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
Syntax (example for apple tree)
|
||||||
|
|
||||||
|
vmg.register_plant({
|
||||||
|
nodes = {tree = "default:tree", leaves = "default:leaves", fruit = "default:apple"},
|
||||||
|
priority = 54,
|
||||||
|
cover = 0.4,
|
||||||
|
density = 0.05,
|
||||||
|
check_func = function(),
|
||||||
|
grow_func = function(),
|
||||||
|
})
|
||||||
|
37
mapgen.lua
37
mapgen.lua
@ -465,7 +465,7 @@ function vmg.generate(minp, maxp, seed)
|
|||||||
data[ivm2] = c_snow_layer -- set node above to snow
|
data[ivm2] = c_snow_layer -- set node above to snow
|
||||||
end
|
end
|
||||||
|
|
||||||
if trees and math.random() < tree_density and above > 0 then -- make a tree
|
--[[if trees and math.random() < tree_density and above > 0 then -- make a tree
|
||||||
|
|
||||||
-- choose a tree from climatic and geological conditions
|
-- choose a tree from climatic and geological conditions
|
||||||
if v14 < 0 and temp < 1.5 and temp >= 0.90 and humidity < 1 and v15 < 0.8 and math.abs(v13) < 0.2 and math.random() < 0.3 then -- Pine Tree
|
if v14 < 0 and temp < 1.5 and temp >= 0.90 and humidity < 1 and v15 < 0.8 and math.abs(v13) < 0.2 and math.random() < 0.3 then -- Pine Tree
|
||||||
@ -571,7 +571,40 @@ function vmg.generate(minp, maxp, seed)
|
|||||||
data[ivm2] = c_mushroom_fertile_brown
|
data[ivm2] = c_mushroom_fertile_brown
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end]]
|
||||||
|
if above > 0 then
|
||||||
|
local conditions = { -- pack it in a table, for plants API
|
||||||
|
v1 = v1,
|
||||||
|
v2 = v2,
|
||||||
|
v3 = v3,
|
||||||
|
v4 = v4,
|
||||||
|
v5 = v5,
|
||||||
|
v6 = v6,
|
||||||
|
v7 = v7,
|
||||||
|
v8 = v8,
|
||||||
|
v9 = v9,
|
||||||
|
v10 = v10,
|
||||||
|
v11 = v11,
|
||||||
|
v12 = v12,
|
||||||
|
v13 = v13,
|
||||||
|
v14 = v14,
|
||||||
|
v15 = v15,
|
||||||
|
v16 = v16,
|
||||||
|
v17 = v17,
|
||||||
|
v18 = v18,
|
||||||
|
v19 = v19,
|
||||||
|
v20 = v20,
|
||||||
|
temp = temp,
|
||||||
|
humidity = humidity,
|
||||||
|
sea_water = sea_water,
|
||||||
|
river_water = river_water,
|
||||||
|
water = water,
|
||||||
|
thickness = thickness
|
||||||
|
}
|
||||||
|
|
||||||
|
vmg.choose_generate_plant(conditions, pos, data, a, ivm2)
|
||||||
end
|
end
|
||||||
|
|
||||||
y = y - 1
|
y = y - 1
|
||||||
end
|
end
|
||||||
elseif n6[i3d_sup+above*i3d_incrY] * slopes <= y + above - mountain_ground then -- if node at "above" nodes up is not in the ground, make dirt
|
elseif n6[i3d_sup+above*i3d_incrY] * slopes <= y + above - mountain_ground then -- if node at "above" nodes up is not in the ground, make dirt
|
||||||
@ -760,6 +793,8 @@ end)
|
|||||||
|
|
||||||
-- Trees are registered in a separate file
|
-- Trees are registered in a separate file
|
||||||
dofile(vmg.path .. "/trees.lua")
|
dofile(vmg.path .. "/trees.lua")
|
||||||
|
dofile(vmg.path .. "/plants_api.lua")
|
||||||
|
dofile(vmg.path .. "/plants.lua")
|
||||||
|
|
||||||
function vmg.get_humidity_raw(pos)
|
function vmg.get_humidity_raw(pos)
|
||||||
local v13 = vmg.get_noise(pos, 13) -- Clayey soil : wetter
|
local v13 = vmg.get_noise(pos, 13) -- Clayey soil : wetter
|
||||||
|
@ -32,7 +32,7 @@ function vmg.choose_generate_plant(conditions, pos, data, area, ivm)
|
|||||||
local rand = math.random() -- Random number to choose the plant
|
local rand = math.random() -- Random number to choose the plant
|
||||||
for _, plant in ipairs(vmg.registered_plants) do -- for each registered plant
|
for _, plant in ipairs(vmg.registered_plants) do -- for each registered plant
|
||||||
local cover = plant.cover
|
local cover = plant.cover
|
||||||
if plant.check(conditions) then -- Place this plant, or do not place anything (see Cover parameter)
|
if plant.check(conditions, pos) then -- Place this plant, or do not place anything (see Cover parameter)
|
||||||
if rand < cover then
|
if rand < cover then
|
||||||
if rand < plant.density then
|
if rand < plant.density then
|
||||||
local grow = plant.grow
|
local grow = plant.grow
|
||||||
|
Loading…
x
Reference in New Issue
Block a user