package net.minecraft.world.level.levelgen.feature.stateproviders;

import net.minecraft.world.level.block.Blocks;
import java.util.Map;
import net.minecraft.core.Registry;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.util.Mth;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.core.BlockPos;
import java.util.Random;
import com.mojang.datafixers.Dynamic;
import net.minecraft.world.level.block.state.BlockState;

public class ForestFlowerProvider extends BlockStateProvider {
    private static final BlockState[] FLOWERS;
    
    public ForestFlowerProvider() {
        super(BlockStateProviderType.FOREST_FLOWER_PROVIDER);
    }
    
    public <T> ForestFlowerProvider(final Dynamic<T> dynamic) {
        this();
    }
    
    @Override
    public BlockState getState(final Random random, final BlockPos fk) {
        final double double4 = Mth.clamp((1.0 + Biome.BIOME_INFO_NOISE.getValue(fk.getX() / 48.0, fk.getZ() / 48.0, false)) / 2.0, 0.0, 0.9999);
        return ForestFlowerProvider.FLOWERS[(int)(double4 * ForestFlowerProvider.FLOWERS.length)];
    }
    
    @Override
    public <T> T serialize(final DynamicOps<T> dynamicOps) {
        final ImmutableMap.Builder<T, T> builder3 = ImmutableMap.<T, T>builder();
        builder3.put((T)dynamicOps.createString("type"), (T)dynamicOps.createString(Registry.BLOCKSTATE_PROVIDER_TYPES.getKey(this.type).toString()));
        return (T)new Dynamic((DynamicOps)dynamicOps, dynamicOps.createMap((Map)builder3.build())).getValue();
    }
    
    static {
        FLOWERS = new BlockState[] { Blocks.DANDELION.defaultBlockState(), Blocks.POPPY.defaultBlockState(), Blocks.ALLIUM.defaultBlockState(), Blocks.AZURE_BLUET.defaultBlockState(), Blocks.RED_TULIP.defaultBlockState(), Blocks.ORANGE_TULIP.defaultBlockState(), Blocks.WHITE_TULIP.defaultBlockState(), Blocks.PINK_TULIP.defaultBlockState(), Blocks.OXEYE_DAISY.defaultBlockState(), Blocks.CORNFLOWER.defaultBlockState(), Blocks.LILY_OF_THE_VALLEY.defaultBlockState() };
    }
}
