Skip to content

Commit

Permalink
Save parameter per world in superflat.txt
Browse files Browse the repository at this point in the history
Little fix at saving blockcache. Add more example. Update README. Add
README in plain text.
  • Loading branch information
srifqi committed Jun 10, 2015
1 parent a5cd62e commit adcda98
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
56 changes: 56 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -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"

29 changes: 21 additions & 8 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion parameter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions parsetext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit adcda98

Please sign in to comment.