Sound registry.


Creating a registry. 0.3>



In order to register sounds you will have to create a registry. To do this, you must use the following code within the init() function:

                    
//This is the init() inside your main class.
public static void init() {
    //Here we create the registry so we can use it later.
    SoundRegistry.CreateRegistry(MOD_ID);
}
                    
                

Register a sound. 0.3>



To register a sound, you'll need to have the necessary files already in place, such as the .ogg file and sounds.json.


I recommend that you separate the code into another class to better organize yourself.

                    
//This is another separate class from the initial one. I recommend you do this for organization.
public class SoundsRegister {
    //Here we create the sound.
    public static final RestSound sound = SoundRegistry.RegisterSound(MOD_ID, "SOUND_ID");

    /*
        Parameters:
            - MOD_ID = Your mod id as string.
            - "SOUND_ID"= Your sound's id as string.
    */

    //You can create a method/function like this to call it from the main class.
    public static void register() {
        //This registers all of your sounds into minecraft.
        SoundRegistry.Register(Testing.MOD_ID);
    }
}
                    
                
                    
//This is another separate class from the initial one. I recommend you do this for organization.
public class SoundsRegister {
    //Here we create the sound.
    public static final Object sound = SoundRegistry.RegisterSound(MOD_ID, "SOUND_ID");

    /*
        Parameters:
            - MOD_ID = Your mod id as string.
            - "SOUND_ID"= Your sound's id as string.
    */

    //You can create a method/function like this to call it from the main class.
    public static void register() {
        //This registers all of your sounds into minecraft.
        SoundRegistry.Register(Testing.MOD_ID);
    }
}
                    
                

Play any sound. 0.3>



With our API, you can play any sound more easily. You just need the following line of code:
                    
SoundRegistry.PlaySound(player, YOUR_SOUND, SoundSource.PLAYERS, 1, 1);

/*
    Parameters:
        - player = The player that produces the sound, it can be null.
        - YOUR_SOUND = Your sound.
        - SoundSource.PLAYERS = Where to play your sound.
        - 1 = The volume. 0 to 1.
        - 1 = The Pitch. -1 to 1. 0 = normal.
*/
                    
                

Create a SoundType. 0.4>



A SoundType is used to group the sounds of a (LINK.block). With this function, you can group your custom sounds to use them in your (LINK.custom blocks).
                    
public static final SoundType customSounds = SoundRegistry.CreateCustomSoundType(Volume, Pitch, BreakSound, StepSound, PlaceSound, HitSound, FallSound);

/*
    Parameters:
        - Volume = The volume. 0 : 1. Float.
        - Pitch = The pitch. -1 : 1. Float.
        - BreakSound = The sound when it breaks.
        - StepSound = The sound when you walk on it.
        - PlaceSound = The sound when you place it.
        - HitSound = The sound when you start breaking it.
        - FallSound = The sound when you fall on it.
*/
                    
                
                    
public static final Object customSounds = SoundRegistry.CreateCustomSoundType(Volume, Pitch, BreakSound, StepSound, PlaceSound, HitSound, FallSound);

/*
    Parameters:
        - Volume = The volume. 0 : 1. Float.
        - Pitch = The pitch. -1 : 1. Float.
        - BreakSound = The sound when it breaks.
        - StepSound = The sound when you walk on it.
        - PlaceSound = The sound when you place it.
        - HitSound = The sound when you start breaking it.
        - FallSound = The sound when you fall on it.
*/