
minetest.register_alias("mapgen_stone", "amogus_blocks:stone")
minetest.register_alias("mapgen_dirt", "amogus_blocks:dirt")
minetest.register_alias("mapgen_water_source", "amogus_blocks:water_source")

minetest.register_biome({
    name = "amogus_beach",
    node_top = "amogus_blocks:sand",
    depth_top = 1,
    node_filler = "amogus_blocks:sand",
    depth_filler = 3,
    node_stone = "amogus_blocks:stone",

    --node_water_top = "amogus_blocks:water",
    --depth_water_top = 1,
    node_water = "amogus_blocks:amogus_blocks:water_source",
    --node_river_water = "amogus_blocks:water",

    y_max = 6,
    y_min = -5,
    heat_point = 50,
    humidity_point = 50,
})
minetest.register_biome({
    name = "amogus_green_biome",
    --node_dust = "amogus_blocks:stone",
    node_top = "amogus_blocks:grass_green",
    depth_top = 1,
    node_filler = "amogus_blocks:dirt",
    depth_filler = 1,
    node_stone = "amogus_blocks:stone",

    --node_water_top = "amogus_blocks:water",
    --depth_water_top = 1,
    node_water = "amogus_blocks:amogus_blocks:water_source",
    --node_river_water = "amogus_blocks:water",

    y_max = 31000,
    y_min = 1,
    heat_point = 100,
    humidity_point = 100,
})
minetest.register_biome({
    name = "amogus_biome",
    --node_dust = "amogus_blocks:stone",
    node_top = "amogus_blocks:grass",
    depth_top = 1,
    node_filler = "amogus_blocks:dirt",
    depth_filler = 1,
    node_stone = "amogus_blocks:stone",

    --node_water_top = "amogus_blocks:water",
    --depth_water_top = 1,
    node_water = "amogus_blocks:amogus_blocks:water_source",
    --node_river_water = "amogus_blocks:water",

    y_max = 31000,
    y_min = 1,
    heat_point = 50,
    humidity_point = 50,
})

minetest.register_ore({
    ore_type       = "scatter",
    ore            = "amogus_blocks:sussium_ore",
    wherein        = "amogus_blocks:stone",
    clust_scarcity = 8 * 8 * 8,
    clust_num_ores = 1,
    clust_size     = 1,
    y_max          = 31000,
    y_min          = -31000,
})minetest.register_ore({
    ore_type       = "scatter",
    ore            = "amogus_blocks:gold_ore",
    wherein        = "amogus_blocks:stone",
    clust_scarcity = 8 * 8 * 8,
    clust_num_ores = 1,
    clust_size     = 1,
    y_max          = 31000,
    y_min          = -31000,
})minetest.register_ore({
    ore_type       = "scatter",
    ore            = "amogus_blocks:obsusian",
    wherein        = "amogus_blocks:stone",
    clust_scarcity = 8 * 8 * 8,
    clust_num_ores = 1,
    clust_size     = 1,
    y_max          = 31000,
    y_min          = -31000,
})

minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:lucky_block",
})minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:lucky_block",
})

minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:amogflower",
})
minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.10,
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:grass_tall",
})minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    fill_ratio = 0.10,
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:purple_grass_tall",
})
minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:amogflower",
})
minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:redflower",
})

minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:yellowflower",
})

minetest.register_decoration({
    deco_type = "simple",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 4321,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    decoration = "amogus_blocks:tv",
})

minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/tree.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"green__biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/green_tree.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"green__biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/green_tree_tall.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass","amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"amogus_biome","green_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/fallen.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    fill_ratio = 0.01,
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/treer.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 4321,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/minihouse.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})

minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 4321,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/amogus_statue.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})

minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/lucky_tree_2.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"amogus_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/lucky_tree_1.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})

minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/lucky_tree_2.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/lucky_tree_1.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})

minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/STONE1.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/STONE2.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    noise_params = {
        offset = 0,
        scale = 0.0001,
        spread = {x = 100, y = 100, z = 100},
        seed = 1234,
        octaves = 3,
        persist = 0.6
    },
    biomes = {"green_biome"},
    y_max = 31000,
    y_min = 1,
    schematic = "/schematics/STONE3.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})
--minetest.register_abm({
--    label = "Spawn random entities",
--    nodenames = {"group:soil", "group:crumbly", "group:choppy", "group:snappy", "group:cracky"},
 --   interval = 15,
 --   chance = 50,
   -- action = function(pos)
--        local r = math.random(1, 500)
 --       if r <= 50 then
 --          minetest.add_entity({x = pos.x + math.random(-10, 10),
  --                               y = pos.y + 1,
  --                               z = pos.z + math.random(-10, 10)}, "amogus_entities:amogus")            
  --              minetest.sound_play("amogus_sound", {
  --              pos = pos,
  --              gain = 1.0,
   --             max_hear_distance = 5
   --         })

   --     end
  --  end
--})

minetest.register_on_generated(function(minp, maxp, seed)
    --local is_newchunk = true
    --for , pos in ipairs(minetest.find_nodes_in_area(minp, maxp, "mymod:amogus_spawner")) do
        --is_new_chunk = false
       -- break
    --end
    --if is_new_chunk then
        for i = 1, math.random(10, 15) do
            minetest.add_entity({x = minp.x + math.random(16), y = minp.y + 1, z = minp.z + math.random(16)}, "amogus_entities:amogus")
            --minetest.sound_play("amogus_sound", { pos = pos,gain = 1.0,max_hear_distance = 5})
        end
    --end
end)


minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:sand"},
    sidelen = 16,
    fill_ratio = 0.0001,
    y_max = 31000,
    y_min = 1,
    biomes = {"amogus_beach"},

    schematic = "/schematics/sand_house_1.mts",
})

minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:sand"},
    sidelen = 16,
    fill_ratio = 0.0001,
    y_max = 31000,
    y_min = 1,
    biomes = {"amogus_beach"},

    schematic = "/schematics/sand_house_2.mts",
})

minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:sand"},
    sidelen = 16,
    fill_ratio = 0.0001,
    y_max = 31000,
    y_min = 1,
    biomes = {"amogus_beach"},

    schematic = "/schematics/sand_house_3.mts",
})


minetest.register_decoration({
    deco_type = "schematic",
    place_on = {"amogus_blocks:grass_green"},
    sidelen = 16,
    fill_ratio = 0.0001,
    y_max = 31000,
    y_min = 1,
    biomes = {"green_biome"},

    schematic = "/schematics/STATUE_GIANT.mts",
})

--minetest.register_on_generated(function(minp, maxp, seed)
--    for x = minp.x, maxp.x do
--       for y = minp.y, maxp.y do
--          for z = minp.z, maxp.z do
--             local p = {x=x, y=y, z=z}
--             if minetest.get_node(p).name == "default:water_source" then
--                minetest.set_node(p, {name="default:water_source", param2=0})
--             end
--          end
--       end
--    end
-- end)