2012-11-05 20:29:04 +01:00
|
|
|
package mekanism.client;
|
2012-10-22 03:29:26 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.URL;
|
|
|
|
|
2012-12-09 06:24:27 +01:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
|
|
|
|
2012-11-07 21:01:46 +01:00
|
|
|
import mekanism.common.Mekanism;
|
2012-10-22 03:29:26 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.src.Block;
|
|
|
|
import net.minecraft.src.EntityPlayer;
|
|
|
|
import net.minecraft.src.ModLoader;
|
|
|
|
import net.minecraft.src.World;
|
|
|
|
|
|
|
|
import paulscode.sound.SoundSystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sound -- an object that is created in SoundHandler. A 'Sound' object runs off of
|
|
|
|
* PaulsCode's SoundSystem. It has several methods; play(), for looping the clip,
|
|
|
|
* stop(), for stopping the loop, remove(), for removing the sound from PaulsCode,
|
|
|
|
* and updateVolume() for updating the volume based on where the player is.
|
|
|
|
* @author AidanBrady
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class Sound
|
|
|
|
{
|
|
|
|
/** The PaulsCode SoundSystem */
|
|
|
|
public SoundSystem soundSystem;
|
|
|
|
|
|
|
|
/** The bundled path where the sound is */
|
|
|
|
public String soundPath;
|
|
|
|
/** A unique identifier for this sound */
|
|
|
|
public String identifier;
|
|
|
|
|
|
|
|
/** X coordinate of this sound effect */
|
|
|
|
public int xCoord;
|
|
|
|
/** Y coordinate of this sound effect */
|
|
|
|
public int yCoord;
|
|
|
|
/** Z coordinate of this sound effect */
|
|
|
|
public int zCoord;
|
|
|
|
|
|
|
|
/** The world in which this sound is playing */
|
|
|
|
public World worldObj;
|
|
|
|
|
|
|
|
/** Whether or not this sound is playing */
|
|
|
|
public boolean isPlaying = false;
|
|
|
|
|
|
|
|
/** A sound, an object that runs off of the PaulsCode sound system.
|
|
|
|
*
|
|
|
|
* @param system - PaulsCode SoundSystem
|
|
|
|
* @param id - unique identifier
|
|
|
|
* @param sound - bundled path to the sound
|
|
|
|
* @param world - world the sound is playing
|
|
|
|
* @param x - x coord
|
|
|
|
* @param y - y coord
|
|
|
|
* @param z - z coord
|
|
|
|
*/
|
|
|
|
public Sound(SoundSystem system, String id, String sound, World world, int x, int y, int z)
|
|
|
|
{
|
|
|
|
soundSystem = system;
|
|
|
|
soundPath = sound;
|
|
|
|
identifier = id;
|
|
|
|
worldObj = world;
|
|
|
|
xCoord = x;
|
|
|
|
yCoord = y;
|
|
|
|
zCoord = z;
|
|
|
|
|
2012-11-07 21:01:46 +01:00
|
|
|
URL url = getClass().getClassLoader().getResource("resources/mekanism/sound/" + sound);
|
2012-10-22 03:29:26 +02:00
|
|
|
if(url == null)
|
|
|
|
{
|
2012-11-05 20:29:04 +01:00
|
|
|
System.out.println("[Mekanism] Invalid sound file: " + sound);
|
2012-10-22 03:29:26 +02:00
|
|
|
}
|
|
|
|
|
2012-11-07 21:01:46 +01:00
|
|
|
Mekanism.audioHandler.sounds.add(this);
|
2012-10-22 03:29:26 +02:00
|
|
|
soundSystem.newSource(false, id, url, sound, true, x, y, z, 0, 16F);
|
|
|
|
soundSystem.activate(id);
|
|
|
|
}
|
|
|
|
|
2012-12-09 06:24:27 +01:00
|
|
|
/**
|
|
|
|
* Start looping the sound effect
|
|
|
|
*/
|
2012-10-22 03:29:26 +02:00
|
|
|
public void play()
|
|
|
|
{
|
|
|
|
if(isPlaying)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
soundSystem.play(identifier);
|
|
|
|
isPlaying = true;
|
|
|
|
}
|
|
|
|
|
2012-12-09 06:24:27 +01:00
|
|
|
/**
|
|
|
|
* Stop looping the sound effect
|
|
|
|
*/
|
2012-10-22 03:29:26 +02:00
|
|
|
public void stop()
|
|
|
|
{
|
|
|
|
if(!isPlaying)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
soundSystem.stop(identifier);
|
|
|
|
isPlaying = false;
|
|
|
|
}
|
|
|
|
|
2012-12-09 06:24:27 +01:00
|
|
|
/**
|
|
|
|
* Remove the sound effect from the PaulsCode SoundSystem
|
|
|
|
*/
|
2012-10-22 03:29:26 +02:00
|
|
|
public void remove()
|
|
|
|
{
|
|
|
|
if(isPlaying)
|
|
|
|
{
|
|
|
|
stop();
|
|
|
|
}
|
2012-11-07 21:01:46 +01:00
|
|
|
|
|
|
|
Mekanism.audioHandler.sounds.remove(this);
|
2012-10-22 03:29:26 +02:00
|
|
|
soundSystem.removeSource(identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Updates the volume based on how far away the player is from the machine
|
|
|
|
*
|
|
|
|
* @param entityplayer - player who is near the machine, usually Minecraft.thePlayer
|
|
|
|
*/
|
|
|
|
public void updateVolume(EntityPlayer entityplayer)
|
|
|
|
{
|
|
|
|
float volume = 0;
|
|
|
|
if (!isPlaying)
|
|
|
|
{
|
|
|
|
volume = 0.0F;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
double distanceVolume = entityplayer.getDistanceSq(xCoord, yCoord, zCoord)*0.01;
|
2012-12-09 06:24:27 +01:00
|
|
|
volume = (float)Math.max(Mekanism.audioHandler.masterVolume-distanceVolume, 0);
|
2012-10-22 03:29:26 +02:00
|
|
|
|
|
|
|
soundSystem.setVolume(identifier, volume);
|
|
|
|
}
|
|
|
|
}
|