package com.mineplex.studio.generator;

import com.mojang.serialization.MapCodec;
import java.util.stream.Stream;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate;
import org.bukkit.craftbukkit.block.CraftBiome;

/**
 * A semi empty biome source. We need to provide a biome inside {@link #getNoiseBiome(int, int, int, Climate.Sampler)}
 * or players can't join, but we disable a lot by returning an empty stream inside {@link #collectPossibleBiomes()}.
 */
public class EmptyBiomeSource extends BiomeSource {
    private final Holder<Biome> biomeHolder;

    public EmptyBiomeSource() {
        this(org.bukkit.block.Biome.BEACH);
    }

    public EmptyBiomeSource(final org.bukkit.block.Biome biome) {
        this.biomeHolder = CraftBiome.bukkitToMinecraftHolder(biome);
    }

    @Override
    protected MapCodec<? extends BiomeSource> codec() {
        throw new UnsupportedOperationException("Cannot serialize SingleBiomeSource");
    }

    @Override
    protected Stream<Holder<Biome>> collectPossibleBiomes() {
        return Stream.empty();
    }

    @Override
    public Holder<Biome> getNoiseBiome(int x, int y, int z, Climate.Sampler noise) {
        return biomeHolder;
    }
}
