概述
本模组是 NoteBlock API 插件的 Fabric 移植版本,可以将 .nbs 文件在音符盒中播放声音。因一些限制,此模组无法完全实现原插件全部的功能。此处是 NoteBlock API 的 Spigot 网站。此模组只能在服务端或单人世界使用。
使用方法
添加到模组中
在其他模组中使用本 API,需要将 Modrinth 存储库添加到模组的 build 文件中的模组前置处。例如下面的代码,需要将 VERSION_TAG 替换为最新版本如 0.1.0+1.19。
repositories {
maven {
url "https://api.modrinth.com/maven"
content { includeGroup "maven.modrinth" }
}
}
dependencies {
modImplementation include("maven.modrinth:nota:VERSION_TAG")
}
获取 .nbs 文件
需要将歌曲的 .midi 文件转换为 .nbs 文件,作者推荐的方式是 Note Block Studio 的编辑器。
播放歌曲
必须先在模组中加载 .nbs 格式的歌曲,然后才能在游戏中播放它,加载方式如下,在模组中定义这些歌曲。
Song song = NBSDecoder.parse(new File("路径1.nbs"));
Song song2 = NBSDecoder.parse(new File("路径2.nbs"));
……
Playlist playlist = new Playlist(song, song2,...);
可以使歌曲播放的事件分为三种,分为广播,位置范围播放,实体范围播放。
音乐广播会给全服所有玩家播放音乐,无论他们的位置在何处,使用方式如下。
Song song; // 加载歌曲
RadioSongPlayer rsp = new RadioSongPlayer(song); // 创建音乐广播事件
rsp.setId(new Identifier("example:radio")); // 设置标识符,不是必须的
rsp.addPlayer(player); // 将玩家添加到歌曲收听
rsp.setPlaying(true); // 进行播放
位置范围播放会给一定指定范围内的所有玩家播放歌曲。
Song song;
PositionSongPlayer psp = new PositionSongPlayer(song); // 创建范围广播事件
psp.setId(new Identifier("example:position"));
psp.setBlockPos(pos); // 设置音乐播放的位置
psp.setDistance(16); // 设置音乐可以被玩家听见的最大距离
psp.addPlayer(player);
psp.setPlaying(true);
实体范围播放会为靠近某种实体一定范围的任意玩家播放音乐。
Song song;
EntitySongPlayer esp = new EntitySongPlayer(song); // 创建实体范围广播事件
esp.setId(new Identifier("example:entity"));
esp.setEntity(entity); //设置播放音乐的实体
esp.setDistance(16); // 设置音乐可以被玩家听见的最大距离
esp.addPlayer(player);
esp.setPlaying(true);