package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.StateDefinition;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.IntegerProperty;

public class SnowLayerBlock extends Block {
    public static final IntegerProperty LAYERS;
    protected static final VoxelShape[] SHAPE_BY_LAYER;
    
    protected SnowLayerBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((StateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)SnowLayerBlock.LAYERS, 1));
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        switch (czg) {
            case LAND: {
                return cfj.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS) < 5;
            }
            case WATER: {
                return false;
            }
            case AIR: {
                return false;
            }
            default: {
                return false;
            }
        }
    }
    
    @Override
    public VoxelShape getShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return SnowLayerBlock.SHAPE_BY_LAYER[cfj.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS)];
    }
    
    @Override
    public VoxelShape getCollisionShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return SnowLayerBlock.SHAPE_BY_LAYER[cfj.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS) - 1];
    }
    
    @Override
    public VoxelShape getBlockSupportShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu) {
        return SnowLayerBlock.SHAPE_BY_LAYER[cfj.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS)];
    }
    
    @Override
    public VoxelShape getVisualShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return SnowLayerBlock.SHAPE_BY_LAYER[cfj.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS)];
    }
    
    @Override
    public boolean useShapeForLightOcclusion(final BlockState cfj) {
        return true;
    }
    
    @Override
    public boolean canSurvive(final BlockState cfj, final LevelReader bqd, final BlockPos fu) {
        final BlockState cfj2 = bqd.getBlockState(fu.below());
        return !cfj2.is(Blocks.ICE) && !cfj2.is(Blocks.PACKED_ICE) && !cfj2.is(Blocks.BARRIER) && (cfj2.is(Blocks.HONEY_BLOCK) || cfj2.is(Blocks.SOUL_SAND) || Block.isFaceFull(cfj2.getCollisionShape(bqd, fu.below()), Direction.UP) || (cfj2.getBlock() == this && cfj2.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS) == 8));
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (!cfj1.canSurvive(bqc, fu5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public void randomTick(final BlockState cfj, final ServerLevel zd, final BlockPos fu, final Random random) {
        if (zd.getBrightness(LightLayer.BLOCK, fu) > 11) {
            Block.dropResources(cfj, zd, fu);
            zd.removeBlock(fu, false);
        }
    }
    
    @Override
    public boolean canBeReplaced(final BlockState cfj, final BlockPlaceContext bin) {
        final int integer4 = cfj.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS);
        if (bin.getItemInHand().getItem() == this.asItem() && integer4 < 8) {
            return !bin.replacingClickedOnBlock() || bin.getClickedFace() == Direction.UP;
        }
        return integer4 == 1;
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        final BlockState cfj3 = bin.getLevel().getBlockState(bin.getClickedPos());
        if (cfj3.is(this)) {
            final int integer4 = cfj3.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS);
            return ((StateHolder<O, BlockState>)cfj3).<Comparable, Integer>setValue((Property<Comparable>)SnowLayerBlock.LAYERS, Math.min(8, integer4 + 1));
        }
        return super.getStateForPlacement(bin);
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(SnowLayerBlock.LAYERS);
    }
    
    static {
        LAYERS = BlockStateProperties.LAYERS;
        SHAPE_BY_LAYER = new VoxelShape[] { Shapes.empty(), Block.box(0.0, 0.0, 0.0, 16.0, 2.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 4.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 6.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 10.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 12.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 14.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 16.0, 16.0) };
    }
}
