Cleanup. Great work on the sound system overhaul, @unpairedbracket! It's perfect!

This commit is contained in:
Aidan C. Brady 2014-08-31 02:01:11 -04:00
parent ee379d7108
commit 9224d1278a
9 changed files with 170 additions and 132 deletions

View file

@ -15,10 +15,12 @@ public class FlamethrowerSound extends PlayerSound
public FlamethrowerSound(EntityPlayer player)
{
super(player, new ResourceLocation("mekanism", "item.flamethrower.idle"));
onSound = new ResourceLocation("mekanism", "item.flamethrower.active");
offSound = new ResourceLocation("mekanism", "item.flamethrower.idle");
inUse = ClientTickHandler.isFlamethrowerOn(player);
sound = inUse ? onSound : offSound;
setFadeIn(0);
setFadeOut(0);
}
@ -47,9 +49,9 @@ public class FlamethrowerSound extends PlayerSound
if(!ClientTickHandler.hasFlamethrower(player))
{
donePlaying = true;
return;
}
if(inUse != ClientTickHandler.isFlamethrowerOn(player))
{
inUse = ClientTickHandler.isFlamethrowerOn(player);

View file

@ -11,6 +11,7 @@ public class GasMaskSound extends PlayerSound
public GasMaskSound(EntityPlayer player)
{
super(player, new ResourceLocation("mekanism", "item.gasMask"));
setFadeIn(30);
setFadeOut(10);
}

View file

@ -11,6 +11,7 @@ public class JetpackSound extends PlayerSound
public JetpackSound(EntityPlayer player)
{
super(player, new ResourceLocation("mekanism", "item.jetpack"));
setFadeIn(30);
setFadeOut(10);
}

View file

@ -8,81 +8,84 @@ public abstract class PlayerSound extends Sound implements IResettableSound
public EntityPlayer player;
boolean beginFadeOut;
boolean donePlaying = true;
int ticks = 0;
int fadeIn;
int fadeOut;
float baseVolume = 0.3F;
public PlayerSound(EntityPlayer player, ResourceLocation location)
public PlayerSound(EntityPlayer p, ResourceLocation location)
{
super(location, 0.3F, 1, true, 0, (float) player.posX, (float) player.posY, (float) player.posZ, AttenuationType.LINEAR);
this.player = player;
super(location, 0.3F, 1, true, 0, (float)p.posX, (float)p.posY, (float)p.posZ, AttenuationType.LINEAR);
player = p;
}
@Override
public float getXPosF()
{
return (float) player.posX;
}
@Override
public float getYPosF()
{
return (float) player.posY;
}
@Override
public float getZPosF()
{
return (float) player.posZ;
}
public PlayerSound setFadeIn(int fadeIn) {
this.fadeIn = Math.min(0, fadeIn);
public PlayerSound setFadeIn(int fade)
{
fadeIn = Math.min(0, fade);
return this;
}
public PlayerSound setFadeOut(int fadeOut) {
public PlayerSound setFadeOut(int fade)
{
this.fadeOut = Math.min(0, fadeOut);
fadeOut = Math.min(0, fade);
return this;
}
public float getFadeInMultiplier() {
return ticks >= fadeIn ? 1 : (ticks / (float) fadeIn);
public float getFadeInMultiplier()
{
return ticks >= fadeIn ? 1 : (ticks / (float)fadeIn);
}
public float getFadeOutMultiplier() {
return ticks >= fadeOut ? 0 : ((fadeOut - ticks) / (float) fadeOut);
public float getFadeOutMultiplier()
{
return ticks >= fadeOut ? 0 : ((fadeOut - ticks) / (float)fadeOut);
}
@Override
public void update()
{
if(!beginFadeOut)
{
if(ticks < fadeIn)
{
ticks++;
}
if(!shouldPlaySound())
{
beginFadeOut = true;
ticks = 0;
}
} else
{
}
else {
ticks++;
}
float multiplier = beginFadeOut ? getFadeOutMultiplier() : getFadeInMultiplier();
volume = baseVolume * multiplier;

View file

@ -22,159 +22,165 @@ import net.minecraft.util.ResourceLocation;
public class Sound implements ISound {
protected AttenuationType attenuation;
protected ResourceLocation sound;
protected float volume;
protected float pitch;
protected float x;
protected float y;
protected float z;
protected boolean repeat;
protected int repeatDelay;
public Sound(String sound) {
public Sound(String sound)
{
this(sound, 0);
}
public Sound(String sound, float volume) {
public Sound(String sound, float volume)
{
this(sound, volume, 0);
}
public Sound(String sound, float volume, float pitch) {
public Sound(String sound, float volume, float pitch)
{
this(sound, volume, pitch, false, 0);
}
public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay) {
public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay)
{
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
}
public Sound(String sound, float volume, float pitch, double x, double y, double z) {
public Sound(String sound, float volume, float pitch, double x, double y, double z)
{
this(sound, volume, pitch, false, 0, x, y, z);
}
public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
{
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation) {
public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
{
this(new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
}
public Sound(ResourceLocation sound) {
public Sound(ResourceLocation sound)
{
this(sound, 0);
}
public Sound(ResourceLocation sound, float volume) {
public Sound(ResourceLocation sound, float volume)
{
this(sound, volume, 0);
}
public Sound(ResourceLocation sound, float volume, float pitch) {
public Sound(ResourceLocation sound, float volume, float pitch)
{
this(sound, volume, pitch, false, 0);
}
public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay) {
public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay)
{
this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE);
}
public Sound(ResourceLocation sound, float volume, float pitch, double x, double y, double z) {
public Sound(ResourceLocation sound, float volume, float pitch, double x, double y, double z)
{
this(sound, volume, pitch, false, 0, x, y, z);
}
public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
{
this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public Sound(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
AttenuationType attenuation) {
this.attenuation = attenuation;
this.sound = sound;
this.volume = volume;
this.pitch = pitch;
this.x = (float) x;
this.y = (float) y;
this.z = (float) z;
this.repeat = repeat;
this.repeatDelay = repeatDelay;
public Sound(ResourceLocation resource, float v, float p, boolean rep, int delay, double xPos, double yPos, double zPos, AttenuationType att)
{
attenuation = att;
sound = resource;
volume = v;
pitch = p;
x = (float)xPos;
y = (float)yPos;
z = (float)zPos;
repeat = rep;
repeatDelay = delay;
}
public Sound(Sound other) {
this.attenuation = other.attenuation;
this.sound = other.sound;
this.volume = other.volume;
this.pitch = other.pitch;
this.x = other.x;
this.y = other.y;
this.z = other.z;
this.repeat = other.repeat;
this.repeatDelay = other.repeatDelay;
public Sound(Sound other)
{
attenuation = other.attenuation;
sound = other.sound;
volume = other.volume;
pitch = other.pitch;
x = other.x;
y = other.y;
z = other.z;
repeat = other.repeat;
repeatDelay = other.repeatDelay;
}
@Override
public AttenuationType getAttenuationType() {
public AttenuationType getAttenuationType()
{
return attenuation;
}
@Override
public ResourceLocation getPositionedSoundLocation() {
public ResourceLocation getPositionedSoundLocation()
{
return sound;
}
@Override
public float getVolume() {
public float getVolume()
{
return volume * client.baseSoundVolume;
}
@Override
public float getPitch() {
public float getPitch()
{
return pitch;
}
@Override
public float getXPosF() {
public float getXPosF()
{
return x;
}
@Override
public float getYPosF() {
public float getYPosF()
{
return y;
}
@Override
public float getZPosF() {
public float getZPosF()
{
return z;
}
@Override
public boolean canRepeat() {
public boolean canRepeat()
{
return repeat;
}
@Override
public int getRepeatDelay() {
public int getRepeatDelay()
{
return repeatDelay;
}
}

View file

@ -53,12 +53,9 @@ public class SoundHandler
public PlayerSound getNewSound(EntityPlayer player)
{
try
{
try {
return soundClass.getDeclaredConstructor(EntityPlayer.class).newInstance(player);
}
catch(Exception e)
{
} catch(Exception e) {
return null;
}
}
@ -78,6 +75,7 @@ public class SoundHandler
String name = player.getCommandSenderName();
Map<String, IResettableSound> map = getMap(name);
IResettableSound sound = map.get(channel.getName());
if(sound == null || replace)
{
PlayerSound newSound = channel.getNewSound(player);
@ -90,6 +88,7 @@ public class SoundHandler
String name = player.getCommandSenderName();
Map<String, IResettableSound> map = getMap(name);
IResettableSound sound = map.get(channel.getName());
if(sound != null)
{
if(canRestartSound(sound))
@ -97,14 +96,17 @@ public class SoundHandler
sound.reset();
playSound(sound);
}
return true;
}
return false;
}
public static Map<String, IResettableSound> getMap(String name)
{
Map<String, IResettableSound> map = soundMaps.get(name);
if(map == null)
{
map = new HashMap<String, IResettableSound>();
@ -127,13 +129,13 @@ public class SoundHandler
public static Map<ISound, String> getSoundMap()
{
if(invPlayingSounds == null)
try
{
{
try {
invPlayingSounds = (Map<ISound, String>)MekanismUtils.getPrivateValue(getSoundManager(), net.minecraft.client.audio.SoundManager.class, ObfuscatedNames.SoundManager_invPlayingSounds);
} catch(Exception e)
{
} catch(Exception e) {
invPlayingSounds = null;
}
}
return invPlayingSounds;
}

View file

@ -5,11 +5,17 @@ import net.minecraft.util.ResourceLocation;
public class TileSound extends Sound implements IResettableSound {
IHasSound source;
boolean beginFadeOut;
boolean donePlaying = true;
int ticks = 0;
int fadeIn = 30;
int fadeOut = 10;
float baseVolume = 1.0F;
public TileSound(IHasSound source, ISoundSource values)
@ -17,71 +23,77 @@ public class TileSound extends Sound implements IResettableSound {
this(source, values.getSoundLocation(), values.getVolume(), values.getPitch(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().xPos, values.getSoundPosition().yPos, values.getSoundPosition().zPos);
}
public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
{
this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
AttenuationType attenuation) {
public TileSound(IHasSound source, String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
{
this(source, new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
}
public TileSound(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) {
public TileSound(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z)
{
this(source, sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR);
}
public TileSound(IHasSound source, ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z,
AttenuationType attenuation) {
super(sound, volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
this.source = source;
this.baseVolume = volume;
public TileSound(IHasSound source, ResourceLocation resource, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation)
{
super(resource, volume, pitch, repeat, repeatDelay, x, y, z, attenuation);
sound = resource;
baseVolume = volume;
}
public TileSound setFadeIn(int fadeIn) {
this.fadeIn = Math.min(0, fadeIn);
public TileSound setFadeIn(int fade)
{
fadeIn = Math.min(0, fade);
return this;
}
public TileSound setFadeOut(int fadeOut) {
this.fadeOut = Math.min(0, fadeOut);
public TileSound setFadeOut(int fade)
{
fadeOut = Math.min(0, fade);
return this;
}
public float getFadeInMultiplier() {
return ticks >= fadeIn ? 1 : (float) (ticks / (float) fadeIn);
public float getFadeInMultiplier()
{
return ticks >= fadeIn ? 1 : (float)(ticks / (float)fadeIn);
}
public float getFadeOutMultiplier() {
return ticks >= fadeOut ? 0 : (float) ((fadeOut - ticks) / (float) fadeOut);
public float getFadeOutMultiplier()
{
return ticks >= fadeOut ? 0 : (float)((fadeOut - ticks) / (float)fadeOut);
}
/* ITickableSound */
@Override
public void update() {
if (!beginFadeOut) {
if (ticks < fadeIn) {
public void update()
{
if(!beginFadeOut)
{
if(ticks < fadeIn)
{
ticks++;
}
if (!source.shouldPlaySound()) {
if(!source.shouldPlaySound())
{
beginFadeOut = true;
ticks = 0;
}
} else {
}
else {
ticks++;
}
float multiplier = beginFadeOut ? getFadeOutMultiplier() : getFadeInMultiplier();
volume = baseVolume * multiplier;
if (multiplier <= 0) {
if(multiplier <= 0)
{
donePlaying = true;
}
}

View file

@ -68,6 +68,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
float speedUpgrades = ((IUpgradeTile)this).getComponent().getUpgrades(Upgrade.SPEED);
return 1F + 20 * speedUpgrades / (float)Upgrade.SPEED.getMax();
}
return 1F;
}
@ -99,12 +100,15 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo
public void validate()
{
super.validate();
sound = new TileSound(this, this);
}
@Override
public void onUpdate()
{
super.onUpdate();
if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(sound) && client.enableMachineSounds)
{
sound.reset();

View file

@ -584,6 +584,13 @@ tooltip.BioGenerator=A generator that burns organic materials of !nthe world to
tooltip.AdvancedSolarGenerator=An advanced generator that directly !nabsorbs the sun's rays with little loss !nto produce energy.
tooltip.WindTurbine=A generator that uses the strength of the wind !nto produce energy, with greater efficiency !nat higher levels.
tooltip.ReactorGlass=
tooltip.ReactorLaserFocusMatrix=
tooltip.ReactorController=
tooltip.ReactorFrame=
tooltip.ReactorNeutronCapturePlate=
tooltip.ReactorPort=
tooltip.OsmiumOre=A strong mineral that can be found !nat nearly any height in the world. !nIt is known to have many uses in !nthe construction of machinery.
tooltip.CopperOre=A common, conductive material that !ncan be used in the production of !nwires. Its ability to withstand !nhigh heats also makes it essential !nto advanced machinery.
tooltip.TinOre=A lightweight, yet sturdy, conductive !nmaterial that is found slightly less !ncommonly than Copper.
@ -669,11 +676,11 @@ tile.Generator.WindTurbine.name=Wind Turbine
tile.Reactor.ReactorController.name=Reactor Controller
tile.Reactor.ReactorFrame.name=Reactor Frame
tile.Reactor.ReactorLaserFocusMatrix.name=Laser Focus Matrix
tile.Reactor.ReactorNeutronCapturePlate.name=Neutron Capture Plate
tile.Reactor.ReactorInOutPort.name=Reactor Port
tile.ReactorGlass.ReactorGlass.name=Reactor Glass
tile.ReactorGlass.ReactorLaserFocusMatrix.name=Laser Focus Matrix
//Gui text
gui.heatGenerator.fuel=Fuel