package net.minecraft.world.item;

import net.minecraft.nbt.ListTag;
import javax.annotation.Nullable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.LecternBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.InteractionResult;

public class WritableBookItem extends Item {
    public WritableBookItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext blv) {
        final Level bqb3 = blv.getLevel();
        final BlockPos fu4 = blv.getClickedPos();
        final BlockState cfj5 = bqb3.getBlockState(fu4);
        if (cfj5.is(Blocks.LECTERN)) {
            return LecternBlock.tryPlaceBook(bqb3, fu4, cfj5, blv.getItemInHand()) ? InteractionResult.sidedSuccess(bqb3.isClientSide) : InteractionResult.PASS;
        }
        return InteractionResult.PASS;
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bqb, final Player bec, final InteractionHand anf) {
        final ItemStack bki5 = bec.getItemInHand(anf);
        bec.openItemGui(bki5, anf);
        bec.awardStat(Stats.ITEM_USED.get(this));
        return InteractionResultHolder.<ItemStack>sidedSuccess(bki5, bqb.isClientSide());
    }
    
    public static boolean makeSureTagIsValid(@Nullable final CompoundTag le) {
        if (le == null) {
            return false;
        }
        if (!le.contains("pages", 9)) {
            return false;
        }
        final ListTag lk2 = le.getList("pages", 8);
        for (int integer3 = 0; integer3 < lk2.size(); ++integer3) {
            final String string4 = lk2.getString(integer3);
            if (string4.length() > 32767) {
                return false;
            }
        }
        return true;
    }
}
