81 lines
2.7 KiB
Java
81 lines
2.7 KiB
Java
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 bfw) {
|
|
final Level bjt3 = bfw.getLevel();
|
|
final BlockPos fk4 = bfw.getClickedPos();
|
|
final BlockState byg5 = bjt3.getBlockState(fk4);
|
|
if (byg5.getBlock() != Blocks.JUKEBOX || byg5.<Boolean>getValue((Property<Boolean>)JukeboxBlock.HAS_RECORD)) {
|
|
return InteractionResult.PASS;
|
|
}
|
|
final ItemStack bek6 = bfw.getItemInHand();
|
|
if (!bjt3.isClientSide) {
|
|
((JukeboxBlock)Blocks.JUKEBOX).setRecord(bjt3, fk4, byg5, bek6);
|
|
bjt3.levelEvent(null, 1010, fk4, Item.getId(this));
|
|
bek6.shrink(1);
|
|
final Player ayg7 = bfw.getPlayer();
|
|
if (ayg7 != null) {
|
|
ayg7.awardStat(Stats.PLAY_RECORD);
|
|
}
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
|
|
public int getAnalogOutput() {
|
|
return this.analogOutput;
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(final ItemStack bek, @Nullable final Level bjt, final List<Component> list, final TooltipFlag bft) {
|
|
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();
|
|
}
|
|
}
|