package net.minecraft.world.item;

import net.minecraft.sounds.SoundEvents;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

public class EmptyMapItem extends ComplexItem {
    public EmptyMapItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bqb, final Player bec, final InteractionHand anf) {
        final ItemStack bki5 = MapItem.create(bqb, Mth.floor(bec.getX()), Mth.floor(bec.getZ()), (byte)0, true, false);
        final ItemStack bki6 = bec.getItemInHand(anf);
        if (!bec.abilities.instabuild) {
            bki6.shrink(1);
        }
        bec.awardStat(Stats.ITEM_USED.get(this));
        bec.playSound(SoundEvents.UI_CARTOGRAPHY_TABLE_TAKE_RESULT, 1.0f, 1.0f);
        if (bki6.isEmpty()) {
            return InteractionResultHolder.<ItemStack>sidedSuccess(bki5, bqb.isClientSide());
        }
        if (!bec.inventory.add(bki5.copy())) {
            bec.drop(bki5, false);
        }
        return InteractionResultHolder.<ItemStack>sidedSuccess(bki6, bqb.isClientSide());
    }
}
