package net.minecraft.world.level.biome;

import java.util.function.Function;
import net.minecraft.core.Registry;
import com.google.common.collect.Sets;
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import java.util.Random;
import java.util.List;
import com.google.common.collect.ImmutableList;
import com.mojang.serialization.Codec;

public class FixedBiomeSource extends BiomeSource {
    public static final Codec<FixedBiomeSource> CODEC;
    private final Biome biome;
    
    public FixedBiomeSource(final Biome bre) {
        super(ImmutableList.<Biome>of(bre));
        this.biome = bre;
    }
    
    @Override
    protected Codec<? extends BiomeSource> codec() {
        return FixedBiomeSource.CODEC;
    }
    
    @Override
    public BiomeSource withSeed(final long long1) {
        return this;
    }
    
    @Override
    public Biome getNoiseBiome(final int integer1, final int integer2, final int integer3) {
        return this.biome;
    }
    
    @Nullable
    @Override
    public BlockPos findBiomeHorizontal(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final List<Biome> list, final Random random, final boolean boolean8) {
        if (!list.contains(this.biome)) {
            return null;
        }
        if (boolean8) {
            return new BlockPos(integer1, integer2, integer3);
        }
        return new BlockPos(integer1 - integer4 + random.nextInt(integer4 * 2 + 1), integer2, integer3 - integer4 + random.nextInt(integer4 * 2 + 1));
    }
    
    @Override
    public Set<Biome> getBiomesWithin(final int integer1, final int integer2, final int integer3, final int integer4) {
        return Sets.<Biome>newHashSet(this.biome);
    }
    
    static {
        CODEC = Registry.BIOME.fieldOf("biome").xmap((Function)FixedBiomeSource::new, bse -> bse.biome).stable().codec();
    }
}
