diff --git a/README.md b/README.md index 1e89739..be30199 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ Disco is a modular music disc loader built for Fabric. Being a **loader**, it doesn't add any music discs by default and relies on addon packs to provide the sound files, textures, and translations. +## Usage + +Instructions on creating your own addon can be found [here][wiki]. + +For end users, the addon's `.jar` file should be placed in the fabric `mods` directory. + ## Dependencies - [Fabric Loader] @@ -14,17 +20,13 @@ Being a **loader**, it doesn't add any music discs by default and relies on addo You have three options for downloading Disco. -- [CurseForge] -- [Modrinth] - [GitHub Releases] +- [Modrinth] +- [CurseForge] -## Usage - -Disco addons are JAR files that contain a resource pack, a data pack, and a `fabric.mod.json`. An unpacked example can be found [here][example]. - -To create a JAR file from an unpacked addon, simply compress it into a zip file and rename the extension to `.jar`. +## Suggestions -> IMPORTANT: Make sure the `.ogg` files only have 1 audio channel (mono) +- [Vibes] - Portable music disc player @@ -36,8 +38,12 @@ To create a JAR file from an unpacked addon, simply compress it into a zip file [curseforge]: https://www.curseforge.com/minecraft/mc-mods/disco [modrinth]: https://modrinth.com/mod/disco -[github releases]: https://github.com/glossnyx/disco/releases +[github releases]: https://github.com/auxves/disco/releases + + + +[vibes]: https://github.com/auxves/vibes - + -[example]: https://github.com/glossnyx/disco/tree/example +[wiki]: https://github.com/auxves/disco/wiki/Adding-a-Disc diff --git a/build.gradle.kts b/build.gradle.kts index c3be646..4def417 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,11 +15,7 @@ dependencies { mappings("net.fabricmc:yarn:${p("yarn")}:v2") modImplementation("net.fabricmc:fabric-loader:${p("loader")}") - - listOf("fabric-resource-loader-v0", "fabric-loot-tables-v1", "fabric-registry-sync-v0").forEach { - modImplementation(fabricApi.module(it, p("fabric_api"))) - } - + modImplementation("net.fabricmc.fabric-api:fabric-api:${p("fabric_api")}") modImplementation("net.fabricmc:fabric-language-kotlin:${p("fabric_kotlin")}") } diff --git a/gradle.properties b/gradle.properties index 3edee61..3ae662a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.jvmargs=-Xmx1G # Project id=disco title=Disco -author=glossnyx +author=auxves description=Modular music disc loader -version=2.0.6 +version=2.0.7 # Versions (https://modmuss50.me/fabric.html) -minecraft=1.18.2 -yarn=1.18.2+build.2 -loader=0.13.3 +minecraft=1.19.2 +yarn=1.19.2+build.28 +loader=0.14.10 -fabric_api=0.48.0+1.18.2 -fabric_kotlin=1.7.1+kotlin.1.6.10 +fabric_api=0.66.0+1.19.2 +fabric_kotlin=1.8.6+kotlin.1.7.21 diff --git a/settings.gradle.kts b/settings.gradle.kts index d689260..8467b71 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ pluginManagement { } plugins { - id("fabric-loom") version "0.11-SNAPSHOT" - kotlin("jvm") version "1.6.10" + id("fabric-loom") version "1.0-SNAPSHOT" + kotlin("jvm") version "1.7.21" } } diff --git a/src/main/java/io/glossnyx/disco/mixin/LootTableAccessor.java b/src/main/java/io/glossnyx/disco/mixin/LootTableAccessor.java deleted file mode 100644 index 27daf84..0000000 --- a/src/main/java/io/glossnyx/disco/mixin/LootTableAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.glossnyx.disco.mixin; - -import net.minecraft.loot.LootPool; -import net.minecraft.loot.LootTable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(LootTable.class) -public interface LootTableAccessor { - @Accessor("pools") - LootPool[] getPools(); -} diff --git a/src/main/kotlin/dev/auxves/disco/Addons.kt b/src/main/kotlin/dev/auxves/disco/Addons.kt new file mode 100644 index 0000000..a6a1fc7 --- /dev/null +++ b/src/main/kotlin/dev/auxves/disco/Addons.kt @@ -0,0 +1,28 @@ +package dev.auxves.disco + +import net.fabricmc.loader.api.FabricLoader +import net.fabricmc.loader.api.metadata.ModMetadata +import net.minecraft.util.Identifier + +data class Addon( + val id: String, + val discs: List, +) + +private fun ModMetadata.toAddon(): Addon { + val custom = getCustomValue(modName).asObject + + val discs = custom.get("discs").asArray.map { + val obj = it.asObject + val identifier = Identifier(id, obj.get("id").asString) + val duration = obj.get("duration").asNumber.toInt() + + Disc(identifier, duration) + } + + return Addon(id, discs) +} + +val addons = FabricLoader.getInstance().allMods + .filter { it.metadata.customValues.containsKey(modName) } + .map { it.metadata.toAddon() } diff --git a/src/main/kotlin/dev/auxves/disco/Disc.kt b/src/main/kotlin/dev/auxves/disco/Disc.kt new file mode 100644 index 0000000..0393e1d --- /dev/null +++ b/src/main/kotlin/dev/auxves/disco/Disc.kt @@ -0,0 +1,21 @@ +package dev.auxves.disco + +import net.minecraft.item.Item +import net.minecraft.item.ItemGroup +import net.minecraft.item.ItemStack +import net.minecraft.item.MusicDiscItem +import net.minecraft.sound.SoundEvent +import net.minecraft.text.Text +import net.minecraft.util.Identifier +import net.minecraft.util.Rarity + +private val settings = Item.Settings() + .group(ItemGroup.MISC) + .rarity(Rarity.RARE) + .maxCount(1) + +class Disc(val id: Identifier, duration: Int) : MusicDiscItem(15, SoundEvent(id), settings, duration) { + override fun getName(stack: ItemStack?): Text { + return Text.translatable("item.minecraft.music_disc_cat") + } +} diff --git a/src/main/kotlin/dev/auxves/disco/Entrypoint.kt b/src/main/kotlin/dev/auxves/disco/Entrypoint.kt new file mode 100644 index 0000000..15f5dcc --- /dev/null +++ b/src/main/kotlin/dev/auxves/disco/Entrypoint.kt @@ -0,0 +1,14 @@ +package dev.auxves.disco + +import net.minecraft.util.registry.Registry + +const val modName = "disco" + +@Suppress("unused") +fun init() { + addons.flatMap { it.discs }.forEach { + Registry.register(Registry.ITEM, it.id, it) + } + + println("Disco loaded!") +} \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/disco/Addons.kt b/src/main/kotlin/io/glossnyx/disco/Addons.kt deleted file mode 100644 index 29d1746..0000000 --- a/src/main/kotlin/io/glossnyx/disco/Addons.kt +++ /dev/null @@ -1,35 +0,0 @@ -package io.glossnyx.disco - -import net.fabricmc.loader.api.FabricLoader -import net.fabricmc.loader.api.metadata.CustomValue -import net.fabricmc.loader.api.metadata.ModMetadata -import net.minecraft.util.Identifier - -data class Addon( - val id: String, - val discs: List, - val tables: Map> -) - -fun CustomValue.CvObject.toIdentifierMap() = associate { (key, value) -> - Identifier(key) to value.asArray.toList().map { Identifier(it.asString) } -} - -fun ModMetadata.toAddon(): Addon { - val custom = getCustomValue(modName).asObject - - val discs = custom.get("discs").asArray.map { Disc(Identifier(id, it.asString)) } - - val tables = custom.get("tables").let { - when (it.type) { - CustomValue.CvType.OBJECT -> it.asObject.toIdentifierMap() - else -> mapOf() - } - } - - return Addon(id, discs, tables) -} - -val addons = FabricLoader.getInstance().allMods - .filter { it.metadata.customValues.containsKey(modName) } - .map { it.metadata.toAddon() } diff --git a/src/main/kotlin/io/glossnyx/disco/Entrypoint.kt b/src/main/kotlin/io/glossnyx/disco/Entrypoint.kt deleted file mode 100644 index 4d44f9e..0000000 --- a/src/main/kotlin/io/glossnyx/disco/Entrypoint.kt +++ /dev/null @@ -1,46 +0,0 @@ -package io.glossnyx.disco - -import io.glossnyx.disco.mixin.LootTableAccessor -import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback -import net.minecraft.item.Item -import net.minecraft.item.ItemGroup -import net.minecraft.item.ItemStack -import net.minecraft.item.MusicDiscItem -import net.minecraft.sound.SoundEvent -import net.minecraft.text.Text -import net.minecraft.text.TranslatableText -import net.minecraft.util.Identifier -import net.minecraft.util.Rarity -import net.minecraft.util.registry.Registry - -const val modName = "disco" - -fun init() { - addons.flatMap { it.discs }.forEach { - Registry.register(Registry.ITEM, it.id, it) - } - - LootTableLoadingCallback.EVENT.register { _, lootManager, id, supplier, _ -> - val tables = addons - .flatMap { it.tables.entries } - .filter { it.value.contains(id) } - .map { it.key } - .distinct() - - tables.forEach { - val table = lootManager.getTable(it) as LootTableAccessor - table.pools.forEach(supplier::withPool) - } - } -} - -private val settings = Item.Settings() - .group(ItemGroup.MISC) - .rarity(Rarity.RARE) - .maxCount(1) - -class Disc(val id: Identifier) : MusicDiscItem(15, SoundEvent(id), settings) { - override fun getName(stack: ItemStack?): Text { - return TranslatableText("item.${modName}.all.name") - } -} diff --git a/src/main/resources/assets/disco/lang/en_us.json b/src/main/resources/assets/disco/lang/en_us.json deleted file mode 100644 index a6e651d..0000000 --- a/src/main/resources/assets/disco/lang/en_us.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "item.disco.all.name": "Music Disc" -} diff --git a/src/main/resources/disco.mixins.json b/src/main/resources/disco.mixins.json deleted file mode 100644 index 4a06ec7..0000000 --- a/src/main/resources/disco.mixins.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "io.glossnyx.disco.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": ["LootTableAccessor"], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 455523c..b85f368 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -6,22 +6,19 @@ "description": "${description}", "authors": ["${author}"], "contact": { - "homepage": "https://github.com/${author}/${id}", + "homepage": "https://auxves.dev/${id}", "sources": "https://github.com/${author}/${id}" }, "license": "MIT", "icon": "assets/${id}/icon.png", "environment": "*", "entrypoints": { - "main": ["io.${author}.${id}.EntrypointKt::init"] + "main": ["dev.${author}.${id}.EntrypointKt::init"] }, - "mixins": ["${id}.mixins.json"], + "mixins": [], "depends": { - "minecraft": "1.18.x", - "fabricloader": "*", - "fabric-resource-loader-v0": "*", - "fabric-loot-tables-v1": "*", - "fabric-registry-sync-v0": "*", + "minecraft": "1.19.x", + "fabric-api": "*", "fabric-language-kotlin": "*" } }