尝试在 Minecraft 中播放声音会导致 [Client thread/WARN]: Unable to play unknown soundEvent
Attempting to play a sound in Minecraft results in [Client thread/WARN]: Unable to play unknown soundEvent
我有一个程序可以在正则表达式与未格式化的消息匹配时播放声音
@SubscribeEvent
public void ChatRecieved(ClientChatReceivedEvent event) {
String message = event.message.getUnformattedText();
Matcher m = regex.matcher(message);
if (m.matches()) {
Minecraft.getMinecraft().thePlayer.playSound("BazaarAlert:sound", 1, 1);
}
}
但是,声音没有播放并且
[Client thread/WARN]: Unable to play unknown soundEvent: bazaaralert:sound
被发送到控制台。
这是我的 sounds.json:
{
"sound": {
"category": "ambient",
"sounds": [
{
"name": "sound",
"stream": false
}
]
}
}
以下是我的项目在 Eclipse 中的格式化方式:
尝试使用资源位置:Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("your/resource/here.ogg")));
显然你不能有一个有大写字母的命名空间(比如 BazaarAlert),sounds.json 只需要带有
的名称
stream: false
仅使用 JSON 的名字使用 Luca100 的 ResourceLocation 解决方案。
例如:
{
"whatever_you_want_the_sound_to_be_name": {
"category": "category",
"sounds": [
{"file"}
]
}
}
会是
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation(this.MODID, "sound"), 1.0F));
我有一个程序可以在正则表达式与未格式化的消息匹配时播放声音
@SubscribeEvent
public void ChatRecieved(ClientChatReceivedEvent event) {
String message = event.message.getUnformattedText();
Matcher m = regex.matcher(message);
if (m.matches()) {
Minecraft.getMinecraft().thePlayer.playSound("BazaarAlert:sound", 1, 1);
}
}
但是,声音没有播放并且
[Client thread/WARN]: Unable to play unknown soundEvent: bazaaralert:sound
被发送到控制台。 这是我的 sounds.json:
{
"sound": {
"category": "ambient",
"sounds": [
{
"name": "sound",
"stream": false
}
]
}
}
以下是我的项目在 Eclipse 中的格式化方式:
尝试使用资源位置:Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("your/resource/here.ogg")));
显然你不能有一个有大写字母的命名空间(比如 BazaarAlert),sounds.json 只需要带有
的名称stream: false
仅使用 JSON 的名字使用 Luca100 的 ResourceLocation 解决方案。
例如:
{
"whatever_you_want_the_sound_to_be_name": {
"category": "category",
"sounds": [
{"file"}
]
}
}
会是
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation(this.MODID, "sound"), 1.0F));