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:
parent
1e214f329e
commit
c7e49d1929
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user