package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
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.LevelReader;
import net.minecraft.core.Direction;
import net.minecraft.stats.Stats;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.shapes.CollisionContext;
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.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.IntegerProperty;

public class CakeBlock extends Block {
    public static final IntegerProperty BITES;
    protected static final VoxelShape[] SHAPE_BY_BITE;
    
    protected CakeBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)CakeBlock.BITES, 0));
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return CakeBlock.SHAPE_BY_BITE[byj.<Integer>getValue((Property<Integer>)CakeBlock.BITES)];
    }
    
    @Override
    public InteractionResult use(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj, final InteractionHand ajk, final BlockHitResult cvg) {
        if (bjw.isClientSide) {
            final ItemStack ben8 = ayj.getItemInHand(ajk);
            if (this.eat(bjw, fk, byj, ayj) == InteractionResult.SUCCESS) {
                return InteractionResult.SUCCESS;
            }
            if (ben8.isEmpty()) {
                return InteractionResult.CONSUME;
            }
        }
        return this.eat(bjw, fk, byj, ayj);
    }
    
    private InteractionResult eat(final LevelAccessor bjx, final BlockPos fk, final BlockState byj, final Player ayj) {
        if (!ayj.canEat(false)) {
            return InteractionResult.PASS;
        }
        ayj.awardStat(Stats.EAT_CAKE_SLICE);
        ayj.getFoodData().eat(2, 0.1f);
        final int integer6 = byj.<Integer>getValue((Property<Integer>)CakeBlock.BITES);
        if (integer6 < 6) {
            bjx.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Integer>setValue((Property<Comparable>)CakeBlock.BITES, integer6 + 1), 3);
        }
        else {
            bjx.removeBlock(fk, false);
        }
        return InteractionResult.SUCCESS;
    }
    
    @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.DOWN && !byj1.canSurvive(bjx, fk5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        return bjz.getBlockState(fk.below()).getMaterial().isSolid();
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(CakeBlock.BITES);
    }
    
    @Override
    public int getAnalogOutputSignal(final BlockState byj, final Level bjw, final BlockPos fk) {
        return (7 - byj.<Integer>getValue((Property<Integer>)CakeBlock.BITES)) * 2;
    }
    
    @Override
    public boolean hasAnalogOutputSignal(final BlockState byj) {
        return true;
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    static {
        BITES = BlockStateProperties.BITES;
        SHAPE_BY_BITE = new VoxelShape[] { Block.box(1.0, 0.0, 1.0, 15.0, 8.0, 15.0), Block.box(3.0, 0.0, 1.0, 15.0, 8.0, 15.0), Block.box(5.0, 0.0, 1.0, 15.0, 8.0, 15.0), Block.box(7.0, 0.0, 1.0, 15.0, 8.0, 15.0), Block.box(9.0, 0.0, 1.0, 15.0, 8.0, 15.0), Block.box(11.0, 0.0, 1.0, 15.0, 8.0, 15.0), Block.box(13.0, 0.0, 1.0, 15.0, 8.0, 15.0) };
    }
}
