package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.tags.Tag;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.LevelReader;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.core.Direction;
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 CocoaBlock extends HorizontalDirectionalBlock implements BonemealableBlock {
    public static final IntegerProperty AGE;
    protected static final VoxelShape[] EAST_AABB;
    protected static final VoxelShape[] WEST_AABB;
    protected static final VoxelShape[] NORTH_AABB;
    protected static final VoxelShape[] SOUTH_AABB;
    
    public CocoaBlock(final Properties c) {
        super(c);
        this.registerDefaultState((((StateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)CocoaBlock.FACING, Direction.NORTH)).<Comparable, Integer>setValue((Property<Comparable>)CocoaBlock.AGE, 0));
    }
    
    @Override
    public boolean isRandomlyTicking(final BlockState cfj) {
        return cfj.<Integer>getValue((Property<Integer>)CocoaBlock.AGE) < 2;
    }
    
    @Override
    public void randomTick(final BlockState cfj, final ServerLevel zd, final BlockPos fu, final Random random) {
        if (zd.random.nextInt(5) == 0) {
            final int integer6 = cfj.<Integer>getValue((Property<Integer>)CocoaBlock.AGE);
            if (integer6 < 2) {
                zd.setBlock(fu, ((StateHolder<O, BlockState>)cfj).<Comparable, Integer>setValue((Property<Comparable>)CocoaBlock.AGE, integer6 + 1), 2);
            }
        }
    }
    
    @Override
    public boolean canSurvive(final BlockState cfj, final LevelReader bqd, final BlockPos fu) {
        final Block bvr5 = bqd.getBlockState(fu.relative(cfj.<Direction>getValue((Property<Direction>)CocoaBlock.FACING))).getBlock();
        return bvr5.is(BlockTags.JUNGLE_LOGS);
    }
    
    @Override
    public VoxelShape getShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        final int integer6 = cfj.<Integer>getValue((Property<Integer>)CocoaBlock.AGE);
        switch (cfj.<Direction>getValue((Property<Direction>)CocoaBlock.FACING)) {
            case SOUTH: {
                return CocoaBlock.SOUTH_AABB[integer6];
            }
            default: {
                return CocoaBlock.NORTH_AABB[integer6];
            }
            case WEST: {
                return CocoaBlock.WEST_AABB[integer6];
            }
            case EAST: {
                return CocoaBlock.EAST_AABB[integer6];
            }
        }
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        BlockState cfj3 = this.defaultBlockState();
        final LevelReader bqd4 = bin.getLevel();
        final BlockPos fu5 = bin.getClickedPos();
        for (final Direction fz9 : bin.getNearestLookingDirections()) {
            if (fz9.getAxis().isHorizontal()) {
                cfj3 = ((StateHolder<O, BlockState>)cfj3).<Comparable, Direction>setValue((Property<Comparable>)CocoaBlock.FACING, fz9);
                if (cfj3.canSurvive(bqd4, fu5)) {
                    return cfj3;
                }
            }
        }
        return null;
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (fz == cfj1.<Direction>getValue((Property<Direction>)CocoaBlock.FACING) && !cfj1.canSurvive(bqc, fu5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public boolean isValidBonemealTarget(final BlockGetter bpg, final BlockPos fu, final BlockState cfj, final boolean boolean4) {
        return cfj.<Integer>getValue((Property<Integer>)CocoaBlock.AGE) < 2;
    }
    
    @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) {
        zd.setBlock(fu, ((StateHolder<O, BlockState>)cfj).<Comparable, Integer>setValue((Property<Comparable>)CocoaBlock.AGE, cfj.<Integer>getValue((Property<Integer>)CocoaBlock.AGE) + 1), 2);
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(CocoaBlock.FACING, CocoaBlock.AGE);
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        return false;
    }
    
    static {
        AGE = BlockStateProperties.AGE_2;
        EAST_AABB = new VoxelShape[] { Block.box(11.0, 7.0, 6.0, 15.0, 12.0, 10.0), Block.box(9.0, 5.0, 5.0, 15.0, 12.0, 11.0), Block.box(7.0, 3.0, 4.0, 15.0, 12.0, 12.0) };
        WEST_AABB = new VoxelShape[] { Block.box(1.0, 7.0, 6.0, 5.0, 12.0, 10.0), Block.box(1.0, 5.0, 5.0, 7.0, 12.0, 11.0), Block.box(1.0, 3.0, 4.0, 9.0, 12.0, 12.0) };
        NORTH_AABB = new VoxelShape[] { Block.box(6.0, 7.0, 1.0, 10.0, 12.0, 5.0), Block.box(5.0, 5.0, 1.0, 11.0, 12.0, 7.0), Block.box(4.0, 3.0, 1.0, 12.0, 12.0, 9.0) };
        SOUTH_AABB = new VoxelShape[] { Block.box(6.0, 7.0, 11.0, 10.0, 12.0, 15.0), Block.box(5.0, 5.0, 9.0, 11.0, 12.0, 15.0), Block.box(4.0, 3.0, 7.0, 12.0, 12.0, 15.0) };
    }
}
