All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yungnickyoung.minecraft.yungsapi.module.SoundEventModuleForge Maven / Gradle / Ivy

There is a newer version: 1.21.1-NeoForge-5.1.2
Show newest version
package com.yungnickyoung.minecraft.yungsapi.module;

import com.yungnickyoung.minecraft.yungsapi.api.autoregister.AutoRegisterSoundEvent;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegisterField;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegistrationManager;
import net.minecraft.core.registries.Registries;
import net.minecraft.sounds.SoundEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.RegisterEvent;

/**
 * Registration of Sound Events.
 */
public class SoundEventModuleForge {
    public static void processEntries() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(SoundEventModuleForge::registerSoundEvents);
    }

    private static void registerSoundEvents(RegisterEvent event) {
        event.register(Registries.SOUND_EVENT, helper -> AutoRegistrationManager.SOUND_EVENTS.stream()
                .filter(data -> !data.processed())
                .forEach(data -> registerSoundEvent(data, helper)));
    }

    private static void registerSoundEvent(AutoRegisterField data, RegisterEvent.RegisterHelper helper) {
        AutoRegisterSoundEvent autoRegisterSoundEvent = (AutoRegisterSoundEvent) data.object();
        SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(data.name());
        helper.register(data.name(), soundEvent);
        autoRegisterSoundEvent.setSupplier(() -> soundEvent);
        data.markProcessed();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy