From c7e49d1929b02f5520fe38d0289be625d4f0dc6a Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 9 May 2024 22:54:03 +0100 Subject: [PATCH] Use RecordItem.getDisplayName to get audio title Rather than constructing the component manually. This should be more compatible with mods that override getDisplayName. --- .../computercraft/shared/media/items/RecordMedia.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/projects/common/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java b/projects/common/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java index 86c638528..8442d7d17 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java @@ -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 net.minecraft.world.item.RecordItem; 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 @@ public final class RecordMedia implements IMedia { @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; } }