diff --git a/src/main/java/mekanism/client/ClientTickHandler.java b/src/main/java/mekanism/client/ClientTickHandler.java index 5f03839eb..1dbb9f8dc 100644 --- a/src/main/java/mekanism/client/ClientTickHandler.java +++ b/src/main/java/mekanism/client/ClientTickHandler.java @@ -11,7 +11,6 @@ import mekanism.api.IClientTicker; import mekanism.api.gas.GasStack; import mekanism.client.sound.FlamethrowerSound; import mekanism.client.sound.GasMaskSound; -import mekanism.client.sound.JetpackSound; import mekanism.common.KeySync; import mekanism.common.Mekanism; import mekanism.common.ObfuscatedNames; @@ -258,9 +257,9 @@ public class ClientTickHandler if(player != null) { - if(!MekanismClient.audioHandler.hasSound(player, JETPACK)) + if(!MekanismClient.audioHandler.soundPlaying(player, JETPACK)) { - MekanismClient.audioHandler.addSound(player, JETPACK, new JetpackSound(player), false); + MekanismClient.audioHandler.addSound(player, JETPACK, true); } MekanismClient.audioHandler.playSound(player, JETPACK); } @@ -272,9 +271,9 @@ public class ClientTickHandler if(player != null) { - if(!MekanismClient.audioHandler.hasSound(player, GASMASK)) + if(!MekanismClient.audioHandler.soundPlaying(player, GASMASK)) { - MekanismClient.audioHandler.addSound(player, GASMASK, new GasMaskSound(player), false); + MekanismClient.audioHandler.addSound(player, GASMASK, true); } MekanismClient.audioHandler.playSound(player, GASMASK); } @@ -284,9 +283,9 @@ public class ClientTickHandler { if(hasFlamethrower(player)) { - if(!MekanismClient.audioHandler.hasSound(player, FLAMETHROWER)) + if(!MekanismClient.audioHandler.soundPlaying(player, FLAMETHROWER)) { - MekanismClient.audioHandler.addSound(player, FLAMETHROWER, new FlamethrowerSound(player), false); + MekanismClient.audioHandler.addSound(player, FLAMETHROWER, true); } MekanismClient.audioHandler.playSound(player, FLAMETHROWER); } diff --git a/src/main/java/mekanism/client/sound/FlamethrowerSound.java b/src/main/java/mekanism/client/sound/FlamethrowerSound.java index b7d6eb2bb..5abfced4d 100644 --- a/src/main/java/mekanism/client/sound/FlamethrowerSound.java +++ b/src/main/java/mekanism/client/sound/FlamethrowerSound.java @@ -17,6 +17,8 @@ public class FlamethrowerSound extends PlayerSound 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); } diff --git a/src/main/java/mekanism/client/sound/SoundHandler.java b/src/main/java/mekanism/client/sound/SoundHandler.java index ec3f8c413..0b09105a9 100644 --- a/src/main/java/mekanism/client/sound/SoundHandler.java +++ b/src/main/java/mekanism/client/sound/SoundHandler.java @@ -33,39 +33,54 @@ public class SoundHandler public enum Channel { - JETPACK("jetpack"), - GASMASK("gasMask"), - FLAMETHROWER("flamethrower"); + JETPACK("jetpack", JetpackSound.class), + GASMASK("gasMask", GasMaskSound.class), + FLAMETHROWER("flamethrower", FlamethrowerSound.class); String channelName; + Class soundClass; - private Channel(String name) + private Channel(String name, Class clazz) { channelName = name; + soundClass = clazz; } public String getName() { return channelName; } + + public PlayerSound getNewSound(EntityPlayer player) + { + try + { + return soundClass.getDeclaredConstructor(EntityPlayer.class).newInstance(player); + } + catch(Exception e) + { + return null; + } + } } - public boolean hasSound(EntityPlayer player, Channel channel) + public boolean soundPlaying(EntityPlayer player, Channel channel) { String name = player.getCommandSenderName(); Map map = getMap(name); IResettableSound sound = map.get(channel.getName()); - return sound != null; + return !(sound == null || sound.isDonePlaying()); } - public void addSound(EntityPlayer player, Channel channel, IResettableSound newSound, boolean replace) + public void addSound(EntityPlayer player, Channel channel, boolean replace) { String name = player.getCommandSenderName(); Map map = getMap(name); IResettableSound sound = map.get(channel.getName()); if(sound == null || replace) { + PlayerSound newSound = channel.getNewSound(player); map.put(channel.getName(), newSound); } } @@ -77,10 +92,9 @@ public class SoundHandler IResettableSound sound = map.get(channel.getName()); if(sound != null) { - if(sound.isDonePlaying() && !getSoundMap().containsKey(sound)) + if(canRestartSound(sound)) { sound.reset(); - Mekanism.logger.info("Playing sound " + sound); playSound(sound); } return true;