package net.minecraft.world.level.block;

import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.tags.Tag;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockGetter;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class CoralBlock extends Block {
    private final Block deadBlock;
    
    public CoralBlock(final Block bvr, final Properties c) {
        super(c);
        this.deadBlock = bvr;
    }
    
    @Override
    public void tick(final BlockState cfj, final ServerLevel zd, final BlockPos fu, final Random random) {
        if (!this.scanForWater(zd, fu)) {
            zd.setBlock(fu, this.deadBlock.defaultBlockState(), 2);
        }
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (!this.scanForWater(bqc, fu5)) {
            bqc.getBlockTicks().scheduleTick(fu5, this, 60 + bqc.getRandom().nextInt(40));
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    protected boolean scanForWater(final BlockGetter bpg, final BlockPos fu) {
        for (final Direction fz7 : Direction.values()) {
            final FluidState cxa8 = bpg.getFluidState(fu.relative(fz7));
            if (cxa8.is(FluidTags.WATER)) {
                return true;
            }
        }
        return false;
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        if (!this.scanForWater(bin.getLevel(), bin.getClickedPos())) {
            bin.getLevel().getBlockTicks().scheduleTick(bin.getClickedPos(), this, 60 + bin.getLevel().getRandom().nextInt(40));
        }
        return this.defaultBlockState();
    }
}
