2012-11-05 20:29:04 +01:00
|
|
|
package mekanism.client;
|
2012-10-22 03:29:26 +02:00
|
|
|
|
2012-11-07 21:01:46 +01:00
|
|
|
import java.util.ArrayList;
|
2012-12-30 22:34:45 +01:00
|
|
|
import java.util.Collections;
|
2012-11-07 21:01:46 +01:00
|
|
|
import java.util.List;
|
2012-10-22 03:29:26 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
2012-12-30 22:34:45 +01:00
|
|
|
import mekanism.common.TileEntityBasicMachine;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.world.World;
|
2012-10-22 03:29:26 +02:00
|
|
|
import paulscode.sound.SoundSystem;
|
2012-12-20 22:53:39 +01:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2012-10-22 03:29:26 +02:00
|
|
|
|
|
|
|
/**
|
2012-11-05 20:29:04 +01:00
|
|
|
* SoundHandler - a class that handles all Sounds used by Mekanism.
|
2012-10-22 03:29:26 +02:00
|
|
|
* Runs off of PaulsCode's SoundSystem.
|
|
|
|
* @author AidanBrady
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class SoundHandler
|
|
|
|
{
|
|
|
|
/** The PaulsCode SoundSystem */
|
|
|
|
public SoundSystem soundSystem;
|
|
|
|
|
2012-12-30 22:34:45 +01:00
|
|
|
public List<Sound> sounds = Collections.synchronizedList(new ArrayList<Sound>());
|
2012-11-07 21:01:46 +01:00
|
|
|
|
2012-12-09 06:24:27 +01:00
|
|
|
public float masterVolume = 0;
|
|
|
|
|
2012-11-05 20:29:04 +01:00
|
|
|
/** SoundHandler -- a class that handles all Sounds used by Mekanism. */
|
2012-10-22 03:29:26 +02:00
|
|
|
public SoundHandler()
|
|
|
|
{
|
|
|
|
if(soundSystem == null)
|
|
|
|
{
|
|
|
|
soundSystem = FMLClientHandler.instance().instance().getClient().sndManager.sndSystem;
|
2012-11-05 20:29:04 +01:00
|
|
|
System.out.println("[Mekanism] Successfully set up SoundHandler.");
|
2012-10-22 03:29:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-07 21:01:46 +01:00
|
|
|
public void onTick()
|
|
|
|
{
|
2012-12-30 22:34:45 +01:00
|
|
|
synchronized(sounds)
|
2012-11-07 21:01:46 +01:00
|
|
|
{
|
2012-12-30 22:34:45 +01:00
|
|
|
for(Sound sound : sounds)
|
|
|
|
{
|
|
|
|
if(FMLClientHandler.instance().getClient().thePlayer != null && FMLClientHandler.instance().getClient().theWorld != null)
|
|
|
|
{
|
|
|
|
sound.updateVolume(FMLClientHandler.instance().getClient().thePlayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
masterVolume = FMLClientHandler.instance().getClient().gameSettings.soundVolume;
|
2012-11-07 21:01:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-22 03:29:26 +02:00
|
|
|
/** Create and return an instance of a Sound.
|
|
|
|
*
|
|
|
|
* @param name - unique identifier for this sound
|
|
|
|
* @param path - bundled path to the sound effect
|
|
|
|
* @param world - world to play sound in
|
|
|
|
* @param x - x coord
|
|
|
|
* @param y - y coord
|
|
|
|
* @param z - z coord
|
|
|
|
* @return Sound instance
|
|
|
|
*/
|
|
|
|
public Sound getSound(String name, String path, World world, int x, int y, int z)
|
|
|
|
{
|
2012-12-30 22:34:45 +01:00
|
|
|
synchronized(sounds)
|
2012-10-31 15:49:04 +01:00
|
|
|
{
|
2012-12-31 20:33:36 +01:00
|
|
|
return new Sound(getIdentifier(), path, world, x, y, z);
|
2012-10-31 15:49:04 +01:00
|
|
|
}
|
2012-10-22 03:29:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-12-30 22:34:45 +01:00
|
|
|
* Get a unique identifier for a sound effect instance by combining the mod's name,
|
|
|
|
* Mekanism, the new sound's unique position on the 'sounds' ArrayList, and a random
|
|
|
|
* number between 0 and 10,000. Example: "Mekanism_6_6123"
|
2012-10-22 03:29:26 +02:00
|
|
|
* @return unique identifier
|
|
|
|
*/
|
2012-12-30 22:34:45 +01:00
|
|
|
public String getIdentifier()
|
2012-10-22 03:29:26 +02:00
|
|
|
{
|
2012-12-30 22:34:45 +01:00
|
|
|
synchronized(sounds)
|
|
|
|
{
|
|
|
|
return "Mekanism_" + sounds.size()+1 + "_" + new Random().nextInt(10000);
|
|
|
|
}
|
2012-10-22 03:29:26 +02:00
|
|
|
}
|
|
|
|
}
|