local mod_name = minetest.get_current_modname()
local mod_path = minetest.get_modpath(mod_name)
local S = minetest.get_translator(mod_name)

br_core.level = {}
br_core.level_for_index = {}

local function sch(name)
    return (mod_path .. DIR_DELIM .. "schematics" .. DIR_DELIM .. name .. ".mts")
end

function br_core.register_level(p)
    if p.level > 180 then error("CANNOT REGISTER LEVEL "..p.level.." AS IT WOULD EXCEED HEIGHT LIMIT") end
    if not p.biome_names then p.biome_names = {} end
    p.index = #br_core.level_for_index+1
    br_core.level[p.level] = p
    br_core.level_for_index[#br_core.level_for_index+1] = p.level
end
local biome_id_count = 0
function br_core.register_biome(p)
    biome_id_count = biome_id_count + 1
    p.uid = biome_id_count
    p.vert_schems = {}
    p.segheight = p.segheight or 80
    for i, schem in pairs(p.schems) do
        local all_layers = false
        if not schem.vertical_segments then
            schem.vertical_segments = {}
            all_layers = true
        end
        for k=0, math.floor(br_core.chunk_width / p.segheight) + 1 do
            if not p.vert_schems[k] then p.vert_schems[k] = {} end
            if all_layers or schem.vertical_segments[k] == 1 then
                for l=1, schem.prevalence or 1 do
                    p.vert_schems[k][#p.vert_schems[k]+1] = p.schems[i]
                end
            end
        end
    end
    if not br_core.level[p.level].biome then br_core.level[p.level].biome = {} end
    -- make a pointer to the biome so you can reference it by name
    if p.name and not br_core.level[p.level].biome_names[p.name] then
        br_core.level[p.level].biome_names[p.name] = {def=p, index=#br_core.level[p.level].biome+1}
    end
    for i=1, p.prevalence or 1 do
        br_core.level[p.level].biome[#br_core.level[p.level].biome+1] = p
    end
end
function br_core.index_to_level(index)
    return br_core.level_for_index[index]
end

function br_core.sort_levels()
    table.sort(br_core.level_for_index, function(a, b) return a < b end)
    for i, level in pairs(br_core.level_for_index) do
        br_core.level[level].index = i
    end
end

br_core.register_level({
    level = 0,
    desc = "Level 0",
    danger = 1,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 28,
    biome_roughness = 195,
    biome_pixelization = 4,
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})

br_core.register_biome({
    level = 0,
    desc = "Level 0 columns",
    danger = 1,
    on_generate = nil,
    segheight = 20,
    can_generate = function(pos) -- must be deterministic
        if vector.distance(pos, vector.new(0, pos.y, 0)) > 10
        and vector.distance(pos, vector.new(0, pos.y, 0)) < 30 then
            return false
        else
            return true
        end
    end,
    schems = {
        {name=sch("0_20_1_columns_0"), vertical_segments={1,0}},
        {name=sch("0_20_2_columns_0"), vertical_segments={0,1}, rotation="0"},
    }
})
br_core.register_biome({
    level = 0,
    desc = "Level 0 main",
    danger = 1,
    on_generate = nil,
    segheight = 20,
    prevalence = 5,
    schems = {
        {name=sch("0_20_1_columns_0"), vertical_segments={1,0}},
        --
        {name=sch("0_20_2_columns_0"), vertical_segments={0,1}, rotation="0"},
        {name=sch("0_20_2_pitfalls_0"), vertical_segments={0,1}, can_generate=function(pos, perlin)
            return ((pos.x%3==0) and pos.z%2==0)
        end},
        {name=sch("0_20_2_walls_0"), vertical_segments={0,1}},
        {name=sch("0_20_2_walls_1"), vertical_segments={0,1}},
        {name=sch("0_20_2_walls_2"), vertical_segments={0,1}},
        {name=sch("0_20_2_walls_3"), vertical_segments={0,1}},
    }
})
br_core.register_biome({
    level = 0,
    desc = "Level 0 main with doors",
    danger = 1,
    on_generate = nil,
    segheight = 20,
    prevalence = 1,
    schems = {
        {name=sch("0_20_1_columns_0"), vertical_segments={1,0}},
        --
        {name=sch("0_20_2_columns_0"), vertical_segments={0,1}, rotation="0", prevalence=12},
        {name=sch("0_20_2_walls_0"), vertical_segments={0,1}, prevalence=12},
        {name=sch("0_20_2_walls_1"), vertical_segments={0,1}, prevalence=12},
        {name=sch("0_20_2_walls_2"), vertical_segments={0,1}, prevalence=12},
        {name=sch("0_20_2_walls_3"), vertical_segments={0,1}, prevalence=12},
        {name=sch("0_20_2_doors_0"), vertical_segments={0,1}, prevalence=2},
        {name=sch("0_20_2_doors_1"), vertical_segments={0,1}, prevalence=2},
        {name=sch("0_20_2_doors_0_portal"), vertical_segments={0,1}, prevalence=2},
        {name=sch("0_20_2_doors_1_portal"), vertical_segments={0,1}, prevalence=2},
        {name=sch("0_20_2_stairs_0_portal"), vertical_segments={0,1}, prevalence=1},
    }
})
br_core.register_biome({
    level = 0,
    desc = "Level 0 concrete",
    danger = 1,
    on_generate = nil,
    segheight = 20,
    prevalence = 1,
    can_generate = function(pos) -- must be deterministic
        if vector.distance(pos, vector.new(0, pos.y, 0)) > 30 then
            return true
        else
            return false
        end
    end,
    schems = {
        {name=sch("0_20_1_columns_0"), vertical_segments={1,0}},
        --
        {name=sch("0_20_2_walls_concrete_0"), vertical_segments={0,1}, prevalence=9},
        {name=sch("0_20_2_walls_concrete_1"), vertical_segments={0,1}, prevalence=5},
        {name=sch("0_20_2_walls_concrete_1_portal"), vertical_segments={0,1}, prevalence=1},
    }
})
br_core.register_biome({
    level = 0,
    desc = "Level 0 nolight",
    danger = 1,
    on_generate = nil,
    segheight = 20,
    prevalence = 2,
    schems = {
        {name=sch("0_20_1_columns_0"), vertical_segments={1,0}},
        --
        {name=sch("0_20_2_nolight_portal_0"), vertical_segments={0,1}, prevalence=1},
        {name=sch("0_20_2_nolight_walls_0"), vertical_segments={0,1}, prevalence=3},
        {name=sch("0_20_2_nolight_walls_1"), vertical_segments={0,1}, prevalence=3},
        {name=sch("0_20_2_nolight_walls_2"), vertical_segments={0,1}, prevalence=3},
        {name=sch("0_20_2_nolight_columns_0"), vertical_segments={0,1}, prevalence=2},
    }
})
br_core.register_biome({
    level = 0,
    desc = "Level 0 dark",
    danger = 1,
    on_generate = nil,
    segheight = 20,
    prevalence = 1,
    can_generate = function(pos) -- must be deterministic
        if vector.distance(pos, vector.new(0, pos.y, 0)) > 30 then
            return true
        else
            return false
        end
    end,
    schems = {
        {name=sch("0_20_1_columns_0"), vertical_segments={1,0}},
        --
        {name=sch("0_20_2_dark_0"), vertical_segments={0,1}, prevalence=8},
        {name=sch("0_20_2_dark_walls_0"), vertical_segments={0,1}, prevalence=8},
        {name=sch("0_20_2_dark_walls_1"), vertical_segments={0,1}, prevalence=8},
        --
        {name=sch("0_20_2_dark_walls_2"), vertical_segments={0,1}, prevalence=4},
        {name=sch("0_20_2_dark_walls_2_portal"), vertical_segments={0,1}},
    }
})




--[[
====LAYOUT====
br_core.level
    LEVELNAME
        desc
        danger
        biome
            BIOMENAME
                schems
                on_generate
                danger
                desc
                level
]]



br_core.register_level({
    level = 1,
    desc = "Level 1",
    danger = 1,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 20,
    sun = {
        visible = false,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})

br_core.register_biome({
    level = 1,
    desc = "Level 1 columns",
    danger = 1,
    on_generate = nil,
    can_generate = function(pos) -- must be deterministic
        if vector.distance(pos, vector.new(0, pos.y, 0)) > 10 then
            return false
        else
            return true
        end
    end,
    schems = {
        {name=sch("1_open_0"), no_rotation=true},
    }
})
br_core.register_biome({
    level = 1,
    desc = "Level 1 main",
    danger = 1,
    on_generate = nil,
    prevalence = 2,
    schems = {
        {name=sch("1_open_0"), no_rotation=true},
        {name=sch("1_open_1"), no_rotation=true},
        {name=sch("1_open_0"), no_rotation=true},
        {name=sch("1_open_1"), no_rotation=true},
        {name=sch("1_open_0"), no_rotation=true},
        {name=sch("1_open_2")},
        {name=sch("1_open_2")},
        {name=sch("1_building_0")}, --PORTAL
        {name=sch("1_building_1")},
        {name=sch("1_building_2")},
        {name=sch("1_stairs_0")},
        {name=sch("1_ramp_0")},
    }
})
br_core.register_biome({
    level = 1,
    desc = "Level 1 main",
    danger = 1,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("1_stairs_0")},
        {name=sch("1_building_0")}, --PORTAL
        {name=sch("1_building_1")},
        {name=sch("1_building_2")},
        {name=sch("1_building_2")},
        {name=sch("1_building_2")},
        {name=sch("1_open_0"), no_rotation=true},
    }
})


-- pipes
br_core.register_level({
    level = 2,
    desc = "Level 2",
    danger = 3,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 20,
    sun = {
        visible = false,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})

br_core.register_biome({
    level = 2,
    desc = "Level 2 corridors",
    danger = 3,
    on_generate = nil,
    can_generate = function(pos) -- must be deterministic
        if vector.distance(pos, vector.new(0, pos.y, 0)) > 10 then
            return false
        else
            return true
        end
    end,
    schems = {
        {name=sch("2_crossroad_0"), no_rotation=true},
    }
})

br_core.register_biome({
    level = 2,
    desc = "Level 0 main",
    danger = 1,
    on_generate = nil,
    biome_roughness = 1,
    biome_pixelization = 2,
    prevalence = 1,
    schems = {
        {name=sch("2_maze_0"), rotation="0", prevalence=9},
        {name=sch("2_crossroad_0"), rotation="0", prevalence=2},
        {name=sch("2_open_0")},
        {name=sch("2_water_0")},
    }
})

br_core.register_biome({
    level = 2,
    desc = "Level 0 main",
    danger = 1,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("2_blue_1"), rotation="0", prevalence=5},
        {name=sch("2_blue_1"), rotation="90", prevalence=1},
        {name=sch("2_blue_1_portal"), no_rotation=true},
        {name=sch("2_blue_0"), rotation="0", prevalence=4},
        {name=sch("2_blue_0_portal")},
    }
})

br_core.register_biome({
    level = 2,
    desc = "Level 0 main",
    danger = 1,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("2_green_0"), rotation="0", prevalence=4},
        {name=sch("2_green_1_portal")},
        {name=sch("2_green_1"), rotation="0", prevalence=4},
        {name=sch("2_green_2"), rotation="0", prevalence=4},
        {name=sch("2_green_0_nolight")},
        {name=sch("2_green_1_nolight")},
    }
})




-- hotel
br_core.register_level({
    level = 5,
    desc = "Level 5",
    danger = 1,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 12,
    sun = {
        visible = false,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})

br_core.register_biome({
    level = 5,
    desc = "Level 5 rust",
    danger = 1,
    on_generate = nil,
    can_generate = function(pos)
        return true
    end,
    segheight = 10,
    schems = {
        {name=sch("5_10h_rust_1_portal"), vertical_segments={1,1}},
        {name=sch("5_10h_rust_0"), rotation="0", vertical_segments={1,1}, prevalence=3},
        {name=sch("5_10h_rust_1"), rotation="0", vertical_segments={1,1}, prevalence=3},
        {name=sch("5_10h_rust_2"), rotation="0", vertical_segments={1,1}, prevalence=3},
    }
})

br_core.register_biome({
    level = 5,
    desc = "Level 0 orange",
    danger = 1,
    on_generate = nil,
    prevalence = 1,
    segheight = 10,
    schems = {
        {name=sch("5_10h_orange_2_portal"), vertical_segments={1,1}},
        {name=sch("5_10h_orange_0"), rotation="0", vertical_segments={1,1}, prevalence=3},
        {name=sch("5_10h_orange_1"), rotation="0", vertical_segments={1,1}, prevalence=3},
        {name=sch("5_10h_orange_2"), rotation="0", vertical_segments={1,1}, prevalence=3},
    }
})

br_core.register_biome({
    level = 5,
    desc = "Level 0 black",
    danger = 1,
    on_generate = nil,
    prevalence = 1,
    segheight = 10,
    schems = {
        {name=sch("5_10h_black_0"), rotation="0", vertical_segments={1,1}, prevalence=1},
        {name=sch("5_20h_black_stairs_0"), vertical_segments={1,0}, prevalence=1, skip_above=1},
        {name=sch("5_10h_black_1"), rotation="90", vertical_segments={1,1}, prevalence=1},
        {name=sch("5_10h_black_2"), rotation="90", vertical_segments={1,1}, prevalence=1},
        {name=sch("5_10h_black_3"), rotation="90", vertical_segments={1,1}, prevalence=1},
        {name=sch("5_10h_black_0"), rotation="0", vertical_segments={1,1}, prevalence=3},
        {name=sch("5_10h_black_1"), rotation="0", vertical_segments={1,1}, prevalence=6},
        {name=sch("5_10h_black_2"), rotation="0", vertical_segments={1,1}, prevalence=6},
        {name=sch("5_10h_black_3"), rotation="0", vertical_segments={1,1}, prevalence=6},
        {name=sch("5_10h_black_portal_0"), rotation="0", vertical_segments={1,1}, prevalence=2},
    }
})

-- hub
br_core.register_level({
    level = 12,
    desc = "Level 12 hub",
    danger = 0,
    grace_dist = 5,
    biome = {},
    segsize = 40,
    base_height = 23,
    sun = {
        visible = true,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})

local l12pattern = {
    1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0
}
br_core.register_biome({
    level = 12,
    desc = "Level 12 tunnel",
    danger = 0,
    on_generate = nil,
    can_generate = function(pos)
        return ((pos.z % 3 == 0) and l12pattern[pos.x%30+1] <= 1)
    end,
    schems = {
        {name=sch("12_tunnel_portal_0"), rotation="90", prevalence=2},
        {name=sch("12_tunnel_random_0"), rotation="90", prevalence=3},
        {name=sch("12_tunnel_0"), rotation="90", prevalence=10},
    }
})
br_core.register_biome({
    level = 12,
    desc = "Level 12 block",
    danger = 0,
    on_generate = nil,
    can_generate = function(pos)
        return ((pos.z % 3 ~= 0) and l12pattern[pos.x%30+1] == 0)
    end,
    schems = {
        {name=sch("12_block_0")},
    }
})
br_core.register_biome({
    level = 12,
    desc = "Level 12 empty",
    danger = 0,
    on_generate = nil,
    can_generate = function(pos)
        return ((pos.z % 3 ~= 0) and l12pattern[pos.x%30+1] == 1)
    end,
    schems = {
        {name=sch("12_block_1")},
    }
})
br_core.register_biome({
    level = 12,
    desc = "Level 12 bridge",
    danger = 0,
    on_generate = nil,
    can_generate = function(pos)
        return ((pos.z % 3 == 0) and l12pattern[pos.x%30+1] == 2)
    end,
    schems = {
        {name=sch("12_bridge_0"), rotation="90"},
    }
})
br_core.register_biome({
    level = 12,
    desc = "Level 12 water",
    danger = 3,
    on_generate = nil,
    can_generate = function(pos)
        return ((pos.z % 3 ~= 0) and l12pattern[pos.x%30+1] == 2)
    end,
    schems = {
        {name=sch("12_water_0"), rotation="90"},
    }
})
br_core.register_on_changed_level(function(player, from_level, to_level)
    if to_level == 12 then
        player:override_day_night_ratio(0.2)
    elseif from_level == 12 then
        player:override_day_night_ratio(1)
    end
end)





-- hub
br_core.register_level({
    level = 17,
    desc = "Level 17",
    danger = 2,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 6,
    biome_roughness = 17862,
    biome_pixelization = 4,
    sun = {
        visible = true,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})

br_core.register_biome({
    level = 17,
    desc = "Level 17 canals",
    danger = 2,
    on_generate = nil,
    segheight = 20,
    can_generate = function(pos)
        return true
    end,
    schems = {
        {name=sch("17_fill_0"), rotation="0", vertical_segments={0,1,1,1}},
        {name=sch("17_canal_0"), rotation="0", prevalence=3, vertical_segments={1,0,0,0}},
        {name=sch("17_canal_1"), rotation="0", prevalence=3, vertical_segments={1,0,0,0}},
        {name=sch("17_canal_1"), rotation="180", prevalence=3, vertical_segments={1,0,0,0}},
        {name=sch("17_canal_2"), rotation="0", prevalence=3, vertical_segments={1,0,0,0}},
        {name=sch("17_canal_2"), rotation="180", prevalence=3, vertical_segments={1,0,0,0}},
        {name=sch("17_canal_2_portal"), rotation="180", prevalence=1, vertical_segments={1,0,0,0}},
        -- {name=sch("17_canal_0"), rotation="180", prevalence=1, vertical_segments={1,0,0}},
    }
})
br_core.register_biome({
    level = 17,
    desc = "Level 17 storm drains",
    danger = 0,
    on_generate = nil,
    segheight = 20,
    can_generate = function(pos)
        return true
    end,
    schems = {
        {name=sch("17_fill_0"), rotation="0", vertical_segments={0,1,1,1}},
        {name=sch("17_storm_drains_0"), rotation="0", prevalence=1, vertical_segments={1,0,0,0}, skip_above=3},
    }
})




-- ???
br_core.register_level({
    level = 31,
    desc = "Level 31",
    danger = 0,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 42,
    biome_roughness = 91.798,
    sun = {
        visible = false,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})
br_core.register_biome({
    level = 31,
    desc = "Level 31",
    danger = 0,
    on_generate = nil,
    segheight = 10,
    prevalence=2,
    can_generate = function(pos) -- must be deterministic
        return ((pos.z%5 ~= 0) or (pos.x%3 == 0))
    end,
    schems = {
        {name=sch("31_10h_corridor_base"),  vertical_segments={1}, prevalence=3, rotation="0"},
        {name=sch("31_10h_corridor_roof"),  vertical_segments={0,0,0,0,0,0,0,1}, rotation="0", prevalence=7},
        {name=sch("31_10h_corridor_0"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0", prevalence=7},
        {name=sch("31_10h_corridor_1"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0", prevalence=7},
        {name=sch("31_10h_corridor_2"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0", prevalence=7},
        {name=sch("31_10h_corridor_3"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0", prevalence=7},
        {name=sch("31_10h_corridor_4"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0", prevalence=7},
        {name=sch("31_10h_corridor_5"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0", prevalence=7},
        {name=sch("31_20h_stairs_0"), vertical_segments={0,1,1,1,1,1,0,0}, skip_above=1, prevalence=3},
        {name=sch("31_20h_stairs_1"), vertical_segments={0,1,1,1,1,1,0,0}, skip_above=1, prevalence=3},
        {name=sch("31_20h_stairs_0_portal"), vertical_segments={0,1,1,1,1,1,0,0}, skip_above=1, prevalence=3},
    }
})
br_core.register_biome({
    level = 31,
    desc = "Level 31",
    danger = 0,
    on_generate = nil,
    segheight = 10,
    can_generate = function(pos) -- must be deterministic
        return (pos.z%5 ~= 0 and (pos.x%8 < 4 and pos.z%7 < 4))
    end,
    schems = {
        {name=sch("31_10h_balcony_base"),  vertical_segments={1}, prevalence=3},
        {name=sch("31_10h_balcony_roof"),  vertical_segments={0,0,0,0,0,0,0,1}},

        {name=sch("31_10h_balcony_0"),     vertical_segments={0,1,1,1,1,1,1,0}, prevalence=3},
        {name=sch("31_10h_balcony_1"),     vertical_segments={0,1,1,1,1,1,1,0}, prevalence=3},
        {name=sch("31_10h_balcony_2"),     vertical_segments={0,1,1,1,1,1,1,0}, prevalence=3},
        {name=sch("31_10h_balcony_3"),     vertical_segments={0,1,1,1,1,1,1,0}, prevalence=3},
        {name=sch("31_10h_balcony_4"),     vertical_segments={0,1,1,1,1,1,1,0}, prevalence=3},
        {name=sch("31_10h_balcony_5"),     vertical_segments={0,1,1,1,1,1,1,0}, prevalence=3},
        {name=sch("31_10h_balcony_6"),     vertical_segments={0,1,1,1,1,1,1,0}, prevalence=3},
        --
        {name=sch("31_10h_balcony_0_portal"),     vertical_segments={0,1,1,1,1,1,1,0}},
        {name=sch("31_10h_balcony_1_portal"),     vertical_segments={0,1,1,1,1,1,1,0}},
        {name=sch("31_10h_balcony_2_portal"),     vertical_segments={0,1,1,1,1,1,1,0}},
        {name=sch("31_10h_balcony_3_portal"),     vertical_segments={0,1,1,1,1,1,1,0}},
        {name=sch("31_10h_balcony_4_portal"),     vertical_segments={0,1,1,1,1,1,1,0}},
        {name=sch("31_10h_balcony_5_portal"),     vertical_segments={0,1,1,1,1,1,1,0}},
        {name=sch("31_10h_balcony_6_portal"),     vertical_segments={0,1,1,1,1,1,1,0}},
    }
})

br_core.register_biome({
    level = 31,
    desc = "Level 31 SHORT",
    danger = 0,
    on_generate = nil,
    segheight = 10,
    prevalence = 1,
    can_generate = function(pos) -- must be deterministic
        return pos.z%5 == 0
    end,
    schems = {
        {name=sch("31_10h_corridor_short_base"),  vertical_segments={1}, prevalence=3, rotation="0"},
        {name=sch("31_10h_corridor_short_roof"),  vertical_segments={0,0,0,0,0,0,0,1}, rotation="0"},
        {name=sch("31_10h_corridor_short_0"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0"},
        {name=sch("31_10h_corridor_short_1"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0"},
        {name=sch("31_10h_corridor_short_2"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0"},
        {name=sch("31_10h_corridor_short_3"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0"},
        {name=sch("31_10h_corridor_short_4"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0"},
        {name=sch("31_10h_corridor_short_5"),     vertical_segments={0,1,1,1,1,1,1,0}, rotation="0"},
    }
})




-- poolrooms
br_core.register_level({
    level = 37,
    desc = "Level 37",
    danger = 0,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 40,
    biome_roughness = 896,
    biome_pixelization = 4,
    sun = {
        visible = true,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#def",
        type = "plain"
    },
})

br_core.register_biome({
    level = 37,
    desc = "Level 37 columns",
    danger = 0,
    on_generate = nil,
    can_generate = function(pos) -- must be deterministic
        if vector.distance(pos, vector.new(0, pos.y, 0)) > 10 then
            return false
        else
            return true
        end
    end,
    schems = {
        {name=sch("37_channel_0")},
    }
})
br_core.register_biome({
    level = 37,
    desc = "Level 0 main",
    danger = 0,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("37_channel_0"), prevalence=3},
        {name=sch("37_channel_1"), prevalence=3},
        {name=sch("37_channel_2"), prevalence=2},
        {name=sch("37_channel_3"), prevalence=1},
        {name=sch("37_pool_0"), prevalence=2},
        {name=sch("37_stair_0"), prevalence=2},
    }
})
br_core.register_biome({
    level = 37,
    desc = "Level 0 closed",
    danger = 0,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("37_channel_0"), rotation="0", prevalence=1},
        {name=sch("37_channel_2"), rotation="0", prevalence=1},
        {name=sch("37_closed_0"), prevalence=5},
        {name=sch("37_closed_1"), prevalence=4},
        {name=sch("37_closed_1_portal"), prevalence=1},
        {name=sch("37_pool_0"), prevalence=2},
        {name=sch("37_stair_0"), prevalence=2},
    }
})




br_core.register_level({
    level = 45,
    desc = "Level 45",
    secret = true,
    danger = 0,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 41,
    sun = {
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
		base_color = "#ffffff",
		type = "regular",
        clouds = false,
		sky_color = {
			day_sky = "#92b9f2" ,
			day_horizon = "#010c22",
			dawn_sky = "#92b9f2" ,
			dawn_horizon = "#010c22",
			night_sky = "#006bff" ,
			night_horizon = "#010c22",
			indoors = "#010c22",
			fog_sun_tint = "#010c22",
			fog_moon_tint = "#010c22",
			fog_tint_type = "custom",
		}
	},
})

br_core.register_biome({
    level = 45,
    desc = "Level 45 doors",
    danger = 0,
    on_generate = nil,
    can_generate = function(pos) -- must be deterministic
        if vector.distance(pos, vector.new(0, pos.y, 0)) > 10 then
            return false
        else
            return true
        end
    end,
    schems = {
        {name=sch("45_doors_0"), no_rotation=true},
        {name=sch("45_sparse_0"), no_rotation=true},
        {name=sch("45_sparse_0"), no_rotation=true},
    }
})

br_core.register_biome({
    level = 45,
    desc = "Level 45 doors with portal",
    danger = 0,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("45_sparse_0"), no_rotation=true},
        {name=sch("45_sparse_0"), no_rotation=true},
        {name=sch("45_sparse_0"), no_rotation=true},
        {name=sch("45_sparse_0_portal"), no_rotation=true},
        {name=sch("45_doors_0"), no_rotation=true},
        {name=sch("45_doors_0"), no_rotation=true},
        {name=sch("45_doors_0"), no_rotation=true},
    }
})




-- ???
br_core.register_level({
    level = 51,
    desc = "Level 51 area",
    danger = 1,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 2,
    biome_roughness = 8.654,
    sun = {
        visible = false,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#001",
        type = "plain"
    },
})
br_core.register_biome({
    level = 51,
    desc = "Level 51",
    danger = 1,
    on_generate = nil,
    segheight = 10,
    can_generate = function(pos) -- must be deterministic
        return true
    end,
    schems = {
        {name=sch("51_shelves_0"),  vertical_segments={1}, prevalence=1, skip_above=3},
        {name=sch("51_shelves_1"),  vertical_segments={1}, prevalence=1, skip_above=3},
        {name=sch("51_shelves_0_portal"),  vertical_segments={1}, prevalence=1, skip_above=3, can_generate = function(pos)
            return ((pos.x % 2 == 0) and (pos.z % 2 == 0))
        end},
        {name=sch("51_shelves_0"),  vertical_segments={1}, prevalence=3, skip_above=3, rotation="0"},
        {name=sch("51_shelves_1"),  vertical_segments={1}, prevalence=3, skip_above=3, rotation="0"},
    }
})
br_core.register_biome({
    level = 51,
    desc = "Level 51",
    danger = 1,
    on_generate = nil,
    segheight = 10,
    schems = {
        {name=sch("51_shelves_0"),  vertical_segments={1}, prevalence=1, skip_above=3},
        {name=sch("51_shelves_1"),  vertical_segments={1}, prevalence=1, skip_above=3},
        {name=sch("51_piles_0"),  vertical_segments={1}, prevalence=9, skip_above=3},
        {name=sch("51_piles_0_portal"),  vertical_segments={1}, prevalence=1, skip_above=3},
        {name=sch("51_car_0"),  vertical_segments={1}, prevalence=1, skip_above=3, can_generate = function(pos)
            return ((pos.x % 3 == 0) and (pos.z % 2 == 0))
        end},
    }
})




-- hospital
br_core.register_level({
    level = 62,
    desc = "Level 62 hospital",
    danger = 2,
    grace_dist = 5,
    biome = {},
    segsize = 40,
    base_height = 2,
    sun = {
        visible = false,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    sky = {
        clouds = false,
        base_color = "#eee",
        type = "plain"
    },
})
br_core.register_biome({
    level = 62,
    desc = "Level 62",
    danger = 2,
    on_generate = nil,
    schems = {
        {name=sch("62_corridors_0"), rotation="0"},
        {name=sch("62_corridors_0"), rotation="90"},
        {name=sch("62_corridors_1"), rotation="0"},
        {name=sch("62_corridors_1"), rotation="90"},
        {name=sch("62_corridors_2"), rotation="0"},
        {name=sch("62_corridors_2"), rotation="90"},
        {name=sch("62_corridors_closed_0"), rotation="0", prevalence=3},
        {name=sch("62_corridors_closed_0"), rotation="90", prevalence=3},
    }
})




if true then
local l96_pattern = {}

local function l96_pattern_add(def)
    for i=1, def.prevalence or 1 do
        l96_pattern[#l96_pattern+1] = def.pattern
    end
end
l96_pattern_add({
    prevalence = 9,
    pattern = {
        {"SW","SS","SS","SE","TV"},
        {"WW","OO","OO","EE","TV"},
        {"WW","ST","OO","EE","TV"},
        {"NW","NN","NN","NE","TV"},
        {"TH","TH","TH","TH","TX"},
    },
})
l96_pattern_add({
    prevalence = 6,
    pattern = {
        {"SW","SS","SS","SE","TV"},
        {"WW","ST","OO","NE","TV"},
        {"WY","OO","EE","PP","TV"},
        {"NW","NN","NE","PP","TV"},
        {"TH","TH","TH","TH","TX"},
    },
})
l96_pattern_add({
    prevalence = 1,
    pattern = {
        {"SW","SE","PP","PP","TV"},
        {"WY","EE","PP","PP","TV"},
        {"WW","EE","PP","PP","TV"},
        {"NW","NE","PP","PP","TV"},
        {"TH","TH","TH","TH","TX"},
    },
})
l96_pattern_add({
    prevalence = 1,
    pattern = {
        {"PP","PP","PP","SW","SE"},
        {"SW","SE","PP","NW","NE"},
        {"WY","EE","PP","PP","PP"},
        {"NW","NE","PP","PP","PP"},
        {"TH","TH","TH","TH","TX"},
    },
})
l96_pattern_add({
    prevalence = 3,
    pattern = {
        {"PP","PP","PP","PP","PP"},
        {"PP","PP","PP","PP","PP"},
        {"PP","PP","PP","PP","PP"},
        {"PP","PP","PP","PP","PP"},
        {"PP","PP","PP","PP","PP"},
    },
})

local length = 5
local width = 5
local function l96_glitchy_version(x, z, perlin)
    local len = 2
    local roughness = 21964.27896 * vector.distance(vector.new(x, 0, z), vector.new(0, 0, 0))
    local variant = math.floor(perlin.variant.data3d[x%len+1][2][z%len+1] * roughness) % #l96_pattern + 1
    return "ALL"
    --l96_pattern[variant][z%length+1][x%width+1]
end

-- streets
br_core.register_level({
    level = 96,
    desc = "Level 96 streets",
    danger = 2,
    grace_dist = 5,
    biome = {},
    segsize = 16,
    base_height = 10,
    on_generate = function(pos, perlin)
        local x, z = pos.x, pos.z
        local roughness = 21964.27896
        local variant = math.floor(perlin.variant.data3d[2][2][2] * roughness) % #l96_pattern + 1

        -- weird "doesn't care about walls" version
        if vector.distance(pos, vector.new(0,0,0)) > 500
        and x%60 > 6 and z%60 > 6 then
            return l96_glitchy_version(x, z, perlin)
        end

        return l96_pattern[variant][z%length+1][x%width+1]
    end,
    sun = {
        visible = true,
        texture = "blank.png",
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    clouds = {
        density = 0.6,
        thickness = 2.3,
        ambient = "#fff",
        color = "#ffffff20",
        height = 180 * br_core.level_height - 32 + 42 - 4.37 + 90,
        speed = {x=2.7, z=3}
    },
    sky = {
		base_color = "#ffffff",
		type = "regular",
		clouds = true,
		sky_color = {
			day_sky = "#80aed9" ,
			day_horizon = "#8086a1",
			dawn_sky = "#979" ,
			dawn_horizon = "#fb9",
			night_sky = "#263965" ,
			night_horizon = "#263965",
			indoors = "#263965",
			fog_sun_tint = "#263965",
			fog_moon_tint = "#263965",
			fog_tint_type = "custom",
		}
	},
})
local l96pl = {}
local l96timer = -1
br_core.register_on_changed_level(function(player, from_level, to_level)
    if to_level == 96 then
        l96pl[player] = true
        player:override_day_night_ratio(1)
    elseif from_level == 96 then
        l96pl[player] = nil
        player:override_day_night_ratio(1)
    end
end)
minetest.register_globalstep(function(dtime)
    local day_period = 600
    if l96timer == -1 then
        l96timer = world_storage:get_key("l96timer") or day_period * 0.4
    end
    l96timer = (l96timer + dtime) % day_period
    if l96timer - dtime < 0 and world_storage then
        world_storage:set_key("l96timer", l96timer)
    end
    for player,_ in pairs(l96pl) do
        if player and player.is_player and player:is_player() then
            player:override_day_night_ratio(math.sin(l96timer / day_period * 3.14))
        end
    end
end)
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "NW",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_corner_0"), rotation="180", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "NE",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_corner_0"), rotation="270", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "SE",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_corner_0"), rotation="0", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "SW",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_corner_0"), rotation="90", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "NN",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_wall_0"), rotation="180", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_1"), rotation="180", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2"), rotation="180", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2_portal"), rotation="180", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_stair_continuous_wall_0"), rotation="0", vertical_segments={0,1}, skip_above=8},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "EE",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), rotation="270", vertical_segments={1}},
        --
        {name=sch("96_wall_0"), rotation="270", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_1"), rotation="270", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2"), rotation="270", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2_portal"), rotation="270", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_stair_continuous_wall_0"), rotation="90", vertical_segments={0,1}, skip_above=8},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "SS",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_wall_0"), rotation="0", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_1"), rotation="0", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2"), rotation="0", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2_portal"), rotation="0", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_stair_continuous_wall_0"), rotation="180", vertical_segments={0,1}, skip_above=8},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "WW",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_wall_0"), rotation="90", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_1"), rotation="90", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2"), rotation="90", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_wall_2_portal"), rotation="90", vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_stair_continuous_wall_0"), rotation="270", vertical_segments={0,1}, skip_above=8},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "WY",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_stair_continuous_wall_0"), rotation="270", vertical_segments={0,1}, skip_above=8},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "TV",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        {name=sch("16x8_air"), rotation="0", vertical_segments={0,0,1,1,1,1,1,1,1,0}},
        --
        {name=sch("96_road_0"), rotation="0", vertical_segments={0,1,0,0,0,0,0,0,0,0}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "TH",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        {name=sch("16x8_air"), rotation="0", vertical_segments={0,0,1,1,1,1,1,1,1,0}},
        --
        {name=sch("96_road_0"), rotation="90", vertical_segments={0,1,0,0,0,0,0,0,0,0}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "TX",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        {name=sch("16x8_air"), rotation="0", vertical_segments={0,0,1,1,1,1,1,1,1,0}},
        --
        {name=sch("96_crossroad_0"), rotation="0", vertical_segments={0,1,0,0,0,0,0,0,0,0}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "OO",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        {name=sch("16x8_air"), rotation="0", vertical_segments={0,0,0,0,0,0,0,0,0,1}},
        --
        {name=sch("96_middle_0"), free_rotation=true, vertical_segments={0,1,1,1,1,1,1,1,1,0}, prevalence=1},
        {name=sch("96_middle_1"), free_rotation=true, vertical_segments={0,1,1,1,1,1,1,1,1,0}, prevalence=1},
        {name=sch("96_middle_2"), free_rotation=true, vertical_segments={0,1,1,1,1,1,1,1,1,0}, prevalence=3},
        {name=sch("96_middle_0_portal"), free_rotation=true, vertical_segments={0,1,1,1,1,1,1,1,1,0}},
        {name=sch("96_stair_0"), free_rotation=true, vertical_segments={0,1,1,1,1,1,1,1,0,0}, skip_above=1, prevalence=3},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "PP",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        {name=sch("16x8_air"), rotation="0", vertical_segments={0,0,1,1,1,1,1,1,1,0}},
        --
        {name=sch("96_park_0"), vertical_segments={0,1}},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "ST",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        {name=sch("16x8_air"), rotation="0", vertical_segments={0,0,1,1,1,1,1,1,1,0}},
        --
        {name=sch("96_stair_continuous_0"), vertical_segments={0,1}, skip_above=8},
    }
})
br_core.register_biome({
    level = 96,
    desc = "Level 96",
    name = "ALL",
    danger = 2,
    on_generate = nil,
    segheight = 8,
    schems = {
        {name=sch("96_underground_0"), vertical_segments={1}},
        --
        {name=sch("96_stair_continuous_0"), vertical_segments={0,1}, skip_above=8, prevalence=9},
        {name=sch("96_blank_ruin"), vertical_segments={0,0,0,0,0,0,0,0,0,1}, prevalence=3},
        {name=sch("96_blank_ruin"), vertical_segments={0,0,0,0,0,0,0,0,1,0}, prevalence=8, skip_above=1},
        {name=sch("96_blank_ruin"), vertical_segments={0,0,0,0,0,0,0,1,0,0}, prevalence=5, skip_above=2},
        --
        {name=sch("96_blank_ruin"), vertical_segments={0,0,0,0,0,1,0,0,0,0}, prevalence=9, skip_above=4},
        --
        {name=sch("96_blank_ruin"), vertical_segments={1,0,0,0,0,0,0,0,0,0}, prevalence=5, skip_above=9},
        {name=sch("96_blank_ruin"), vertical_segments={0,0,1,0,0,0,0,0,0,0}, prevalence=5, skip_above=8},
            {name=sch("96_blank_ruin"), vertical_segments={1}, prevalence=2, skip_above=9, can_generate=function(pos)
            if (pos.x % 60 < 12) and (pos.z % 60 < 12) then return false
            else return true end
        end},
        --
        {name=sch("96_corner_0"), vertical_segments={0,1,1,1,1,1,1,1,1,1}},
        {name=sch("96_middle_0"), free_rotation=true, vertical_segments={1,1,1,1,1,1,1,1,1,1}, prevalence=1},
        {name=sch("96_middle_1"), free_rotation=true, vertical_segments={1,1,1,1,1,1,1,1,1,1}, prevalence=1},
        {name=sch("96_middle_2"), free_rotation=true, vertical_segments={1,1,1,1,1,1,1,1,1,1}, prevalence=3},
        {name=sch("96_middle_0_portal"), free_rotation=true, vertical_segments={1,1,1,1,1,1,1,1,1,1}},
        --
        {name=sch("96_stair_0"), free_rotation=true, vertical_segments={1,1,1,1,1,1,1,1,0,0}, skip_above=1, prevalence=3},
        {name=sch("96_stair_0"), free_rotation=true, vertical_segments={1,0,0,0,0,0,0,0,0,0}, prevalence=3, skip_above=1},
    }
})
end


br_core.register_level({
    level = 180,
    desc = "Level 180 \'the end\'",
    secret = true,
    danger = 0,
    grace_dist = 5,
    biome = {},
    segsize = 20,
    base_height = 42,
    biome_roughness = 2981.7138976,
    sun = {
        visible = true,
        sunrise_visible = false,
    },
    moon = {
        visible = false,
    },
    clouds = {
        density = 0.6,
        thickness = 2.3,
        ambient = "#fff",
        color = "#ffffff20",
        height = 180 * br_core.level_height - 32 + 42 - 4.37 + 90,
        speed = {x=2.7, z=3}
    },
    sky = {
		base_color = "#ffffff",
		type = "regular",
		clouds = true,
		sky_color = {
			day_sky = "#3383a6" ,
			day_horizon = "#3383a6",
			dawn_sky = "#000" ,
			dawn_horizon = "#000",
			night_sky = "#263965" ,
			night_horizon = "#263965",
			indoors = "#263965",
			fog_sun_tint = "#263965",
			fog_moon_tint = "#263965",
			fog_tint_type = "custom",
		}
	},
})

br_core.register_biome({
    level = 180,
    desc = "Level 180 house",
    danger = 0,
    on_generate = nil,
    prevalence = 1,
    can_generate = function(seg_pos) -- must be deterministic
        if (seg_pos.x%17 == 0) and (seg_pos.z%87 == 0) then
            return true
        else
            return false
        end
    end,
    schems = {
        {name=sch("180_house_0")},
    }
})

br_core.register_biome({
    level = 180,
    desc = "Level 180",
    danger = 0,
    on_generate = nil,
    can_generate = function(pos) -- must be deterministic
        return true
    end,
    prevalence = 20,
    schems = {
        {name=sch("180_open_0")},
    }
})

br_core.register_biome({
    level = 180,
    desc = "Level 180",
    danger = 0,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("180_open_0")},
        {name=sch("180_open_0")},
        {name=sch("180_open_0")},
        {name=sch("180_open_0")},
        {name=sch("180_open_1")},
        {name=sch("180_open_2")},
        {name=sch("180_open_3")},
        {name=sch("180_open_4")},
        {name=sch("180_arch_0")},
        {name=sch("180_path_0")},
    }
})

br_core.register_biome({
    level = 180,
    desc = "Level 180",
    danger = 0,
    on_generate = nil,
    prevalence = 1,
    schems = {
        {name=sch("180_arch_0")},
        {name=sch("180_path_0")},
        {name=sch("180_path_0")},
        {name=sch("180_path_0")},
        {name=sch("180_path_1")},
        {name=sch("180_path_1")},
    }
})
br_core.register_on_changed_level(function(player, from_level, to_level)
    if to_level == 180 and from_level ~= -1 then
        player:set_pos(vector.new(50,br_spawn.get_level_y(180),50))
    end
end)

-- sort levels after all mods loaded
minetest.register_on_mods_loaded(function()
    br_core.sort_levels()
end)
