package net.minecraft.world.level.block;

import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.LivingEntity;
import javax.annotation.Nullable;
import net.minecraft.network.chat.Component;
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.inventory.EnchantmentMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.Nameable;
import net.minecraft.world.MenuProvider;
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.block.entity.EnchantmentTableBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import java.util.Random;
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.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.phys.shapes.VoxelShape;

public class EnchantmentTableBlock extends BaseEntityBlock {
    protected static final VoxelShape SHAPE;
    
    protected EnchantmentTableBlock(final Properties c) {
        super(c);
    }
    
    @Override
    public boolean useShapeForLightOcclusion(final BlockState cfj) {
        return true;
    }
    
    @Override
    public VoxelShape getShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return EnchantmentTableBlock.SHAPE;
    }
    
    @Override
    public void animateTick(final BlockState cfj, final Level bqb, final BlockPos fu, final Random random) {
        super.animateTick(cfj, bqb, fu, random);
        for (int integer6 = -2; integer6 <= 2; ++integer6) {
            for (int integer7 = -2; integer7 <= 2; ++integer7) {
                if (integer6 > -2 && integer6 < 2 && integer7 == -1) {
                    integer7 = 2;
                }
                if (random.nextInt(16) == 0) {
                    for (int integer8 = 0; integer8 <= 1; ++integer8) {
                        final BlockPos fu2 = fu.offset(integer6, integer8, integer7);
                        if (bqb.getBlockState(fu2).is(Blocks.BOOKSHELF)) {
                            if (!bqb.isEmptyBlock(fu.offset(integer6 / 2, 0, integer7 / 2))) {
                                break;
                            }
                            bqb.addParticle(ParticleTypes.ENCHANT, fu.getX() + 0.5, fu.getY() + 2.0, fu.getZ() + 0.5, integer6 + random.nextFloat() - 0.5, integer8 - random.nextFloat() - 1.0f, integer7 + random.nextFloat() - 0.5);
                        }
                    }
                }
            }
        }
    }
    
    @Override
    public RenderShape getRenderShape(final BlockState cfj) {
        return RenderShape.MODEL;
    }
    
    @Override
    public BlockEntity newBlockEntity(final BlockGetter bpg) {
        return new EnchantmentTableBlockEntity();
    }
    
    @Override
    public InteractionResult use(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec, final InteractionHand anf, final BlockHitResult deh) {
        if (bqb.isClientSide) {
            return InteractionResult.SUCCESS;
        }
        bec.openMenu(cfj.getMenuProvider(bqb, fu));
        return InteractionResult.CONSUME;
    }
    
    @Nullable
    @Override
    public MenuProvider getMenuProvider(final BlockState cfj, final Level bqb, final BlockPos fu) {
        final BlockEntity cdl5 = bqb.getBlockEntity(fu);
        if (cdl5 instanceof EnchantmentTableBlockEntity) {
            final Component mr6 = ((Nameable)cdl5).getDisplayName();
            return new SimpleMenuProvider((integer, beb, bec) -> new EnchantmentMenu(integer, beb, ContainerLevelAccess.create(bqb, fu)), mr6);
        }
        return null;
    }
    
    @Override
    public void setPlacedBy(final Level bqb, final BlockPos fu, final BlockState cfj, final LivingEntity aoy, final ItemStack bki) {
        if (bki.hasCustomHoverName()) {
            final BlockEntity cdl7 = bqb.getBlockEntity(fu);
            if (cdl7 instanceof EnchantmentTableBlockEntity) {
                ((EnchantmentTableBlockEntity)cdl7).setCustomName(bki.getHoverName());
            }
        }
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        return false;
    }
    
    static {
        SHAPE = Block.box(0.0, 0.0, 0.0, 16.0, 12.0, 16.0);
    }
}
