package net.minecraft.world.level.biome;

import java.util.function.BiFunction;
import com.mojang.datafixers.kinds.Applicative;
import net.minecraft.util.Codecs;
import net.minecraft.core.Registry;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.Collection;
import com.google.common.collect.ImmutableList;
import java.util.List;
import com.mojang.serialization.Codec;

public class CheckerboardColumnBiomeSource extends BiomeSource {
    public static final Codec<CheckerboardColumnBiomeSource> CODEC;
    private final List<Biome> allowedBiomes;
    private final int bitShift;
    private final int size;
    
    public CheckerboardColumnBiomeSource(final List<Biome> list, final int integer) {
        super(ImmutableList.copyOf(list));
        this.allowedBiomes = list;
        this.bitShift = integer + 2;
        this.size = integer;
    }
    
    @Override
    protected Codec<? extends BiomeSource> codec() {
        return CheckerboardColumnBiomeSource.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.allowedBiomes.get(Math.floorMod((integer1 >> this.bitShift) + (integer3 >> this.bitShift), this.allowedBiomes.size()));
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Registry.BIOME.listOf().fieldOf("biomes").forGetter(brn -> brn.allowedBiomes), (App)Codecs.intRange(0, 62).fieldOf("scale").withDefault(2).forGetter(brn -> brn.size)).apply(instance, (BiFunction)CheckerboardColumnBiomeSource::new));
    }
}
