package net.minecraft.world.item;

import com.google.common.collect.Maps;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.JukeboxBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.InteractionResult;
import net.minecraft.sounds.SoundEvent;
import java.util.Map;

public class RecordItem extends Item {
    private static final Map<SoundEvent, RecordItem> BY_NAME;
    private final int analogOutput;
    private final SoundEvent sound;
    
    protected RecordItem(final int integer, final SoundEvent ack, final Properties a) {
        super(a);
        this.analogOutput = integer;
        this.sound = ack;
        RecordItem.BY_NAME.put(this.sound, this);
    }
    
    @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.JUKEBOX) || cfj5.<Boolean>getValue((Property<Boolean>)JukeboxBlock.HAS_RECORD)) {
            return InteractionResult.PASS;
        }
        final ItemStack bki6 = blv.getItemInHand();
        if (!bqb3.isClientSide) {
            ((JukeboxBlock)Blocks.JUKEBOX).setRecord(bqb3, fu4, cfj5, bki6);
            bqb3.levelEvent(null, 1010, fu4, Item.getId(this));
            bki6.shrink(1);
            final Player bec7 = blv.getPlayer();
            if (bec7 != null) {
                bec7.awardStat(Stats.PLAY_RECORD);
            }
        }
        return InteractionResult.sidedSuccess(bqb3.isClientSide);
    }
    
    public int getAnalogOutput() {
        return this.analogOutput;
    }
    
    @Override
    public void appendHoverText(final ItemStack bki, @Nullable final Level bqb, final List<Component> list, final TooltipFlag bls) {
        list.add(this.getDisplayName().withStyle(ChatFormatting.GRAY));
    }
    
    public MutableComponent getDisplayName() {
        return new TranslatableComponent(this.getDescriptionId() + ".desc");
    }
    
    @Nullable
    public static RecordItem getBySound(final SoundEvent ack) {
        return RecordItem.BY_NAME.get(ack);
    }
    
    public SoundEvent getSound() {
        return this.sound;
    }
    
    static {
        BY_NAME = Maps.newHashMap();
    }
}
