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 bfz) {
        final Level bjw3 = bfz.getLevel();
        final BlockPos fk4 = bfz.getClickedPos();
        final BlockState byj5 = bjw3.getBlockState(fk4);
        if (byj5.getBlock() == Blocks.LECTERN) {
            return LecternBlock.tryPlaceBook(bjw3, fk4, byj5, bfz.getItemInHand()) ? InteractionResult.SUCCESS : InteractionResult.PASS;
        }
        return InteractionResult.PASS;
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bjw, final Player ayj, final InteractionHand ajk) {
        final ItemStack ben5 = ayj.getItemInHand(ajk);
        ayj.openItemGui(ben5, ajk);
        ayj.awardStat(Stats.ITEM_USED.get(this));
        return InteractionResultHolder.<ItemStack>success(ben5);
    }
    
    public static boolean makeSureTagIsValid(@Nullable final CompoundTag jt) {
        if (jt == null) {
            return false;
        }
        if (!jt.contains("pages", 9)) {
            return false;
        }
        final ListTag jz2 = jt.getList("pages", 8);
        for (int integer3 = 0; integer3 < jz2.size(); ++integer3) {
            final String string4 = jz2.getString(integer3);
            if (string4.length() > 32767) {
                return false;
            }
        }
        return true;
    }
}
