package net.minecraft.world.item;

import com.google.common.collect.Maps;
import net.minecraft.network.chat.TranslatableComponent;
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 aah, final Properties a) {
        super(a);
        this.analogOutput = integer;
        this.sound = aah;
        RecordItem.BY_NAME.put(this.sound, this);
    }
    
    @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.JUKEBOX || byj5.<Boolean>getValue((Property<Boolean>)JukeboxBlock.HAS_RECORD)) {
            return InteractionResult.PASS;
        }
        final ItemStack ben6 = bfz.getItemInHand();
        if (!bjw3.isClientSide) {
            ((JukeboxBlock)Blocks.JUKEBOX).setRecord(bjw3, fk4, byj5, ben6);
            bjw3.levelEvent(null, 1010, fk4, Item.getId(this));
            ben6.shrink(1);
            final Player ayj7 = bfz.getPlayer();
            if (ayj7 != null) {
                ayj7.awardStat(Stats.PLAY_RECORD);
            }
        }
        return InteractionResult.SUCCESS;
    }
    
    public int getAnalogOutput() {
        return this.analogOutput;
    }
    
    @Override
    public void appendHoverText(final ItemStack ben, @Nullable final Level bjw, final List<Component> list, final TooltipFlag bfw) {
        list.add(this.getDisplayName().withStyle(ChatFormatting.GRAY));
    }
    
    public Component getDisplayName() {
        return new TranslatableComponent(this.getDescriptionId() + ".desc", new Object[0]);
    }
    
    @Nullable
    public static RecordItem getBySound(final SoundEvent aah) {
        return RecordItem.BY_NAME.get(aah);
    }
    
    public SoundEvent getSound() {
        return this.sound;
    }
    
    static {
        BY_NAME = Maps.newHashMap();
    }
}
