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;
|
2016-01-08 18:24:27 +01:00
|
|
|
import mekanism.client.HolidayManager;
|
2014-08-28 00:16:59 +02:00
|
|
|
import mekanism.client.sound.ISoundSource;
|
|
|
|
import mekanism.common.base.IActiveState;
|
2015-03-20 04:16:27 +01:00
|
|
|
import mekanism.common.base.IHasSound;
|
|
|
|
import mekanism.common.base.SoundWrapper;
|
2014-08-28 00:16:59 +02:00
|
|
|
import net.minecraft.client.audio.ISound.AttenuationType;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2015-03-18 18:26:12 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-08-28 00:16:59 +02:00
|
|
|
|
|
|
|
public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlock implements IHasSound, ISoundSource, IActiveState
|
|
|
|
{
|
|
|
|
/** The ResourceLocation of the machine's sound */
|
|
|
|
public ResourceLocation soundURL;
|
|
|
|
|
2015-03-18 21:24:03 +01:00
|
|
|
/** The bundled URL of this machine's sound effect */
|
2015-03-18 18:26:12 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-03-20 04:16:27 +01:00
|
|
|
public SoundWrapper sound;
|
2016-01-09 19:37:37 +01:00
|
|
|
|
|
|
|
/** The path of this machine's sound */
|
|
|
|
public String soundPath;
|
2014-08-28 00:16:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The base of all blocks that deal with electricity and make noise.
|
|
|
|
*
|
2016-01-09 19:37:37 +01:00
|
|
|
* @param sound - the sound path of this block
|
2014-08-28 00:16:59 +02:00
|
|
|
* @param name - full name of this block
|
|
|
|
* @param maxEnergy - how much energy this block can store
|
|
|
|
*/
|
2016-01-09 19:37:37 +01:00
|
|
|
public TileEntityNoisyElectricBlock(String sound, String name, double maxEnergy)
|
2014-08-28 00:16:59 +02:00
|
|
|
{
|
|
|
|
super(name, maxEnergy);
|
2016-01-08 18:24:27 +01:00
|
|
|
|
2016-01-09 19:37:37 +01:00
|
|
|
soundPath = sound;
|
2014-08-28 00:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 18:26:12 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-03-20 04:16:27 +01:00
|
|
|
public SoundWrapper getSound()
|
2014-08-28 00:16:59 +02:00
|
|
|
{
|
|
|
|
return sound;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 21:24:03 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public boolean shouldPlaySound()
|
|
|
|
{
|
|
|
|
return getActive() && !isInvalid();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 21:24:03 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public ResourceLocation getSoundLocation()
|
|
|
|
{
|
|
|
|
return soundURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 21:24:03 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public float getVolume()
|
|
|
|
{
|
|
|
|
return 1F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 21:24:03 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public float getPitch()
|
|
|
|
{
|
|
|
|
return 1F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 21:24:03 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public Pos3D getSoundPosition()
|
|
|
|
{
|
|
|
|
return new Pos3D(xCoord+0.5, yCoord+0.5, zCoord+0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 21:24:03 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public boolean shouldRepeat()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 21:24:03 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public int getRepeatDelay()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-18 18:26:12 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-08-28 00:16:59 +02:00
|
|
|
public AttenuationType getAttenuation()
|
|
|
|
{
|
|
|
|
return AttenuationType.LINEAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void validate()
|
|
|
|
{
|
|
|
|
super.validate();
|
2014-09-05 19:31:10 +02:00
|
|
|
|
2015-03-18 21:24:03 +01:00
|
|
|
if(worldObj.isRemote)
|
|
|
|
{
|
2016-01-09 16:07:22 +01:00
|
|
|
try {
|
2016-01-09 19:37:37 +01:00
|
|
|
soundURL = HolidayManager.filterSound(new ResourceLocation("mekanism", "tile." + soundPath));
|
2016-01-09 16:07:22 +01:00
|
|
|
initSounds();
|
|
|
|
} catch(Throwable t) {}
|
2015-03-18 21:24:03 +01:00
|
|
|
}
|
2014-09-05 19:31:10 +02:00
|
|
|
}
|
|
|
|
|
2015-03-18 18:26:12 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-09-05 19:31:10 +02:00
|
|
|
public void initSounds()
|
|
|
|
{
|
2015-03-20 04:16:27 +01:00
|
|
|
sound = new SoundWrapper(this, this);
|
2014-08-28 00:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
2014-08-31 08:01:11 +02:00
|
|
|
super.onUpdate();
|
|
|
|
|
2015-03-18 21:24:03 +01:00
|
|
|
if(worldObj.isRemote)
|
|
|
|
{
|
|
|
|
updateSound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void updateSound()
|
|
|
|
{
|
2015-03-20 04:16:27 +01:00
|
|
|
if(shouldPlaySound() && getSound().canRestart() && client.enableMachineSounds)
|
2015-03-18 21:24:03 +01:00
|
|
|
{
|
|
|
|
getSound().reset();
|
2015-03-20 04:16:27 +01:00
|
|
|
getSound().play();
|
2015-03-18 21:24:03 +01:00
|
|
|
}
|
2014-08-28 00:16:59 +02:00
|
|
|
}
|
|
|
|
}
|