package net.minecraft.world.level.block;

import java.util.List;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.AbstractFlowerFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.configurations.DecoratedFeatureConfiguration;
import net.minecraft.server.level.ServerLevel;
import java.util.Random;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class GrassBlock extends SpreadingSnowyDirtBlock implements BonemealableBlock {
    public GrassBlock(final Properties c) {
        super(c);
    }
    
    @Override
    public boolean isValidBonemealTarget(final BlockGetter bpg, final BlockPos fu, final BlockState cfj, final boolean boolean4) {
        return bpg.getBlockState(fu.above()).isAir();
    }
    
    @Override
    public boolean isBonemealSuccess(final Level bqb, final Random random, final BlockPos fu, final BlockState cfj) {
        return true;
    }
    
    @Override
    public void performBonemeal(final ServerLevel zd, final Random random, final BlockPos fu, final BlockState cfj) {
        final BlockPos fu2 = fu.above();
        final BlockState cfj2 = Blocks.GRASS.defaultBlockState();
        int integer8 = 0;
    Label_0282_Outer:
        while (integer8 < 128) {
            BlockPos fu3 = fu2;
            int integer9 = 0;
            while (true) {
                while (integer9 < integer8 / 16) {
                    fu3 = fu3.offset(random.nextInt(3) - 1, (random.nextInt(3) - 1) * random.nextInt(3) / 2, random.nextInt(3) - 1);
                    if (zd.getBlockState(fu3.below()).is(this)) {
                        if (!zd.getBlockState(fu3).isCollisionShapeFullBlock(zd, fu3)) {
                            ++integer9;
                            continue Label_0282_Outer;
                        }
                    }
                    ++integer8;
                    continue Label_0282_Outer;
                }
                final BlockState cfj3 = zd.getBlockState(fu3);
                if (cfj3.is(cfj2.getBlock()) && random.nextInt(10) == 0) {
                    ((BonemealableBlock)cfj2.getBlock()).performBonemeal(zd, random, fu3, cfj3);
                }
                if (!cfj3.isAir()) {
                    continue;
                }
                BlockState cfj4;
                if (random.nextInt(8) == 0) {
                    final List<ConfiguredFeature<?, ?>> list12 = zd.getBiome(fu3).getFlowerFeatures();
                    if (list12.isEmpty()) {
                        continue;
                    }
                    final ConfiguredFeature<?, ?> ckb13 = ((DecoratedFeatureConfiguration)list12.get(0).config).feature;
                    cfj4 = ((AbstractFlowerFeature)ckb13.feature).getRandomFlower(random, fu3, (FeatureConfiguration)ckb13.config);
                }
                else {
                    cfj4 = cfj2;
                }
                if (cfj4.canSurvive(zd, fu3)) {
                    zd.setBlock(fu3, cfj4, 3);
                }
                continue;
            }
        }
    }
}
