|
if (itemStack.getItem() instanceof MusicDiscItem musicDiscItem){
SoundEvent sound = musicDiscItem.getSound();
player.playSound(sound, xxxxxx);
player.getWorld().playSound(sound,xxxxxx);
}
解释:将item转为MusicDiscItem,通过MusicDiscItem获取SoundEvent 对象,用player或world的playsound方法传入SoundEvent 对象 |
|