package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.BlockGetter;
import javax.annotation.Nullable;
import net.minecraft.network.chat.Component;
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.MenuProvider;
import net.minecraft.stats.Stats;
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.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.BlockPlaceContext;
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.network.chat.TranslatableComponent;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.DirectionProperty;

public class AnvilBlock extends FallingBlock {
    public static final DirectionProperty FACING;
    private static final VoxelShape BASE;
    private static final VoxelShape X_LEG1;
    private static final VoxelShape X_LEG2;
    private static final VoxelShape X_TOP;
    private static final VoxelShape Z_LEG1;
    private static final VoxelShape Z_LEG2;
    private static final VoxelShape Z_TOP;
    private static final VoxelShape X_AXIS_AABB;
    private static final VoxelShape Z_AXIS_AABB;
    private static final TranslatableComponent CONTAINER_TITLE;
    
    public AnvilBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Direction>setValue((Property<Comparable>)AnvilBlock.FACING, Direction.NORTH));
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)AnvilBlock.FACING, bcq.getHorizontalDirection().getClockWise());
    }
    
    @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) {
            return InteractionResult.SUCCESS;
        }
        ayj.openMenu(byj.getMenuProvider(bjw, fk));
        ayj.awardStat(Stats.INTERACT_WITH_ANVIL);
        return InteractionResult.SUCCESS;
    }
    
    @Nullable
    @Override
    public MenuProvider getMenuProvider(final BlockState byj, final Level bjw, final BlockPos fk) {
        return new SimpleMenuProvider((integer, ayi, ayj) -> new AnvilMenu(integer, ayi, ContainerLevelAccess.create(bjw, fk)), AnvilBlock.CONTAINER_TITLE);
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        final Direction fp6 = byj.<Direction>getValue((Property<Direction>)AnvilBlock.FACING);
        if (fp6.getAxis() == Direction.Axis.X) {
            return AnvilBlock.X_AXIS_AABB;
        }
        return AnvilBlock.Z_AXIS_AABB;
    }
    
    @Override
    protected void falling(final FallingBlockEntity awa) {
        awa.setHurtsEntities(true);
    }
    
    @Override
    public void onLand(final Level bjw, final BlockPos fk, final BlockState byj3, final BlockState byj4) {
        bjw.levelEvent(1031, fk, 0);
    }
    
    @Override
    public void onBroken(final Level bjw, final BlockPos fk) {
        bjw.levelEvent(1029, fk, 0);
    }
    
    @Nullable
    public static BlockState damage(final BlockState byj) {
        final Block bph2 = byj.getBlock();
        if (bph2 == Blocks.ANVIL) {
            return ((AbstractStateHolder<O, BlockState>)Blocks.CHIPPED_ANVIL.defaultBlockState()).<Comparable, Comparable>setValue((Property<Comparable>)AnvilBlock.FACING, (Comparable)byj.<V>getValue((Property<V>)AnvilBlock.FACING));
        }
        if (bph2 == Blocks.CHIPPED_ANVIL) {
            return ((AbstractStateHolder<O, BlockState>)Blocks.DAMAGED_ANVIL.defaultBlockState()).<Comparable, Comparable>setValue((Property<Comparable>)AnvilBlock.FACING, (Comparable)byj.<V>getValue((Property<V>)AnvilBlock.FACING));
        }
        return null;
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)AnvilBlock.FACING, btu.rotate(byj.<Direction>getValue((Property<Direction>)AnvilBlock.FACING)));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(AnvilBlock.FACING);
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    static {
        FACING = HorizontalDirectionalBlock.FACING;
        BASE = Block.box(2.0, 0.0, 2.0, 14.0, 4.0, 14.0);
        X_LEG1 = Block.box(3.0, 4.0, 4.0, 13.0, 5.0, 12.0);
        X_LEG2 = Block.box(4.0, 5.0, 6.0, 12.0, 10.0, 10.0);
        X_TOP = Block.box(0.0, 10.0, 3.0, 16.0, 16.0, 13.0);
        Z_LEG1 = Block.box(4.0, 4.0, 3.0, 12.0, 5.0, 13.0);
        Z_LEG2 = Block.box(6.0, 5.0, 4.0, 10.0, 10.0, 12.0);
        Z_TOP = Block.box(3.0, 10.0, 0.0, 13.0, 16.0, 16.0);
        X_AXIS_AABB = Shapes.or(AnvilBlock.BASE, AnvilBlock.X_LEG1, AnvilBlock.X_LEG2, AnvilBlock.X_TOP);
        Z_AXIS_AABB = Shapes.or(AnvilBlock.BASE, AnvilBlock.Z_LEG1, AnvilBlock.Z_LEG2, AnvilBlock.Z_TOP);
        CONTAINER_TITLE = new TranslatableComponent("container.repair", new Object[0]);
    }
}
