获取当前歌曲
这是一个简单的 FabricMC 模组,允许你通过命令获取 Minecraft 中当前播放的歌曲。你可以在 Modrinth 下载最新版本。
命令
该模组向游戏添加了两个命令:
/getsong — 获取当前播放歌曲的信息,例如名称和作曲家。
/getsongid — 获取当前播放歌曲的 命名空间 ID。
不过,除了使用这些命令外,你还可以在 F3 屏幕 上查看相同的信息。
API
该模组提供了一种基于资源包的方法来获取 Minecraft 中歌曲的信息,如名称、作曲家、专辑和曲目编号。
资源包开发者
如果你的资源包为游戏添加了自定义音乐,请考虑将你的歌曲添加到资源包中的 getcurrentsong/song_names.json 文件中。此 JSON 文件有一个根对象,键为歌曲 ID,值为一个对象,其格式如下所述:
{
"name": "歌曲名称(字符串,必填)",
"composer": "作曲家姓名(字符串,必填)",
"soundtrack": "专辑名称(字符串,可选)",
"trackNumber": "专辑中的曲目编号(整数,可选)"
}
如果指定了 soundtrack,则必须同时指定 trackNumber,反之亦然。
模组开发者
要在 Gradle 中包含此模组的 API,请将以下内容添加到你的 build.gradle 中(代码改编自 Modrinth Maven 文档):
repositories {
// 其他 Maven 仓库可以放在 Modrinth 之上(或之下)。我们不需要优先级 :)
// 请记住,这是声明插件的 `repositories` 块,而不是在 `pluginManagement` 中!
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
modApi "maven.modrinth:getcurrentsong:1.0.1"
}
一旦将 API 添加到你的 build.gradle 中,你就可以使用以下 API 从资源包中加载歌曲信息(SongNameDatabase 类位于 io.github.gaming32.getcurrentsong 包中):
SongNameDatabase#isInitialized — 如果歌曲信息当前处于已加载状态,则返回 true。当此方法返回 false 时尝试读取数据库可能不会返回正确数据。请注意!
SongNameDatabase#getSong — 根据名称或 net.minecraft.util.Identifier 获取当前歌曲,并返回一个 SongNameDatabase.SongInfo 对象;如果在数据库中未找到该歌曲,则返回 null。
Get Current Song
This is a simple FabricMC mod that allows you to get the currently playing song in Minecraft via a command. You can download the latest version on Modrinth.
Commands
This mod adds two commands to the game:
/getsong — Gets information about the currently playing song, such as the name and composer.
/getsongid — Gets the namespaced ID of the currently playing song.
However, instead of using these commands, you can see the same information on the F3 screen.
API
This mod provides a resource-based method of getting information about the songs in Minecraft, such as name, composer, album, and track number.
Resource pack developers
If your resource pack adds custom music to the game, consider adding your song(s) to the getcurrentsong/song_names.json file in your resource pack. This JSON file has one root object, with keys being the song IDs and values being an object whose form is described below:
{
"name": "song name (string, required)",
"composer": "composer's name (string, required)",
"soundtrack": "album name (string, optional)",
"trackNumber": "track number in album (integer, optional)"
}
If the soundtrack is specified, the track number must also be specified, and vice-versa.
Mod develepers
To include this mod's API with Gradle, add the following to your build.gradle (code adapted from the Modrinth Maven docs):
repositories {
// Other Maven repositories can go above (or below) Modrinth's. We don't need priority :)
// Do remember, though, this is the `repositories` block below where plugins are declared, not in `pluginManagement`!
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
modApi "maven.modrinth:getcurrentsong:1.0.1"
}
Once you have added the API to your build.gradle, you can load song information from resource packs using the following API (the SongNameDatabase class is in the io.github.gaming32.getcurrentsong package):
SongNameDatabase#isInitialized — Return true if the song info is currently in a loaded state. Attempting to read from the database when this returns false may not return correct data. You have been warned!
SongNameDatabase#getSong — Gets the current song by name or net.minecraft.util.Identifier and returns a SongNameDatabase.SongInfo object or null if the song wasn't found in the database.
评论 0
登录后参与评分
还没有评论,来抢沙发吧