跳到主要内容

26自定义音乐光盘

自定义音乐光盘

在ModSounds中添加:

public static final SoundEvent BAR_BRAWL = registerSoundEvent("bar_brawl");

然后注册一个物品ModItems中:

public static final Item BAR_BRAWL_MUSIC_DISC = registerItem("bar_brawl_music_disc",
new MusicDiscItem(7, ModSounds.BAR_BRAWL, new FabricItemSettings().maxCount(1), 122));

添加到物品组:

entries.add(ModItems.BAR_BRAWL_MUSIC_DISC);

数据生成:

ModItemTagProvider中:

getOrCreateTagBuilder(ItemTags.MUSIC_DISCS)
.add(ModItems.BAR_BRAWL_MUSIC_DISC);

getOrCreateTagBuilder(ItemTags.CREEPER_DROP_MUSIC_DISCS)
.add(ModItems.BAR_BRAWL_MUSIC_DISC);

ModModelProvider中:

itemModelGenerator.register(ModItems.CORN, Models.GENERATED);
itemModelGenerator.register(ModItems.BAR_BRAWL_MUSIC_DISC, Models.GENERATED);

添加音乐文件:

sounds.json中:

"bar_brawl": {
"sounds": [
{
"name": "tutorialmod:bar_brawl",
"stream": true
}
]
}

此外还需要将音乐文件ogg格式,以及唱片的图片等内容放入正确的位置

##效果

image-20240825104804790