From a97a4456071b940cbe0a12e6578ea33f76bb86ae Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Mon, 9 Dec 2024 18:54:34 +0000 Subject: [PATCH] Add an interface for meta- and nbt-aware music disks to fix modded disk support in electric jukeboxes (#96) --- .../api/MusicRecordMetadataProvider.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/gtnewhorizon/gtnhlib/api/MusicRecordMetadataProvider.java diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/api/MusicRecordMetadataProvider.java b/src/main/java/com/gtnewhorizon/gtnhlib/api/MusicRecordMetadataProvider.java new file mode 100644 index 0000000..6d9b1bc --- /dev/null +++ b/src/main/java/com/gtnewhorizon/gtnhlib/api/MusicRecordMetadataProvider.java @@ -0,0 +1,33 @@ +package com.gtnewhorizon.gtnhlib.api; + +import java.util.Collections; + +import net.minecraft.item.ItemRecord; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +/** + * Implement on classes extending {@link ItemRecord} to provide metadata and NBT-aware versions of the standard music + * metadata for use by other mods that implement custom jukeboxes. + */ +public interface MusicRecordMetadataProvider { + + /** + * @param stack The ItemStack to get the sound resource for. + * @return The ResourceLocation of the sound this record plays, or {@code null} if none. + */ + default ResourceLocation getMusicRecordResource(ItemStack stack) { + if (stack == null || stack.getItem() != this) { + return null; + } + final ItemRecord self = (ItemRecord) this; + return self.getRecordResource(self.recordName); + } + + /** + * @return A list of all variants of this music record item that have playable music. + */ + default Iterable getMusicRecordVariants() { + return Collections.singleton(new ItemStack((ItemRecord) this, 1, 0)); + } +}