Use RecordItem.getDisplayName to get audio title

Rather than constructing the component manually. This should be more
compatible with mods that override getDisplayName.
This commit is contained in:
Jonathan Coates 2024-05-09 22:54:03 +01:00
parent 1e214f329e
commit c7e49d1929
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
1 changed files with 3 additions and 8 deletions

View File

@ -5,7 +5,6 @@
package dan200.computercraft.shared.media.items;
import dan200.computercraft.api.media.IMedia;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.RecordItem;
@ -13,7 +12,7 @@
import javax.annotation.Nullable;
/**
* An implementation of IMedia for ItemRecords.
* An implementation of {@link IMedia} for {@link RecordItem}.
*/
public final class RecordMedia implements IMedia {
public static final RecordMedia INSTANCE = new RecordMedia();
@ -29,16 +28,12 @@ private RecordMedia() {
@Override
public @Nullable String getAudioTitle(ItemStack stack) {
var item = stack.getItem();
if (!(item instanceof RecordItem)) return null;
return Component.translatable(item.getDescriptionId() + ".desc").getString();
return item instanceof RecordItem record ? record.getDisplayName().getString() : null;
}
@Override
public @Nullable SoundEvent getAudio(ItemStack stack) {
var item = stack.getItem();
if (!(item instanceof RecordItem)) return null;
return ((RecordItem) item).getSound();
return item instanceof RecordItem record ? record.getSound() : null;
}
}