Mekanism-tilera-Edition/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java

115 lines
2.4 KiB
Java
Raw Normal View History

2014-08-28 00:16:59 +02:00
package mekanism.common.tile;
import mekanism.api.MekanismConfig.client;
2014-08-28 00:16:59 +02:00
import mekanism.api.Pos3D;
import mekanism.client.sound.IHasSound;
import mekanism.client.sound.IResettableSound;
2014-08-28 00:16:59 +02:00
import mekanism.client.sound.ISoundSource;
import mekanism.client.sound.SoundHandler;
import mekanism.client.sound.TileSound;
import mekanism.common.Upgrade;
2014-08-28 00:16:59 +02:00
import mekanism.common.base.IActiveState;
import mekanism.common.base.IUpgradeTile;
2014-08-28 00:16:59 +02:00
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ISound.AttenuationType;
import net.minecraft.util.ResourceLocation;
public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlock implements IHasSound, ISoundSource, IActiveState
{
/** The ResourceLocation of the machine's sound */
public ResourceLocation soundURL;
/** The bundled URL of this machine's sound effect */
public IResettableSound sound;
2014-08-28 00:16:59 +02:00
/**
* The base of all blocks that deal with electricity and make noise.
*
* @param name - full name of this block
* @param maxEnergy - how much energy this block can store
*/
public TileEntityNoisyElectricBlock(String soundPath, String name, double maxEnergy)
{
super(name, maxEnergy);
soundURL = new ResourceLocation("mekanism", "tile." + soundPath);
}
@Override
public ISound getSound()
{
return sound;
}
@Override
public boolean shouldPlaySound()
{
return getActive() && !isInvalid();
}
@Override
public ResourceLocation getSoundLocation()
{
return soundURL;
}
@Override
public float getVolume()
{
return 1F;
}
@Override
public float getPitch()
{
if(this instanceof IUpgradeTile)
{
float speedUpgrades = ((IUpgradeTile)this).getComponent().getUpgrades(Upgrade.SPEED);
return 1F + 20 * speedUpgrades / (float)Upgrade.SPEED.getMax();
}
2014-08-28 00:16:59 +02:00
return 1F;
}
@Override
public Pos3D getSoundPosition()
{
return new Pos3D(xCoord+0.5, yCoord+0.5, zCoord+0.5);
}
@Override
public boolean shouldRepeat()
{
return true;
}
@Override
public int getRepeatDelay()
{
return 0;
}
@Override
public AttenuationType getAttenuation()
{
return AttenuationType.LINEAR;
}
@Override
public void validate()
{
super.validate();
sound = new TileSound(this, this);
2014-08-28 00:16:59 +02:00
}
@Override
public void onUpdate()
{
if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(sound) && client.enableMachineSounds)
2014-08-28 00:16:59 +02:00
{
sound.reset();
SoundHandler.playSound(sound);
2014-08-28 00:16:59 +02:00
}
}
}