2014-08-28 00:16:59 +02:00
|
|
|
package mekanism.common.tile;
|
|
|
|
|
2014-08-30 03:37:02 +02:00
|
|
|
import mekanism.api.MekanismConfig.client;
|
2014-08-28 00:16:59 +02:00
|
|
|
import mekanism.api.Pos3D;
|
|
|
|
import mekanism.client.sound.IHasSound;
|
2014-08-29 06:15:00 +02:00
|
|
|
import mekanism.client.sound.IResettableSound;
|
2014-08-28 00:16:59 +02:00
|
|
|
import mekanism.client.sound.ISoundSource;
|
2014-08-29 06:15:00 +02:00
|
|
|
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;
|
2014-08-29 06:15:00 +02:00
|
|
|
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 */
|
2014-08-29 06:15:00 +02:00
|
|
|
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()
|
|
|
|
{
|
2014-08-29 06:15:00 +02:00
|
|
|
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();
|
2014-08-29 06:15:00 +02:00
|
|
|
sound = new TileSound(this, this);
|
2014-08-28 00:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
2014-08-30 03:37:02 +02:00
|
|
|
if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(sound) && client.enableMachineSounds)
|
2014-08-28 00:16:59 +02:00
|
|
|
{
|
|
|
|
sound.reset();
|
2014-08-29 06:15:00 +02:00
|
|
|
SoundHandler.playSound(sound);
|
2014-08-28 00:16:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|