diff --git a/README.md b/README.md index 3559ab0..1b8704e 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,16 @@ CC 1.0 Universal (see LICENSE file) - Change `sflat.Y_ORIGIN` to adjust where first layer is (default: 1) - Change `sflat.BLOCKS` to adjust the layer of map (code: from bottom to top;biome,decoration) (examples available) +###Modify existed world +- Open superflat.txt file in your world's folder +- Do like opening parameter.lua file + ##`sflat.BLOCKS` code's Built-in Preset |Preset|Code |------|---- |Example|`"node:name_bottom=amount,node:name_top=amount"` |Example (+decoration)|`"node:name_bottom=amount,node:name_top=amount;Biome,decoration"` +|Forest|`"superflat:bedrock=1,default:dirt=2,default:dirt_with_grass=1;Forest,decoration"` |Default superflat|`"superflat:bedrock=1,default:dirt=2,default:dirt_with_grass=1"` |Shallow Underground|`"superflat:bedrock=1,default:stone=230,default:dirt=5,default:dirt_with_grass=1"` |Deep Underground|`"superflat:bedrock=1,default:stone=920,default:dirt=10,default:dirt_with_grass=1"` diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..372b0db --- /dev/null +++ b/README.txt @@ -0,0 +1,56 @@ +(Yet Another) Superflat Map Generator [superflat] +========= + +#License +CC 1.0 Universal (see LICENSE file) + +#Feature +- This mod will create customizable world's layers' world +- Decoration (optional) +- If you're falling, you will be returned to surface + +#How To Modify +- Open parameter.lua file +- Change `sflat.Y_ORIGIN` to adjust where first layer is (default: 1) +- Change `sflat.BLOCKS` to adjust the layer of map (code: from bottom to top;biome,decoration) (examples available) + +##Modify existed world +- Open superflat.txt file in your world's folder +- Do like opening parameter.lua file + +#sflat.BLOCKS code's Built-in Preset +Preset + Code + +Example + "node:name_bottom=amount,node:name_top=amount" +Example (+decoration) + "node:name_bottom=amount,node:name_top=amount;Biome,decoration" + +Forest + "superflat:bedrock=1,default:dirt=2,default:dirt_with_grass=1;Forest,decoration" +Default superflat + "superflat:bedrock=1,default:dirt=2,default:dirt_with_grass=1" +Shallow Underground + "superflat:bedrock=1,default:stone=230,default:dirt=5,default:dirt_with_grass=1" +Deep Underground + "superflat:bedrock=1,default:stone=920,default:dirt=10,default:dirt_with_grass=1" +Very Deep Underground + "superflat:bedrock=1,default:stone=3680,default:dirt=15,default:dirt_with_grass=1" +Bottomless Pit + "default:cobble=2,default:dirt=3,default:dirt_with_grass=1" +Shallow Sea + "superflat:bedrock=1,default:dirt=3,default:water_source=5" +Sea + "superflat:bedrock=1,default:dirt=3,default:water_source=10" +Deep Sea + "superflat:bedrock=1,default:dirt=3,default:water_source=20" +Water World + "superflat:bedrock=1,default:dirt=3,default:water_source=60" +Beach + "superflat:bedrock=1,default:sand=3,default:water_source=1" +Desert superflat + "superflat:bedrock=1,default:desert_sand=3" +Farmer's dream + "superflat:bedrock=1,default:water_source=1,farming:soil_wet=1" + diff --git a/init.lua b/init.lua index 1e84684..f85db67 100644 --- a/init.lua +++ b/init.lua @@ -27,10 +27,23 @@ minetest.register_node("superflat:bedrock", { sounds = default.node_sound_stone_defaults() }) +-- Read and check if superflat.txt file exists +-- Current bug: If no text at superflat.txt, it will not run and throw error when parsing +if file_exists(minetest.get_worldpath()..DIR_DELIM.."superflat.txt") == true then + dofile(minetest.get_worldpath()..DIR_DELIM.."superflat.txt") +else + local list = io.open(minetest.get_worldpath()..DIR_DELIM.."superflat.txt", "w") + list:write( + "sflat.Y_ORIGIN = "..sflat.Y_ORIGIN.."\n".. + "sflat.BLOCKS = \""..sflat.BLOCKS.."\"" + ) + list:close() +end + local pBLOCKS = sflat.parsetext(sflat.BLOCKS) local blockcache = {minetest.get_content_id("air")} for i=1,#pBLOCKS do - blockcache[i+1] = minetest.get_content_id(pBLOCKS[i]) + blockcache[i] = minetest.get_content_id(pBLOCKS[i]) end minetest.register_on_generated(function(minp, maxp, seed) @@ -44,23 +57,23 @@ minetest.register_on_generated(function(minp, maxp, seed) local data = vm:get_data() local pr = PseudoRandom(seed+1) - --generate layers + -- Generate layers for z = minp.z, maxp.z do for x = minp.x, maxp.x do for y = minp.y, maxp.y do local vi = area:index(x, y, z) if (y >= sflat.Y_ORIGIN and y < sflat.Y_ORIGIN + #pBLOCKS) then - data[vi] = blockcache[y - sflat.Y_ORIGIN + 2] + data[vi] = blockcache[y - sflat.Y_ORIGIN + 1] else - data[vi] = blockcache[1] -- air + -- air end end end end - -- if decoration enabled + -- If decoration enabled if sflat.options.decoration == true then - --decorate terrain + -- Decorate terrain sflat.decoration.generate(minp, maxp, pBLOCKS, data, area, seed, pr) end @@ -81,9 +94,9 @@ minetest.register_globalstep(function(dtime) sflat.bedrock_timer = 1 local pos = player:getpos() if pos.y < sflat.Y_ORIGIN-1 then - -- teleport them back to surface + -- Teleport them back to surface player:setpos({x=pos.x,y=#pBLOCKS+2,z=pos.z}) - -- build first layers under them + -- Build first layers under them if minetest.env:get_node({x=pos.x,y=sflat.Y_ORIGIN,z=pos.z}).name == "air" then minetest.env:set_node({x=pos.x,y=0,z=pos.z}, {name=pBLOCKS[1]}) end diff --git a/parameter.lua b/parameter.lua index 1257f7c..9c49983 100644 --- a/parameter.lua +++ b/parameter.lua @@ -3,18 +3,26 @@ -- Modify parameter here -- --------------------------- +-- Only works for new world +-- For existed world, edit superflat.txt file in your world's folder + +-- Start of the superflat layers sflat.Y_ORIGIN = 1 +-- What form is the layer sflat.BLOCKS = "superflat:bedrock=1,default:dirt=2,default:dirt_with_grass=1" --[[ -- EXAMPLE "node:name_bottom=amount,node:name_top=amount" - "node:name_bottom=amount,node:name_top=amount;Biome,decoration" + "node:name_bottom=amount,node:name_top=amount;Biome,decoration" (with decoration) -- DEFAULT SUPERFLAT "superflat:bedrock=1,default:dirt=2,default:dirt_with_grass=1" +-- SUPERFLAT: Forest + "superflat:bedrock=1,default:dirt=2,default:dirt_with_grass=1;Forest,decoration" + -- SUPERFLAT: Shallow Underground "superflat:bedrock=1,default:stone=230,default:dirt=5,default:dirt_with_grass=1" diff --git a/parsetext.lua b/parsetext.lua index 36199a9..1c0288b 100644 --- a/parsetext.lua +++ b/parsetext.lua @@ -6,6 +6,7 @@ -- Minetest library function string:split(sep) local sep, fields = sep or ",", {} local pattern = string.format("([^%s]+)", sep) self:gsub(pattern, function(c) fields[#fields+1] = c end) return fields end +function file_exists(filename)local f=io.open(filename, "r");if f==nil then return false else f:close() return true end end function sflat.parsetext(text) if text:split(";")[2] ~= nil then