This commit is contained in:
Aidan C. Brady 2014-07-16 19:16:38 -04:00
parent 4309a7d7b1
commit 8ccf4e6653
8 changed files with 41 additions and 27 deletions

View file

@ -11,7 +11,7 @@ public class FlamethrowerSound extends PlayerSound
public FlamethrowerSound(String id, EntityPlayer entity)
{
super(id, getSound(getInUse(entity)), entity);
super(id, getSound(getInUse(entity)), SoundHandler.CHANNEL_FLAMETHROWER, entity);
inUse = getInUse(entity);
}
@ -31,13 +31,14 @@ public class FlamethrowerSound extends PlayerSound
{
return false;
}
if(isPlaying)
if(!isPlaying)
{
System.out.println(getLocation());
ticksSincePlay++;
play();
}
ticksSincePlay++;
return true;
}

View file

@ -9,7 +9,7 @@ public class GasMaskSound extends PlayerSound
{
public GasMaskSound(String id, EntityPlayer entity)
{
super(id, "GasMask.ogg", entity);
super(id, "GasMask.ogg", SoundHandler.CHANNEL_GASMASK, entity);
}
@Override

View file

@ -9,7 +9,7 @@ public class JetpackSound extends PlayerSound
{
public JetpackSound(String id, EntityPlayer entity)
{
super(id, "Jetpack.ogg", entity);
super(id, "Jetpack.ogg", SoundHandler.CHANNEL_JETPACK, entity);
}
@Override

View file

@ -9,9 +9,9 @@ public abstract class PlayerSound extends Sound
/** The TileEntity this sound is associated with. */
public EntityPlayer player;
public PlayerSound(String id, String sound, EntityPlayer entity)
public PlayerSound(String id, String sound, String chan, EntityPlayer entity)
{
super(id, sound, entity, new Pos3D(entity));
super(id, sound, chan, entity, new Pos3D(entity));
player = entity;
}

View file

@ -22,6 +22,8 @@ public abstract class Sound
public int ticksSincePlay = 0;
private Object objRef;
public String channel;
protected Minecraft mc = Minecraft.getMinecraft();
@ -31,9 +33,9 @@ public abstract class Sound
* @param sound - bundled path to the sound
* @param tileentity - the tile this sound is playing from.
*/
public Sound(String id, String sound, Object obj, Pos3D loc)
public Sound(String id, String sound, String chan, Object obj, Pos3D loc)
{
if(MekanismClient.audioHandler.getMap(obj) != null)
if(MekanismClient.audioHandler.getSound(obj, chan) != null)
{
return;
}
@ -43,6 +45,7 @@ public abstract class Sound
prevSoundPath = sound;
identifier = id;
objRef = obj;
channel = chan;
URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + sound);
@ -58,7 +61,7 @@ public abstract class Sound
SoundHandler.getSoundSystem().activate(id);
}
MekanismClient.audioHandler.registerSound(objRef, prevSoundPath, this);
MekanismClient.audioHandler.registerSound(objRef, channel, this);
}
}
@ -109,7 +112,7 @@ public abstract class Sound
}
/**
* Remove the sound effect from the PaulsCode SoundSystem
* Remove the sound effect from the PaulsCode SoundSystem and the Mekanism SoundHandler
*/
public void remove()
{
@ -120,7 +123,7 @@ public abstract class Sound
stopLoop();
}
MekanismClient.audioHandler.removeSound(objRef, prevSoundPath);
MekanismClient.audioHandler.removeSound(objRef, channel);
if(SoundHandler.getSoundSystem() != null)
{

View file

@ -225,25 +225,30 @@ public class SoundHandler
}
}
public void removeSound(Object ref, String path)
public void removeSound(Object ref, String channel)
{
if(soundMaps.get(ref) == null)
{
return;
}
soundMaps.get(ref).remove(path);
soundMaps.get(ref).remove(channel);
if(soundMaps.get(ref).isEmpty())
{
soundMaps.remove(ref);
}
}
public void registerSound(Object ref, String path, Sound sound)
public void registerSound(Object ref, String channel, Sound sound)
{
if(soundMaps.get(ref) == null)
{
soundMaps.put(ref, new SoundMap(ref, path, sound));
soundMaps.put(ref, new SoundMap(ref, channel, sound));
return;
}
soundMaps.get(ref).add(path, sound);
soundMaps.get(ref).add(channel, sound);
}
/**
@ -251,22 +256,22 @@ public class SoundHandler
* @param tileEntity - the holder of the sound
* @return Sound instance
*/
public SoundMap getMap(Object obj)
public SoundMap getMap(Object ref)
{
synchronized(soundMaps)
{
return soundMaps.get(obj);
return soundMaps.get(ref);
}
}
public Sound getSound(Object obj, String channel)
public Sound getSound(Object ref, String channel)
{
if(soundMaps.get(obj) == null)
if(soundMaps.get(ref) == null)
{
return null;
}
return soundMaps.get(obj).getSound(channel);
return soundMaps.get(ref).getSound(channel);
}
/**
@ -285,7 +290,7 @@ public class SoundHandler
{
if(getMap(tile) == null)
{
new TileSound(getIdentifier(tile), HolidayManager.filterSound(((IHasSound)tile).getSoundPath()), tile);
new TileSound(getIdentifier(tile), CHANNEL_TILE_DEFAULT, HolidayManager.filterSound(((IHasSound)tile).getSoundPath()), tile);
}
}
}

View file

@ -71,6 +71,11 @@ public class SoundMap implements Iterable<Sound>
MekanismClient.audioHandler.soundMaps.remove(objRef);
}
public boolean isEmpty()
{
return soundMap.isEmpty();
}
public int size()
{
return soundMap.size();

View file

@ -28,9 +28,9 @@ public class TileSound extends Sound
* @param sound - bundled path to the sound
* @param tileentity - the tile this sound is playing from.
*/
public TileSound(String id, String sound, TileEntity tileentity)
public TileSound(String id, String sound, String chan, TileEntity tileentity)
{
super(id, sound, tileentity, new Pos3D(tileentity));
super(id, sound, chan, tileentity, new Pos3D(tileentity));
tileEntity = tileentity;
}