少女祈祷中...

关于声音事件的注册,首先需要根据这个网站在resource文件夹下写sounds.json。https://forge-doc-119x-zh-cn.readthedocs.io/zh-cn/latest/gameeffects/sounds/
不能使用DeferredRegister注册声音事件,要用SoundEvent.createVariableRangeEvent方法注册

1
2
3
4
5
private static SoundEvent makeSoundEvent(String name) {
SoundEvent event = SoundEvent.createVariableRangeEvent(prefix(name));
EVENTS.add(event);
return event;
}

使用这个方法进行注册音乐事件的注册

1
2
public static final List<SoundEvent> EVENTS = new ArrayList<>();
public static final SoundEvent th08_10_love_color = makeSoundEvent("th08_10_love_color");

然后遍历整个列表注册

1
2
3
4
5
public static void init(BiConsumer<SoundEvent, ResourceLocation> r) {
for (SoundEvent event : EVENTS) {
r.accept(event, event.getLocation());
}
}

最后把这个注册放进主线中

1
2
3
4
5
6
bind(eventBus,Registries.SOUND_EVENT,SoundRegistry::init);


private static <T> void bind(IEventBus eventBus, ResourceKey<Registry<T>> registry, Consumer<BiConsumer<T, ResourceLocation>> source) {
eventBus.addListener((RegisterEvent event) -> source.accept((t, rl) -> event.register(registry, rl, () -> t)));
}

https://github.com/Crystal1921/LivelyDanmaku/blob/main/src/main/java/com/tutorial/lively_danmaku/init/SoundRegistry.java