From 3330fe3643da41d6f35492f195a62e2b2781c64a Mon Sep 17 00:00:00 2001 From: Lemon Slemon Date: Sun, 3 May 2015 15:13:20 -0700 Subject: [PATCH] first commit --- README.md | 1 + depends.txt | 1 + init.lua | 49 ++++++++++++++++++++++++++++++++ init.lua.example | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 README.md create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 init.lua.example diff --git a/README.md b/README.md new file mode 100644 index 0000000..f34bcb2 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# gen diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..ec843f7 --- /dev/null +++ b/init.lua @@ -0,0 +1,49 @@ +-- fairly imperfect code + +local c_air = minetest.get_content_id("air") +local c_water = minetest.get_content_id("default:water_source") +local c_stone = minetest.get_content_id("default:stone") +local c_dirt = minetest.get_content_id("default:dirt") +local c_dirt_with_grass = minetest.get_content_id("default:dirt_with_grass") + +minetest.register_on_generated(function(minp, maxp, seed) + + local x0,z0,x1,z1 = minp.x,minp.z,maxp.x,maxp.z -- Assume X and Z lengths are equal + + t1 = os.clock() + local geninfo = "[mg] generates..." + print(geninfo) + minetest.chat_send_all(geninfo) + + local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") + local data = vm:get_data() + local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} + + for x=minp.x,maxp.x,1 do + for z=minp.z,maxp.z,1 do + for y=minp.y,maxp.y,1 do + local p_pos = area:index(x, y, z) + local x = x/10 + local land_base = 10*math.abs(x + math.sin(x) + math.sin(x + math.sin(x))) + if y == math.floor(land_base) then + data[p_pos] = c_dirt_with_grass + elseif y == math.floor(land_base) - 1 then + data[p_pos] = c_dirt + elseif y < land_base then + data[p_pos] = c_stone + elseif y < 30 then + data[p_pos] = c_water + end + end + end + end + + vm:set_data(data) + vm:calc_lighting() + vm:update_liquids() + vm:write_to_map() + + local geninfo = string.format("[mg] done after: %.2fs", os.clock() - t1) + print(geninfo) + minetest.chat_send_all(geninfo) +end) diff --git a/init.lua.example b/init.lua.example new file mode 100644 index 0000000..a493af6 --- /dev/null +++ b/init.lua.example @@ -0,0 +1,72 @@ +-- fairly imperfect code + +local c_air = minetest.get_content_id("air") +local c_water = minetest.get_content_id("default:water_source") +local c_stone = minetest.get_content_id("default:stone") + +local river_rarity = 0.1 +local river_scale = 10 + +local perlin_scale = river_rarity*river_scale*100 +local inverted_rarity = 1-river_rarity + +minetest.register_on_generated(function(minp, maxp, seed) + + --avoid calculating perlin noises for unneeded places + if maxp.y <= -150 + or minp.y >= 150 then + return + end + + local perlin1 = minetest.get_perlin(11,3, 0.5, perlin_scale) --Get map specific perlin + local x0,z0,x1,z1 = minp.x,minp.z,maxp.x,maxp.z -- Assume X and Z lengths are equal + + if not ( perlin1:get2d( {x=x0, y=z0} ) > inverted_rarity ) --top left + and not ( perlin1:get2d( { x = x0 + ( (x1-x0)/2), y=z0 } ) > inverted_rarity )--top middle + and not (perlin1:get2d({x=x1, y=z1}) > inverted_rarity) --bottom right + and not (perlin1:get2d({x=x1, y=z0+((z1-z0)/2)}) > inverted_rarity) --right middle + and not (perlin1:get2d({x=x0, y=z1}) > inverted_rarity) --bottom left + and not (perlin1:get2d({x=x1, y=z0}) > inverted_rarity) --top right + and not (perlin1:get2d({x=x0+((x1-x0)/2), y=z1}) > inverted_rarity) --left middle + and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > inverted_rarity) --middle + and not (perlin1:get2d({x=x0, y=z1+((z1-z0)/2)}) > inverted_rarity) then --bottom middle + return + end + + t1 = os.clock() + local geninfo = "[mg] generates..." + print(geninfo) + minetest.chat_send_all(geninfo) + + + local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") + local data = vm:get_data() + local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} + + for x=minp.x,maxp.x,1 do + for z=minp.z,maxp.z,1 do + local test = math.abs(perlin1:get2d({x=x, y=z})) + if test <= 0.1 then + for y=minp.y,maxp.y,1 do + local p_pos = area:index(x, y, z) + if y <= test*100-10 then + data[p_pos] = c_stone + elseif y <= 1 then + data[p_pos] = c_water + else + data[p_pos] = c_air + end + end + end + end + end + + vm:set_data(data) + vm:calc_lighting() + vm:update_liquids() + vm:write_to_map() + + local geninfo = string.format("[mg] done after: %.2fs", os.clock() - t1) + print(geninfo) + minetest.chat_send_all(geninfo) +end)