1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-24 16:07:01 +00:00

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

View File

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