From 79d178bc57aff448d78af3104982f2f87362f6f5 Mon Sep 17 00:00:00 2001 From: Gael-de-Sailly Date: Sat, 24 Oct 2015 21:19:32 +0200 Subject: [PATCH] Activated plants API --- README.md | 21 ++++++++++++++++++++- mapgen.lua | 37 ++++++++++++++++++++++++++++++++++++- plants_api.lua | 2 +- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c56183..75f5a3a 100644 --- a/README.md +++ b/README.md @@ -56,4 +56,23 @@ Mod created by Gael-de-Sailly and now mainly developed by duane-r. * Added… this changelog :-D ### 1.0 (Saturday March 7, 2015) -* Created mapgen (using 7 noises at the moment). \ No newline at end of file +* 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(), + }) diff --git a/mapgen.lua b/mapgen.lua index 3216a44..f3a4bfd 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -465,7 +465,7 @@ function vmg.generate(minp, maxp, seed) data[ivm2] = c_snow_layer -- set node above to snow 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 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 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 + y = y - 1 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 @@ -760,6 +793,8 @@ end) -- Trees are registered in a separate file dofile(vmg.path .. "/trees.lua") +dofile(vmg.path .. "/plants_api.lua") +dofile(vmg.path .. "/plants.lua") function vmg.get_humidity_raw(pos) local v13 = vmg.get_noise(pos, 13) -- Clayey soil : wetter diff --git a/plants_api.lua b/plants_api.lua index 8b1a657..ce8b27f 100644 --- a/plants_api.lua +++ b/plants_api.lua @@ -32,7 +32,7 @@ function vmg.choose_generate_plant(conditions, pos, data, area, ivm) local rand = math.random() -- Random number to choose the plant for _, plant in ipairs(vmg.registered_plants) do -- for each registered plant 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 < plant.density then local grow = plant.grow