
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_alias("mapgen_river_water_source", "amogus_blocks:water_source")

-- I need to register alias of amogus_blocks:water that doesn't even exist in any of the mods to air because Minetest is f****d up and tries to use "water" by default
minetest.register_alias("amogus_blocks:water", "air")


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 = "amogus_blocks:water_source",

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

    node_water = "amogus_blocks:water_source",

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

    node_water = "amogus_blocks:water_source",

    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_ore({
    ore_type       = "scatter",
    ore            = "amogus_blocks:iron_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_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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/schematics/STONE3.mts",
    flags = "place_center_x, place_center_z",
    rotation = "random",
})

minetest.register_on_generated(function(minp, maxp, seed)
    for i = 1, math.random(10, 25) do
        minetest.add_entity({x = minp.x + math.random(16), y = minp.y + 1, z = minp.z + math.random(16)}, "amogus_entities:amogus")
    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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/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 = minetest.get_modpath("amogus_generator") .. "/schematics/STATUE_GIANT.mts",
})


-- DEBUG
--imposters_spawned = 0


minetest.register_abm({
	label = "Spawn Imposter",
	nodenames = {"air"},
	neighbors = {"group:stone"},
	interval = 10,
	chance = 200,
	action = function(pos)
        -- DEBUG
        --imposters_spawned = imposters_spawned + 1
        --minetest.chat_send_all("Imposters spawned: " .. imposters_spawned)

        -- only spawn on solid blocks AND in the dark
        if minetest.registered_nodes[minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name].walkable and minetest.get_node_light(pos) <= 12 then
            -- do not spawn if there is already an sussy imposter nearby
            local nearby_entities = minetest.get_objects_inside_radius(pos, 10)
            local imposter_nearby = false

            for _, entity in pairs(nearby_entities) do
                if (entity:get_luaentity() and entity:get_luaentity().name or "") == "amogus_entities:sussy_imposter" then
                    imposter_nearby = true
                    break
                end
            end

            if not imposter_nearby then
                minetest.add_entity(pos, "amogus_entities:sussy_imposter")
            end

        end
	end
})