From 4b413ccb36f161a7b986262903ab14e4b984f860 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Fri, 20 Mar 2015 14:00:56 +0000 Subject: [PATCH] tidied mapgen --- mapgen.lua | 55 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/mapgen.lua b/mapgen.lua index c7f990b..31e8a47 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -1,13 +1,15 @@ -- Generate new foods on map -minetest.register_on_generated(function(minp, maxp, seed) +function farming.mgv6ongen(minp, maxp, seed) + + if maxp.y < 2 and minp.y > 0 then return end local perlin1 = minetest.get_perlin(329, 3, 0.6, 100) -- Assume X and Z lengths are equal local divlen = 16 - local divs = (maxp.x-minp.x)/divlen+1; + local divs = (maxp.x-minp.x)/divlen+1 for divx=0,divs-1 do for divz=0,divs-1 do @@ -18,12 +20,12 @@ minetest.register_on_generated(function(minp, maxp, seed) local z1 = minp.z + math.floor((divz+1)*divlen) -- Determine plant amount from perlin noise - local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9) + local plant_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9) - -- Find random positions for plant based on this random - local pr = PseudoRandom(seed+1) + -- Find random positions for plant + local pr = PseudoRandom(seed+420) - for i=0,grass_amount do + for i=0,plant_amount do local x = pr:next(x0, x1) local z = pr:next(z0, z1) @@ -44,37 +46,44 @@ minetest.register_on_generated(function(minp, maxp, seed) local nn = minetest.get_node(p).name -- Check if the node can be replaced - if minetest.registered_nodes[nn] and + if minetest.registered_nodes[nn] + and minetest.registered_nodes[nn].buildable_to then - minetest.registered_nodes[nn].buildable_to then nn = minetest.get_node({x=x,y=ground_y,z=z}).name -- If dirt with grass, add plant in various stages of maturity if nn == "default:dirt_with_grass" then local type = math.random(1,11) + local plant + if type == 1 and ground_y > 15 then - minetest.set_node(p,{name="farming:potato_"..pr:next(3, 4)}) + plant = "farming:potato_"..pr:next(3, 4) elseif type == 2 then - minetest.set_node(p,{name="farming:tomato_"..pr:next(7, 8)}) + plant = "farming:tomato_"..pr:next(7, 8) elseif type == 3 then - minetest.set_node(p,{name="farming:carrot_"..pr:next(7, 8)}) + plant = "farming:carrot_"..pr:next(7, 8) elseif type == 4 then - minetest.set_node(p,{name="farming:cucumber_4"}) + plant = "farming:cucumber_4" elseif type == 5 then - minetest.set_node(p,{name="farming:corn_"..pr:next(7, 8)}) + plant = "farming:corn_"..pr:next(7, 8) elseif type == 6 and ground_y > 20 then - minetest.set_node(p,{name="farming:coffee_5"}) + plant = "farming:coffee_5" elseif type == 7 and minetest.find_node_near(p, 3, {"group:water"}) then - minetest.set_node(p,{name="farming:melon_8"}) + plant = "farming:melon_8" elseif type == 8 and ground_y > 15 then - minetest.set_node(p,{name="farming:pumpkin_8"}) + plant = "farming:pumpkin_8" elseif type == 9 and ground_y > 5 then - minetest.set_node(p,{name="farming:raspberry_4"}) + plant = "farming:raspberry_4" elseif type == 10 and ground_y > 10 then - minetest.set_node(p,{name="farming:rhubarb_3"}) + plant = "farming:rhubarb_3" elseif type == 11 and ground_y > 5 then - minetest.set_node(p,{name="farming:blueberry_4"}) + plant = "farming:blueberry_4" + end + + -- Add plant + if plant then + minetest.set_node(p, {name=plant}) end end end @@ -82,4 +91,12 @@ minetest.register_on_generated(function(minp, maxp, seed) end end end +end + +-- Enable in mapgen v6 only (disabled) + +minetest.register_on_mapgen_init(function(mg_params) + --if mg_params.mgname == "v6" then + minetest.register_on_generated(farming.mgv6ongen) + --end end)