package net.minecraft.world.level.block;

import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;

public class GrassPathBlock extends Block {
    protected static final VoxelShape SHAPE;
    
    protected GrassPathBlock(final Properties c) {
        super(c);
    }
    
    @Override
    public boolean useShapeForLightOcclusion(final BlockState byj) {
        return true;
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        if (!this.defaultBlockState().canSurvive(bcq.getLevel(), bcq.getClickedPos())) {
            return Block.pushEntitiesUp(this.defaultBlockState(), Blocks.DIRT.defaultBlockState(), bcq.getLevel(), bcq.getClickedPos());
        }
        return super.getStateForPlacement(bcq);
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (fp == Direction.UP && !byj1.canSurvive(bjx, fk5)) {
            bjx.getBlockTicks().scheduleTick(fk5, this, 1);
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public void tick(final BlockState byj, final ServerLevel xd, final BlockPos fk, final Random random) {
        FarmBlock.turnToDirt(byj, xd, fk);
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        final BlockState byj2 = bjz.getBlockState(fk.above());
        return !byj2.getMaterial().isSolid() || byj2.getBlock() instanceof FenceGateBlock;
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return GrassPathBlock.SHAPE;
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    @Override
    public boolean isViewBlocking(final BlockState byj, final BlockGetter bjg, final BlockPos fk) {
        return true;
    }
    
    static {
        SHAPE = FarmBlock.SHAPE;
    }
}
