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

import java.util.Map;
import net.minecraft.core.Registry;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.types.DynamicOps;
import net.minecraft.world.level.block.Blocks;
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 PlainFlowerProvider extends BlockStateProvider {
    private static final BlockState[] LOW_NOISE_FLOWERS;
    private static final BlockState[] HIGH_NOISE_FLOWERS;
    
    public PlainFlowerProvider() {
        super(BlockStateProviderType.PLAIN_FLOWER_PROVIDER);
    }
    
    public <T> PlainFlowerProvider(final Dynamic<T> dynamic) {
        this();
    }
    
    @Override
    public BlockState getState(final Random random, final BlockPos fk) {
        final double double4 = Biome.BIOME_INFO_NOISE.getValue(fk.getX() / 200.0, fk.getZ() / 200.0, false);
        if (double4 < -0.8) {
            return PlainFlowerProvider.LOW_NOISE_FLOWERS[random.nextInt(PlainFlowerProvider.LOW_NOISE_FLOWERS.length)];
        }
        if (random.nextInt(3) > 0) {
            return PlainFlowerProvider.HIGH_NOISE_FLOWERS[random.nextInt(PlainFlowerProvider.HIGH_NOISE_FLOWERS.length)];
        }
        return Blocks.DANDELION.defaultBlockState();
    }
    
    @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 {
        LOW_NOISE_FLOWERS = new BlockState[] { Blocks.ORANGE_TULIP.defaultBlockState(), Blocks.RED_TULIP.defaultBlockState(), Blocks.PINK_TULIP.defaultBlockState(), Blocks.WHITE_TULIP.defaultBlockState() };
        HIGH_NOISE_FLOWERS = new BlockState[] { Blocks.POPPY.defaultBlockState(), Blocks.AZURE_BLUET.defaultBlockState(), Blocks.OXEYE_DAISY.defaultBlockState(), Blocks.CORNFLOWER.defaultBlockState() };
    }
}
