Started work on flamethrower sounds, also increased efficiency of SoundHandler (now loops over sounds only once instead of twice)

This commit is contained in:
Aidan C. Brady committed 2014-07-15 01:09:38 -04:00
1 parent f9fdb56e24
commit cdeb25803c
5 files changed
+102 -20

No files matched your search

@@ -0,0 +1,64 @@
package mekanism.client.sound;
import mekanism.client.ClientTickHandler;
import mekanism.common.item.ItemFlamethrower;
import mekanism.common.item.ItemJetpack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public class FlamethrowerSound extends PlayerSound
{
public byte type = 0;
public FlamethrowerSound(String id, EntityPlayer entity)
{
super(id, "Jetpack.ogg", entity);
}
@Override
public boolean update(World world)
{
if(!super.update(world))
{
return false;
}
else if(!hasFlamethrower(player))
{
return false;
}
else {
if(ClientTickHandler.isJetpackOn(player) != isPlaying)
{
if(ClientTickHandler.isJetpackOn(player))
{
play();
}
else {
stopLoop();
}
}
}
if(isPlaying)
{
ticksSincePlay++;
}
return true;
}
private boolean hasFlamethrower(EntityPlayer player)
{
if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemJetpack)
{
ItemFlamethrower flamethrower = (ItemFlamethrower)player.getCurrentEquippedItem().getItem();
if(flamethrower.getGas(player.getCurrentEquippedItem()) != null)
{
return true;
}
}
return false;
}
}
@@ -25,7 +25,11 @@ public abstract class PlayerSound extends Sound
@Override
public boolean update(World world)
{
if(player.isDead)
if(!super.update(world))
{
return false;
}
else if(player.isDead)
{
return false;
}
+16 -3
View File
@@ -11,7 +11,7 @@ import net.minecraft.world.World;
public abstract class Sound
{
/** The bundled path where the sound is */
public String soundPath;
public String prevSoundPath;
/** A unique identifier for this sound */
public String identifier;
@@ -40,7 +40,7 @@ public abstract class Sound
synchronized(MekanismClient.audioHandler.sounds)
{
soundPath = sound;
prevSoundPath = sound;
identifier = id;
objRef = obj;
@@ -129,8 +129,21 @@ public abstract class Sound
}
}
}
public String getSoundPath()
{
return prevSoundPath;
}
public abstract boolean update(World world);
public boolean update(World world)
{
if(!getSoundPath().equals(prevSoundPath))
{
return false;
}
return true;
}
public abstract Pos3D getLocation();
@@ -181,29 +181,26 @@ public class SoundHandler
{
ArrayList<Sound> soundsToRemove = new ArrayList<Sound>();
World world = FMLClientHandler.instance().getClient().theWorld;
for(Sound sound : sounds.values())
if(FMLClientHandler.instance().getClient().thePlayer != null && world != null)
{
if(FMLClientHandler.instance().getClient().thePlayer != null && world != null)
for(Sound sound : sounds.values())
{
if(!sound.update(world))
{
soundsToRemove.add(sound);
continue;
}
if(sound.isPlaying)
{
sound.updateVolume();
}
}
}
for(Sound sound : soundsToRemove)
{
sound.remove();
}
for(Sound sound : sounds.values())
{
if(sound.isPlaying)
for(Sound sound : soundsToRemove)
{
sound.updateVolume();
sound.remove();
}
}
}
@@ -50,7 +50,11 @@ public class TileSound extends Sound
@Override
public boolean update(World world)
{
if(!(tileEntity instanceof IHasSound))
if(!super.update(world))
{
return false;
}
else if(!(tileEntity instanceof IHasSound))
{
return false;
}
@@ -58,7 +62,7 @@ public class TileSound extends Sound
{
return false;
}
else if(!HolidayManager.filterSound(((IHasSound)tileEntity).getSoundPath()).equals(soundPath))
else if(!HolidayManager.filterSound(((IHasSound)tileEntity).getSoundPath()).equals(prevSoundPath))
{
return false;
}