Skip to content

Instantly share code, notes, and snippets.

@PilzAdam
Created June 17, 2013 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PilzAdam/5797689 to your computer and use it in GitHub Desktop.
Save PilzAdam/5797689 to your computer and use it in GitHub Desktop.
diff --git a/mods/default/mapgen.lua b/mods/default/mapgen.lua
index 6bde5e0..e49235c 100644
--- a/mods/default/mapgen.lua
+++ b/mods/default/mapgen.lua
@@ -281,6 +281,91 @@ minetest.register_ore({
height_min = -10,
})
+--
+-- Decorations
+--
+
+--papyrus
+minetest.register_decoration({
+ deco_type = "simple",
+ place_on = "default:dirt_with_grass",
+ divlen = 8,
+ decoration = "default:papyrus",
+ height = 2,
+ height_max = 4,
+ noise_params = {
+ offset = -20 / 64,
+ scale = 45 / 64,
+ spread = {x=100, y=100, z=100},
+ seed = 354,
+ octaves = 3,
+ persist = 0.7
+ },
+ spawn_by = "default:water_source",
+ num_spawn_by = 1
+})
+
+--cactuses
+minetest.register_decoration({
+ deco_type = "simple",
+ place_on = "default:desert_sand",
+ divlen = 16,
+ decoration = "default:cactus",
+ height = 3,
+ height_max = 4,
+ noise_params = {
+ offset = -3 / 256,
+ scale = 6 / 256,
+ spread = {x=100, y=100, z=100},
+ seed = 230,
+ octaves = 3,
+ persist = 0.6
+ }
+})
+
+
+--grass
+minetest.register_decoration({
+ deco_type = "simple",
+ place_on = "default:dirt_with_grass",
+ divlen = 16,
+ decoration_list = {
+ "default:grass_1",
+ "default:grass_2",
+ "default:grass_3",
+ "default:grass_4",
+ "default:grass_5"
+ },
+ height = 1,
+ fill_ratio = 0.02,
+ --[[noise_params = {
+ offset = 0,
+ scale = 9 / 256, -- originally ^3 as well...
+ spread = {x=100, y=100, z=100},
+ seed = 329,
+ octaves = 3,
+ persist = 0.6
+ }]]
+})
+
+
+--dry shrubs
+minetest.register_decoration({
+ deco_type = "simple",
+ place_on = "default:desert_sand",
+ divlen = 16,
+ decoration = "default:dry_shrub",
+ height = 1,
+ noise_params = {
+ offset = 0,
+ scale = 9 / 256, -- originally ^3 as well...
+ spread = {x=100, y=100, z=100},
+ seed = 329,
+ octaves = 3,
+ persist = 0.6
+ }
+})
+
function default.generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, chunk_size, ore_per_chunk, height_min, height_max)
minetest.log('action', "WARNING: default.generate_ore is deprecated")
@@ -323,32 +408,6 @@ function default.generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume
--print("generate_ore done")
end
-function default.make_papyrus(pos, size)
- for y=0,size-1 do
- local p = {x=pos.x, y=pos.y+y, z=pos.z}
- local nn = minetest.get_node(p).name
- if minetest.registered_nodes[nn] and
- minetest.registered_nodes[nn].buildable_to then
- minetest.set_node(p, {name="default:papyrus"})
- else
- return
- end
- end
-end
-
-function default.make_cactus(pos, size)
- for y=0,size-1 do
- local p = {x=pos.x, y=pos.y+y, z=pos.z}
- local nn = minetest.get_node(p).name
- if minetest.registered_nodes[nn] and
- minetest.registered_nodes[nn].buildable_to then
- minetest.set_node(p, {name="default:cactus"})
- else
- return
- end
- end
-end
-
-- facedir: 0/1/2/3 (head node facedir value)
-- length: length of rainbow tail
function default.make_nyancat(pos, facedir, length)
@@ -375,7 +434,7 @@ function default.make_nyancat(pos, facedir, length)
end
end
-function generate_nyancats(seed, minp, maxp)
+function generate_nyancats(minp, maxp, seed)
local height_min = -31000
local height_max = -32
if maxp.y < height_min or minp.y > height_max then
@@ -397,117 +456,5 @@ function generate_nyancats(seed, minp, maxp)
end
end
-minetest.register_on_generated(function(minp, maxp, seed)
- if maxp.y >= 2 and minp.y <= 0 then
- -- Generate papyrus
- local perlin1 = minetest.get_perlin(354, 3, 0.7, 100)
- -- Assume X and Z lengths are equal
- local divlen = 8
- local divs = (maxp.x-minp.x)/divlen+1;
- for divx=0,divs-1 do
- for divz=0,divs-1 do
- local x0 = minp.x + math.floor((divx+0)*divlen)
- local z0 = minp.z + math.floor((divz+0)*divlen)
- local x1 = minp.x + math.floor((divx+1)*divlen)
- local z1 = minp.z + math.floor((divz+1)*divlen)
- -- Determine papyrus amount from perlin noise
- local papyrus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 45 - 20)
- -- Find random positions for papyrus based on this random
- local pr = PseudoRandom(seed+1)
- for i=0,papyrus_amount do
- local x = pr:next(x0, x1)
- local z = pr:next(z0, z1)
- if minetest.get_node({x=x,y=1,z=z}).name == "default:dirt_with_grass" and
- minetest.find_node_near({x=x,y=1,z=z}, 1, "default:water_source") then
- default.make_papyrus({x=x,y=2,z=z}, pr:next(2, 4))
- end
- end
- end
- end
- -- Generate cactuses
- local perlin1 = minetest.get_perlin(230, 3, 0.6, 100)
- -- Assume X and Z lengths are equal
- local divlen = 16
- local divs = (maxp.x-minp.x)/divlen+1;
- for divx=0,divs-1 do
- for divz=0,divs-1 do
- local x0 = minp.x + math.floor((divx+0)*divlen)
- local z0 = minp.z + math.floor((divz+0)*divlen)
- local x1 = minp.x + math.floor((divx+1)*divlen)
- local z1 = minp.z + math.floor((divz+1)*divlen)
- -- Determine cactus amount from perlin noise
- local cactus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 6 - 3)
- -- Find random positions for cactus based on this random
- local pr = PseudoRandom(seed+1)
- for i=0,cactus_amount do
- local x = pr:next(x0, x1)
- local z = pr:next(z0, z1)
- -- Find ground level (0...15)
- local ground_y = nil
- for y=30,0,-1 do
- if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
- ground_y = y
- break
- end
- end
- -- If desert sand, make cactus
- if ground_y and minetest.get_node({x=x,y=ground_y,z=z}).name == "default:desert_sand" then
- default.make_cactus({x=x,y=ground_y+1,z=z}, pr:next(3, 4))
- end
- end
- end
- end
- -- Generate grass
- 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;
- for divx=0,divs-1 do
- for divz=0,divs-1 do
- local x0 = minp.x + math.floor((divx+0)*divlen)
- local z0 = minp.z + math.floor((divz+0)*divlen)
- local x1 = minp.x + math.floor((divx+1)*divlen)
- local z1 = minp.z + math.floor((divz+1)*divlen)
- -- Determine grass amount from perlin noise
- local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9)
- -- Find random positions for grass based on this random
- local pr = PseudoRandom(seed+1)
- for i=0,grass_amount do
- local x = pr:next(x0, x1)
- local z = pr:next(z0, z1)
- -- Find ground level (0...15)
- local ground_y = nil
- for y=30,0,-1 do
- if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
- ground_y = y
- break
- end
- end
-
- if ground_y then
- local p = {x=x,y=ground_y+1,z=z}
- local nn = minetest.get_node(p).name
- -- Check if the node can be replaced
- if minetest.registered_nodes[nn] and
- minetest.registered_nodes[nn].buildable_to then
- nn = minetest.get_node({x=x,y=ground_y,z=z}).name
- -- If desert sand, add dry shrub
- if nn == "default:desert_sand" then
- minetest.set_node(p,{name="default:dry_shrub"})
-
- -- If dirt with grass, add grass
- elseif nn == "default:dirt_with_grass" then
- minetest.set_node(p,{name="default:grass_"..pr:next(1, 5)})
- end
- end
- end
-
- end
- end
- end
- end
-
- -- Generate nyan cats
- generate_nyancats(seed, minp, maxp)
-end)
+minetest.register_on_generated(generate_nyancats)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment