diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index e6ce5fdde..985bb3914 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -1,7 +1,6 @@ package mekanism.client; import java.io.File; -import java.util.HashMap; import mekanism.api.Coord4D; import mekanism.api.MekanismConfig.client; @@ -90,7 +89,6 @@ import mekanism.client.render.tileentity.RenderSalinationController; import mekanism.client.render.tileentity.RenderSeismicVibrator; import mekanism.client.render.tileentity.RenderTeleporter; import mekanism.client.sound.SoundHandler; -import mekanism.client.sound.SoundMap; import mekanism.common.CommonProxy; import mekanism.common.Mekanism; import mekanism.common.MekanismBlocks; @@ -493,29 +491,6 @@ public class ClientProxy extends CommonProxy } } - @Override - public void unloadSoundHandler() - { - if(client.enableSounds) - { - if(MekanismClient.audioHandler != null) - { - synchronized(MekanismClient.audioHandler.soundMaps) - { - HashMap mapsCopy = new HashMap(); - mapsCopy.putAll(MekanismClient.audioHandler.soundMaps); - - for(SoundMap map : mapsCopy.values()) - { - map.kill(); - } - - MekanismClient.audioHandler.soundMaps.clear(); - } - } - } - } - @Override public void preInit() { diff --git a/src/main/java/mekanism/client/ClientTickHandler.java b/src/main/java/mekanism/client/ClientTickHandler.java index 32aff92b3..5f03839eb 100644 --- a/src/main/java/mekanism/client/ClientTickHandler.java +++ b/src/main/java/mekanism/client/ClientTickHandler.java @@ -7,45 +7,30 @@ import java.util.List; import java.util.Map; import java.util.Set; -import mekanism.api.EnumColor; import mekanism.api.IClientTicker; -import mekanism.api.MekanismConfig.client; import mekanism.api.gas.GasStack; import mekanism.client.sound.FlamethrowerSound; import mekanism.client.sound.GasMaskSound; import mekanism.client.sound.JetpackSound; -import mekanism.client.sound.SoundHandler; import mekanism.common.KeySync; import mekanism.common.Mekanism; import mekanism.common.ObfuscatedNames; -import mekanism.common.block.BlockMachine.MachineType; -import mekanism.common.item.ItemBlockMachine; -import mekanism.common.item.ItemConfigurator; -import mekanism.common.item.ItemElectricBow; import mekanism.common.item.ItemFlamethrower; import mekanism.common.item.ItemFreeRunners; import mekanism.common.item.ItemGasMask; import mekanism.common.item.ItemJetpack; import mekanism.common.item.ItemJetpack.JetpackMode; import mekanism.common.item.ItemScubaTank; -import mekanism.common.item.ItemWalkieTalkie; -import mekanism.common.network.PacketConfiguratorState.ConfiguratorStateMessage; -import mekanism.common.network.PacketElectricBowState.ElectricBowStateMessage; import mekanism.common.network.PacketFlamethrowerActive.FlamethrowerActiveMessage; import mekanism.common.network.PacketJetpackData.JetpackDataMessage; import mekanism.common.network.PacketJetpackData.JetpackPacket; -import mekanism.common.network.PacketPortableTankState.PortableTankStateMessage; import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage; import mekanism.common.network.PacketScubaTankData.ScubaTankPacket; -import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage; -import mekanism.common.util.LangUtils; import mekanism.common.util.MekanismUtils; -import mekanism.api.util.StackUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.StringUtils; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -54,6 +39,10 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER; +import static mekanism.client.sound.SoundHandler.Channel.GASMASK; +import static mekanism.client.sound.SoundHandler.Channel.JETPACK; + /** * Client-side tick handler for Mekanism. Used mainly for the update check upon startup. * @author AidanBrady @@ -90,27 +79,10 @@ public class ClientTickHandler { tickStart(); } - else if(event.phase == Phase.END) - { - tickEnd(); - } } public void tickStart() { - if(!preloadedSounds && client.enableSounds && MekanismClient.audioHandler != null && MekanismClient.audioHandler.isSystemLoaded()) - { - preloadedSounds = true; - - new Thread(new Runnable() { - @Override - public void run() - { - MekanismClient.audioHandler.preloadSounds(); - } - }).start(); - } - MekanismClient.ticksPassed++; if(!hasNotified && mc.theWorld != null && Mekanism.latestVersionNumber != null && Mekanism.recentNews != null) @@ -286,12 +258,11 @@ public class ClientTickHandler if(player != null) { - if(MekanismClient.audioHandler.getSound(player, SoundHandler.CHANNEL_JETPACK) == null) + if(!MekanismClient.audioHandler.hasSound(player, JETPACK)) { - //player.worldObj.playSoundAtEntity(player, "mekanism:item.jetpack", 1F, 1F); - player.worldObj.playSound(player.posX, player.posY, player.posZ, "mekanism:item.jetpack", 1, 1, false); - //new JetpackSound(MekanismClient.audioHandler.getIdentifier(player), player); + MekanismClient.audioHandler.addSound(player, JETPACK, new JetpackSound(player), false); } + MekanismClient.audioHandler.playSound(player, JETPACK); } } @@ -301,10 +272,11 @@ public class ClientTickHandler if(player != null) { - if(MekanismClient.audioHandler.getSound(player, SoundHandler.CHANNEL_GASMASK) == null) + if(!MekanismClient.audioHandler.hasSound(player, GASMASK)) { - new GasMaskSound(MekanismClient.audioHandler.getIdentifier(player), player); + MekanismClient.audioHandler.addSound(player, GASMASK, new GasMaskSound(player), false); } + MekanismClient.audioHandler.playSound(player, GASMASK); } } @@ -312,10 +284,11 @@ public class ClientTickHandler { if(hasFlamethrower(player)) { - if(MekanismClient.audioHandler.getSound(player, SoundHandler.CHANNEL_FLAMETHROWER) == null) + if(!MekanismClient.audioHandler.hasSound(player, FLAMETHROWER)) { - new FlamethrowerSound(MekanismClient.audioHandler.getIdentifier(player), player); + MekanismClient.audioHandler.addSound(player, FLAMETHROWER, new FlamethrowerSound(player), false); } + MekanismClient.audioHandler.playSound(player, FLAMETHROWER); } } } @@ -486,15 +459,4 @@ public class ClientTickHandler return false; } - - public void tickEnd() - { - if(MekanismClient.audioHandler != null) - { - synchronized(MekanismClient.audioHandler.soundMaps) - { - MekanismClient.audioHandler.onTick(); - } - } - } } diff --git a/src/main/java/mekanism/client/ThreadMultiblockSparkle.java b/src/main/java/mekanism/client/ThreadMultiblockSparkle.java index 8f894092f..c21208a6a 100644 --- a/src/main/java/mekanism/client/ThreadMultiblockSparkle.java +++ b/src/main/java/mekanism/client/ThreadMultiblockSparkle.java @@ -34,7 +34,7 @@ public class ThreadMultiblockSparkle extends Thread try { if(general.dynamicTankEasterEgg) { - MekanismClient.audioHandler.quickPlay("cj/CJ_" + (random.nextInt(8)+1) + ".ogg", pointer.getWorldObj(), Coord4D.get(pointer)); + pointer.getWorldObj().playSound(pointer.xCoord, pointer.yCoord, pointer.zCoord, "mekanism:etc.cj", 1F, 1F, false); } loop(pointer); diff --git a/src/main/java/mekanism/client/sound/FlamethrowerSound.java b/src/main/java/mekanism/client/sound/FlamethrowerSound.java index 927561159..b7d6eb2bb 100644 --- a/src/main/java/mekanism/client/sound/FlamethrowerSound.java +++ b/src/main/java/mekanism/client/sound/FlamethrowerSound.java @@ -1,60 +1,58 @@ package mekanism.client.sound; import mekanism.client.ClientTickHandler; + import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; +import net.minecraft.util.ResourceLocation; public class FlamethrowerSound extends PlayerSound { - public boolean inUse = false; - - public FlamethrowerSound(String id, EntityPlayer entity) + public boolean inUse; + + public ResourceLocation onSound; + public ResourceLocation offSound; + + public FlamethrowerSound(EntityPlayer player) { - super(id, getSound(ClientTickHandler.isFlamethrowerOn(entity)), SoundHandler.CHANNEL_FLAMETHROWER, entity); - - inUse = ClientTickHandler.isFlamethrowerOn(entity); + super(player, new ResourceLocation("mekanism", "item.flamethrower.idle")); + onSound = new ResourceLocation("mekanism", "item.flamethrower.active"); + offSound = new ResourceLocation("mekanism", "item.flamethrower.idle"); + setFadeIn(0); + setFadeOut(0); } @Override - public boolean update(World world) + public boolean isDonePlaying() { - if(!super.update(world)) - { - return false; - } - else if(!ClientTickHandler.hasFlamethrower(player)) - { - return false; - } - else if(inUse != ClientTickHandler.isFlamethrowerOn(player)) - { - return false; - } - - if(!isPlaying) - { - play(); - } - - ticksSincePlay++; + return donePlaying; + } + @Override + public boolean shouldPlaySound() + { return true; } - + @Override - public float getMultiplier() + public float getVolume() { - return super.getMultiplier() * (inUse ? 2 : 1); + return super.getVolume() * (inUse ? 2 : 1); } - + @Override - public boolean doGradualEffect() + public void update() { - return false; - } - - private static String getSound(boolean inUse) - { - return inUse ? "FlamethrowerActive.ogg" : "FlamethrowerIdle.ogg"; + if(!ClientTickHandler.hasFlamethrower(player)) + { + donePlaying = true; + + return; + } + if(inUse != ClientTickHandler.isFlamethrowerOn(player)) + { + inUse = ClientTickHandler.isFlamethrowerOn(player); + sound = inUse ? onSound : offSound; + donePlaying = true; + } } } diff --git a/src/main/java/mekanism/client/sound/GasMaskSound.java b/src/main/java/mekanism/client/sound/GasMaskSound.java index 52dfa9032..ce60fe3e7 100644 --- a/src/main/java/mekanism/client/sound/GasMaskSound.java +++ b/src/main/java/mekanism/client/sound/GasMaskSound.java @@ -2,46 +2,29 @@ package mekanism.client.sound; import mekanism.client.ClientTickHandler; import mekanism.common.item.ItemGasMask; + import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; +import net.minecraft.util.ResourceLocation; public class GasMaskSound extends PlayerSound { - public GasMaskSound(String id, EntityPlayer entity) + public GasMaskSound(EntityPlayer player) { - super(id, "GasMask.ogg", SoundHandler.CHANNEL_GASMASK, entity); + super(player, new ResourceLocation("mekanism", "item.gasMask")); + setFadeIn(0); + setFadeOut(0); } @Override - public boolean update(World world) + public boolean isDonePlaying() { - if(!super.update(world)) - { - return false; - } - else if(!hasGasMask(player)) - { - return false; - } - else { - if(ClientTickHandler.isGasMaskOn(player) != isPlaying) - { - if(ClientTickHandler.isGasMaskOn(player)) - { - play(); - } - else { - stopLoop(); - } - } - } + return donePlaying; + } - if(isPlaying) - { - ticksSincePlay++; - } - - return true; + @Override + public boolean shouldPlaySound() + { + return hasGasMask(player) && ClientTickHandler.isGasMaskOn(player); } private boolean hasGasMask(EntityPlayer player) diff --git a/src/main/java/mekanism/client/sound/IResettableSound.java b/src/main/java/mekanism/client/sound/IResettableSound.java new file mode 100644 index 000000000..b453875b7 --- /dev/null +++ b/src/main/java/mekanism/client/sound/IResettableSound.java @@ -0,0 +1,8 @@ +package mekanism.client.sound; + +import net.minecraft.client.audio.ITickableSound; + +public interface IResettableSound extends ITickableSound +{ + public void reset(); +} diff --git a/src/main/java/mekanism/client/sound/JetpackSound.java b/src/main/java/mekanism/client/sound/JetpackSound.java index 250c9aae5..792578499 100644 --- a/src/main/java/mekanism/client/sound/JetpackSound.java +++ b/src/main/java/mekanism/client/sound/JetpackSound.java @@ -2,46 +2,29 @@ package mekanism.client.sound; import mekanism.client.ClientTickHandler; import mekanism.common.item.ItemJetpack; + import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; +import net.minecraft.util.ResourceLocation; public class JetpackSound extends PlayerSound { - public JetpackSound(String id, EntityPlayer entity) + public JetpackSound(EntityPlayer player) { - super(id, "Jetpack.ogg", SoundHandler.CHANNEL_JETPACK, entity); + super(player, new ResourceLocation("mekanism", "item.jetpack")); + setFadeIn(0); + setFadeOut(0); } @Override - public boolean update(World world) + public boolean isDonePlaying() { - if(!super.update(world)) - { - return false; - } - else if(!hasJetpack(player)) - { - return false; - } - else { - if(ClientTickHandler.isJetpackOn(player) != isPlaying) - { - if(ClientTickHandler.isJetpackOn(player)) - { - play(); - } - else { - stopLoop(); - } - } - } + return donePlaying; + } - if(isPlaying) - { - ticksSincePlay++; - } - - return true; + @Override + public boolean shouldPlaySound() + { + return hasJetpack(player) && ClientTickHandler.isJetpackOn(player); } private boolean hasJetpack(EntityPlayer player) diff --git a/src/main/java/mekanism/client/sound/PlayerSound.java b/src/main/java/mekanism/client/sound/PlayerSound.java index 2511c137e..83653ebfb 100644 --- a/src/main/java/mekanism/client/sound/PlayerSound.java +++ b/src/main/java/mekanism/client/sound/PlayerSound.java @@ -1,53 +1,114 @@ package mekanism.client.sound; -import mekanism.api.Pos3D; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; +import mekanism.common.Mekanism; -public abstract class PlayerSound extends Sound +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; + +public abstract class PlayerSound extends Sound implements IResettableSound { - /** The TileEntity this sound is associated with. */ public EntityPlayer player; - public PlayerSound(String id, String sound, String chan, EntityPlayer entity) - { - super(id, sound, chan, entity, new Pos3D(entity)); + boolean beginFadeOut; + boolean donePlaying = true; + int ticks = 0; + int fadeIn = 50; + int fadeOut = 50; + float baseVolume = 0.3F; - player = entity; + + public PlayerSound(EntityPlayer player, ResourceLocation location) + { + super(location, 0.3F, 1, true, 0, (float) player.posX, (float) player.posY, (float) player.posZ, AttenuationType.LINEAR); + this.player = player; } @Override - public float getMultiplier() + public float getXPosF() { - return super.getMultiplier()*0.3F; + + return (float) player.posX; } @Override - public boolean update(World world) + public float getYPosF() { - if(!super.update(world)) - { - return false; - } - else if(player.isDead) - { - return false; - } - else if(player.worldObj != world) - { - return false; - } - else if(!world.loadedEntityList.contains(player)) - { - return false; - } - return true; + return (float) player.posY; } @Override - public Pos3D getLocation() + public float getZPosF() { - return new Pos3D(player); + + return (float) player.posZ; + } + + public PlayerSound setFadeIn(int fadeIn) { + + this.fadeIn = Math.min(0, fadeIn); + return this; + } + + public PlayerSound setFadeOut(int fadeOut) { + + this.fadeOut = Math.min(0, fadeOut); + return this; + } + + public float getFadeInMultiplier() { + + return ticks >= fadeIn ? 1 : (float) (ticks / (float) fadeIn); + } + + public float getFadeOutMultiplier() { + + return ticks >= fadeOut ? 0 : (float) ((fadeOut - ticks) / (float) fadeOut); + } + + @Override + public void update() + { + + if(!beginFadeOut) + { + if(ticks < fadeIn) + { + ticks++; + } + if(!shouldPlaySound()) + { + beginFadeOut = true; + ticks = 0; + } + } else + { + ticks++; + } + float multiplier = beginFadeOut ? getFadeOutMultiplier() : getFadeInMultiplier(); + volume = baseVolume * multiplier; + + if(multiplier <= 0) + { + Mekanism.logger.info("Sound Stopping. " + this); + donePlaying = true; + } + } + + @Override + public boolean isDonePlaying() + { + return donePlaying; + } + + public abstract boolean shouldPlaySound(); + + @Override + public void reset() + { + donePlaying = false; + beginFadeOut = false; + volume = baseVolume; + ticks = 0; } } diff --git a/src/main/java/mekanism/client/sound/Sound.java b/src/main/java/mekanism/client/sound/Sound.java index 8be57b8ac..8b94fd153 100644 --- a/src/main/java/mekanism/client/sound/Sound.java +++ b/src/main/java/mekanism/client/sound/Sound.java @@ -1,251 +1,178 @@ package mekanism.client.sound; -import java.net.URL; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; -import mekanism.api.MekanismConfig.client; -import mekanism.api.Pos3D; -import mekanism.client.MekanismClient; -import mekanism.common.Mekanism; -import net.minecraft.client.Minecraft; import net.minecraft.client.audio.ISound; -import net.minecraft.client.audio.ISound.AttenuationType; import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; -import net.minecraftforge.client.ForgeHooksClient; -public abstract class Sound -{ - /** The bundled path where the sound is */ - public String prevSoundPath; +/** + * Generic ISound class with lots of constructor functionality. + * Required because - of course - Mojang has no generic that + * lets you specify *any* arguments for this. + * + * Taken from CoFHLib + * + * @author skyboy + * + */ +@SideOnly(Side.CLIENT) +public class Sound implements ISound { - /** A unique identifier for this sound */ - public String identifier; + 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; - /** Whether or not this sound is playing */ - public boolean isPlaying = false; + public Sound(String sound) { - public int ticksSincePlay = 0; - - private Object objRef; - - public String channel; - - protected Minecraft mc = Minecraft.getMinecraft(); - - /** - * A sound that runs off of the PaulsCode sound system. - * @param id - unique identifier - * @param sound - bundled path to the sound - * @param tileentity - the tile this sound is playing from. - */ - public Sound(String id, String sound, String chan, Object obj, Pos3D loc) - { - if(MekanismClient.audioHandler.getSound(obj, chan) != null) - { - return; - } - - synchronized(MekanismClient.audioHandler.soundMaps) - { - prevSoundPath = sound; - identifier = id; - objRef = obj; - channel = chan; - - URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + sound); - - if(url == null) - { - Mekanism.logger.error("Invalid sound file: " + sound); - } - - if(SoundHandler.getSoundSystem() != null) - { - SoundHandler.getSoundSystem().newSource(false, id, url, sound, true, (float)loc.xPos, (float)loc.yPos, (float)loc.zPos, 0, 16F); - updateVolume(); - SoundHandler.getSoundSystem().activate(id); - } - - MekanismClient.audioHandler.registerSound(objRef, channel, this); - } + this(sound, 0); } - /** - * Start looping the sound effect - */ - public void play() - { - synchronized(MekanismClient.audioHandler.soundMaps) - { - if(isPlaying) - { - return; - } + public Sound(String sound, float volume) { - ISound sound = ForgeHooksClient.playSound(SoundHandler.getSoundManager(), new DummySound()); - if (!(sound instanceof DummySound)) return; - - ticksSincePlay = 0; - - if(SoundHandler.getSoundSystem() != null) - { - updateVolume(); - SoundHandler.getSoundSystem().play(identifier); - } - - isPlaying = true; - } + this(sound, volume, 0); } - /** - * Stop looping the sound effect - */ - public void stopLoop() - { - synchronized(MekanismClient.audioHandler.soundMaps) - { - if(!isPlaying) - { - return; - } + public Sound(String sound, float volume, float pitch) { - if(SoundHandler.getSoundSystem() != null) - { - updateVolume(); - SoundHandler.getSoundSystem().stop(identifier); - } - - isPlaying = false; - } + this(sound, volume, pitch, false, 0); } - /** - * Remove the sound effect from the PaulsCode SoundSystem and the Mekanism SoundHandler - */ - public void remove() - { - synchronized(MekanismClient.audioHandler.soundMaps) - { - if(isPlaying) - { - stopLoop(); - } + public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay) { - MekanismClient.audioHandler.removeSound(objRef, channel); - - if(SoundHandler.getSoundSystem() != null) - { - updateVolume(); - SoundHandler.getSoundSystem().removeSource(identifier); - } - } - } - - public String getSoundPath() - { - return prevSoundPath; + this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE); } - public boolean update(World world) - { - if(!getSoundPath().equals(prevSoundPath)) - { - return false; - } - - return true; + public Sound(String sound, float volume, float pitch, double x, double y, double z) { + + this(sound, volume, pitch, false, 0, x, y, z); } - public abstract Pos3D getLocation(); + public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z) { - public float getMultiplier() - { - return doGradualEffect() ? Math.min(1, ((float)ticksSincePlay/30F)) : 1; - } - - public boolean doGradualEffect() - { - return true; + this(sound, volume, pitch, repeat, repeatDelay, x, y, z, AttenuationType.LINEAR); } - /** - * Updates the volume based on how far away the player is from the machine. - * @param entityplayer - player who is near the machine, always Minecraft.thePlayer - */ - public void updateVolume() - { - synchronized(MekanismClient.audioHandler.soundMaps) - { - try { - float multiplier = getMultiplier(); - float volume = 0; - float masterVolume = MekanismClient.audioHandler.getMasterVolume(); - double distance = mc.thePlayer.getDistance(getLocation().xPos, getLocation().yPos, getLocation().zPos); - volume = (float)Math.min(Math.max(masterVolume-((distance*.08F)*masterVolume), 0)*multiplier, 1); - volume *= Math.max(0, Math.min(1, client.baseSoundVolume)); + public Sound(String sound, float volume, float pitch, boolean repeat, int repeatDelay, double x, double y, double z, AttenuationType attenuation) { - if(SoundHandler.getSoundSystem() != null) - { - SoundHandler.getSoundSystem().setVolume(identifier, volume); - } - } catch(Exception e) {} - } + this(new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation); } - public class DummySound implements ISound - { - @Override - public ResourceLocation getPositionedSoundLocation() - { - return new ResourceLocation("mekanism", "sound.ogg"); - } + public Sound(ResourceLocation sound) { - @Override - public boolean canRepeat() - { - return false; - } - - @Override - public int getRepeatDelay() - { - return 0; - } - - @Override - public float getVolume() - { - return 1; - } - - @Override - public float getPitch() - { - return 0; - } - - @Override - public float getXPosF() - { - return (float)getLocation().xPos; - } - - @Override - public float getYPosF() - { - return (float)getLocation().yPos; - } - - @Override - public float getZPosF() - { - return (float)getLocation().zPos; - } - - @Override - public AttenuationType getAttenuationType() - { - return AttenuationType.LINEAR; - } + this(sound, 0); } + + public Sound(ResourceLocation sound, float volume) { + + this(sound, volume, 0); + } + + 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) { + + 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) { + + 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) { + + 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(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; + } + + @Override + public AttenuationType getAttenuationType() { + + return attenuation; + } + + @Override + public ResourceLocation getPositionedSoundLocation() { + + return sound; + } + + @Override + public float getVolume() { + + return volume; + } + + @Override + public float getPitch() { + + return pitch; + } + + @Override + public float getXPosF() { + + return x; + } + + @Override + public float getYPosF() { + + return y; + } + + @Override + public float getZPosF() { + + return z; + } + + @Override + public boolean canRepeat() { + + return repeat; + } + + @Override + public int getRepeatDelay() { + + return repeatDelay; + } + } diff --git a/src/main/java/mekanism/client/sound/SoundBase.java b/src/main/java/mekanism/client/sound/SoundBase.java deleted file mode 100644 index 0fb19c2e4..000000000 --- a/src/main/java/mekanism/client/sound/SoundBase.java +++ /dev/null @@ -1,178 +0,0 @@ -package mekanism.client.sound; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.client.audio.ISound; -import net.minecraft.util.ResourceLocation; - -/** - * Generic ISound class with lots of constructor functionality. - * Required because - of course - Mojang has no generic that - * lets you specify *any* arguments for this. - * - * Taken from CoFHLib - * - * @author skyboy - * - */ -@SideOnly(Side.CLIENT) -public class SoundBase implements ISound { - - protected AttenuationType attenuation; - protected final ResourceLocation sound; - protected float volume; - protected float pitch; - protected float x; - protected float y; - protected float z; - protected boolean repeat; - protected int repeatDelay; - - public SoundBase(String sound) { - - this(sound, 0); - } - - public SoundBase(String sound, float volume) { - - this(sound, volume, 0); - } - - public SoundBase(String sound, float volume, float pitch) { - - this(sound, volume, pitch, false, 0); - } - - public SoundBase(String sound, float volume, float pitch, boolean repeat, int repeatDelay) { - - this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE); - } - - public SoundBase(String sound, float volume, float pitch, double x, double y, double z) { - - this(sound, volume, pitch, false, 0, x, y, z); - } - - public SoundBase(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 SoundBase(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 SoundBase(ResourceLocation sound) { - - this(sound, 0); - } - - public SoundBase(ResourceLocation sound, float volume) { - - this(sound, volume, 0); - } - - public SoundBase(ResourceLocation sound, float volume, float pitch) { - - this(sound, volume, pitch, false, 0); - } - - public SoundBase(ResourceLocation sound, float volume, float pitch, boolean repeat, int repeatDelay) { - - this(sound, volume, pitch, repeat, repeatDelay, 0, 0, 0, AttenuationType.NONE); - } - - public SoundBase(ResourceLocation sound, float volume, float pitch, double x, double y, double z) { - - this(sound, volume, pitch, false, 0, x, y, z); - } - - public SoundBase(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 SoundBase(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 SoundBase(SoundBase 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; - } - - @Override - public AttenuationType getAttenuationType() { - - return attenuation; - } - - @Override - public ResourceLocation getPositionedSoundLocation() { - - return sound; - } - - @Override - public float getVolume() { - - return volume; - } - - @Override - public float getPitch() { - - return pitch; - } - - @Override - public float getXPosF() { - - return x; - } - - @Override - public float getYPosF() { - - return y; - } - - @Override - public float getZPosF() { - - return z; - } - - @Override - public boolean canRepeat() { - - return repeat; - } - - @Override - public int getRepeatDelay() { - - return repeatDelay; - } - -} diff --git a/src/main/java/mekanism/client/sound/SoundHandler.java b/src/main/java/mekanism/client/sound/SoundHandler.java index 060ba80d6..ec3f8c413 100644 --- a/src/main/java/mekanism/client/sound/SoundHandler.java +++ b/src/main/java/mekanism/client/sound/SoundHandler.java @@ -1,36 +1,18 @@ package mekanism.client.sound; -import java.io.File; -import java.io.FileInputStream; -import java.net.URL; -import java.security.CodeSource; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.Random; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import mekanism.api.Coord4D; -import mekanism.api.MekanismConfig.client; -import mekanism.client.HolidayManager; import mekanism.common.Mekanism; import mekanism.common.ObfuscatedNames; import mekanism.common.util.MekanismUtils; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.ITickableSound; import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.audio.SoundCategory; import net.minecraft.client.audio.SoundManager; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.ChunkEvent; -import paulscode.sound.SoundSystem; -import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -43,298 +25,80 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class SoundHandler { - /** All the sound references in the Minecraft game. */ - public Map soundMaps = Collections.synchronizedMap(new HashMap()); + public Map> soundMaps = new HashMap>(); + + public static Map invPlayingSounds; public static Minecraft mc = Minecraft.getMinecraft(); - - public static final String CHANNEL_TILE_DEFAULT = "tile"; - public static final String CHANNEL_JETPACK = "jetpack"; - public static final String CHANNEL_GASMASK = "gasMask"; - public static final String CHANNEL_FLAMETHROWER = "flamethrower"; - /** - * SoundHandler -- a class that handles all Sounds used by Mekanism. - */ - public SoundHandler() + public enum Channel { - MinecraftForge.EVENT_BUS.register(this); + JETPACK("jetpack"), + GASMASK("gasMask"), + FLAMETHROWER("flamethrower"); - Mekanism.logger.info("Successfully set up SoundHandler."); + String channelName; + + private Channel(String name) + { + channelName = name; + } + + public String getName() + { + return channelName; + } } - public void preloadSounds() + public boolean hasSound(EntityPlayer player, Channel channel) { - CodeSource src = getClass().getProtectionDomain().getCodeSource(); - String corePath = src.getLocation().getFile().split("/mekanism/client")[0]; - List listings = listFiles(corePath.replace("%20", " ").replace(".jar!", ".jar").replace("file:", ""), "assets/mekanism/sounds"); + String name = player.getCommandSenderName(); + Map map = getMap(name); + IResettableSound sound = map.get(channel.getName()); - for(String s : listings) + return sound != null; + } + + public void addSound(EntityPlayer player, Channel channel, IResettableSound newSound, boolean replace) + { + String name = player.getCommandSenderName(); + Map map = getMap(name); + IResettableSound sound = map.get(channel.getName()); + if(sound == null || replace) { - if(s.contains("etc") || s.contains("holiday")) + map.put(channel.getName(), newSound); + } + } + + public boolean playSound(EntityPlayer player, Channel channel) + { + String name = player.getCommandSenderName(); + Map map = getMap(name); + IResettableSound sound = map.get(channel.getName()); + if(sound != null) + { + if(sound.isDonePlaying() && !getSoundMap().containsKey(sound)) { - continue; - } - - if(s.contains("/mekanism/sounds/")) - { - s = s.split("/mekanism/sounds/")[1]; - } - - preloadSound(s); - } - - Mekanism.logger.info("Preloaded " + listings.size() + " object sounds."); - - if(client.holidays) - { - listings = listFiles(corePath.replace("%20", " ").replace(".jar!", ".jar").replace("file:", ""), "assets/mekanism/sounds/holiday"); - - for(String s : listings) - { - if(s.contains("/mekanism/sounds/")) - { - s = s.split("/mekanism/sounds/")[1]; - } - - if(!s.contains("holiday")) - { - s = "holiday/" + s; - } - - preloadSound(s); + sound.reset(); + Mekanism.logger.info("Playing sound " + sound); + playSound(sound); } + return true; } + return false; } - private List listFiles(String path, String s) + public Map getMap(String name) { - List names = new ArrayList(); - - File f = new File(path); - - if(!f.exists()) + Map map = soundMaps.get(name); + if(map == null) { - return names; + map = new HashMap(); + soundMaps.put(name, map); } - - if(!f.isDirectory()) - { - try { - ZipInputStream zip = new ZipInputStream(new FileInputStream(path)); - - while(true) - { - ZipEntry e = zip.getNextEntry(); - - if(e == null) - { - break; - } - - String name = e.getName(); - - if(name.contains(s) && name.endsWith(".ogg")) - { - names.add(name); - } - } - - zip.close(); - } catch(Exception e) { - e.printStackTrace(); - } - } - else { - f = new File(path + "/" + s); - - for(File file : f.listFiles()) - { - if(file.getPath().contains(s) && file.getName().endsWith(".ogg")) - { - names.add(file.getName()); - } - } - } - - return names; + return map; } - private void preloadSound(String sound) - { - String id = "pre_" + sound; - URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + sound); - - if(getSoundSystem() != null) - { - getSoundSystem().newSource(false, id, url, sound, true, 0, 0, 0, 0, 16F); - getSoundSystem().activate(id); - getSoundSystem().removeSource(id); - } - } - - /** - * Ticks the sound handler. Should be called every Minecraft tick, or 20 times per second. - */ - public void onTick() - { - synchronized(soundMaps) - { - if(getSoundSystem() != null) - { - if(!Mekanism.proxy.isPaused()) - { - ArrayList soundsToRemove = new ArrayList(); - World world = FMLClientHandler.instance().getClient().theWorld; - - if(FMLClientHandler.instance().getClient().thePlayer != null && world != null) - { - for(SoundMap map : soundMaps.values()) - { - for(Sound sound : map) - { - if(!sound.update(world)) - { - soundsToRemove.add(sound); - continue; - } - - if(sound.isPlaying) - { - sound.updateVolume(); - } - } - } - - for(Sound sound : soundsToRemove) - { - sound.remove(); - } - } - } - else { - for(SoundMap map : soundMaps.values()) - { - map.stopLoops(); - } - } - } - else { - Mekanism.proxy.unloadSoundHandler(); - } - } - } - - public void removeSound(Object ref, String channel) - { - if(soundMaps.get(ref) == null) - { - return; - } - - soundMaps.get(ref).remove(channel); - - if(soundMaps.get(ref).isEmpty()) - { - soundMaps.remove(ref); - } - } - - public void registerSound(Object ref, String channel, Sound sound) - { - if(soundMaps.get(ref) == null) - { - soundMaps.put(ref, new SoundMap(ref, channel, sound)); - return; - } - - soundMaps.get(ref).add(channel, sound); - } - - /** - * Gets a sound object from a specific TileEntity, null if there is none. - * @param tileEntity - the holder of the sound - * @return Sound instance - */ - public SoundMap getMap(Object ref) - { - synchronized(soundMaps) - { - return soundMaps.get(ref); - } - } - - public Sound getSound(Object ref, String channel) - { - if(soundMaps.get(ref) == null) - { - return null; - } - - return soundMaps.get(ref).getSound(channel); - } - - /** - * Get a unique identifier for a sound effect instance by combining the mod's name, - * Mekanism, the new sound's unique position on the 'sounds' ArrayList, and a random - * number between 0 and 10,000. Example: "Mekanism_6_6123" - * @return unique identifier - */ - public String getIdentifier(Object obj) - { - synchronized(soundMaps) - { - String toReturn = "Mekanism_" + getActiveSize() + "_" + new Random().nextInt(10000); - - return toReturn; - } - } - - public int getActiveSize() - { - int count = 0; - - for(SoundMap map : soundMaps.values()) - { - count += map.size(); - } - - return count; - } - - /** - * Plays a sound in a specific location. - * @param soundPath - sound path to play - * @param world - world to play in - * @param object - location to play - */ - public void quickPlay(String soundPath, World world, Coord4D object) - { - URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + soundPath); - - if(url == null) - { - Mekanism.logger.info("Invalid sound file: " + soundPath); - } - - String s = getSoundSystem().quickPlay(false, url, soundPath, false, object.xCoord, object.yCoord, object.zCoord, 0, 16F); - getSoundSystem().setVolume(s, getMasterVolume()); - } - - public float getMasterVolume() - { - return FMLClientHandler.instance().getClient().gameSettings.getSoundLevel(SoundCategory.MASTER); - } - - public static SoundSystem getSoundSystem() - { - try { - return (SoundSystem)MekanismUtils.getPrivateValue(getSoundManager(), SoundManager.class, ObfuscatedNames.SoundManager_sndSystem); - } catch(Exception e) { - return null; - } - } - public static SoundManager getSoundManager() { try { @@ -343,44 +107,32 @@ public class SoundHandler return null; } } - - public static boolean isSystemLoaded() + + //Fudge required because sound thread gets behind and the biMap crashes when rapidly toggling sounds. + public static Map getSoundMap() { + if(invPlayingSounds == null) try { - return (Boolean)MekanismUtils.getPrivateValue(getSoundManager(), net.minecraft.client.audio.SoundManager.class, new String[] {"loaded"}); + invPlayingSounds = (Map)MekanismUtils.getPrivateValue(getSoundManager(), net.minecraft.client.audio.SoundManager.class, ObfuscatedNames.SoundManager_invPlayingSounds); } catch(Exception e) { - return false; + invPlayingSounds = null; } + return invPlayingSounds; + + } + + public static boolean canRestartSound(ITickableSound sound) + { + return sound.isDonePlaying() && !getSoundMap().containsKey(sound); } public static void playSound(String sound) { - mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(sound), 1.0F)); + playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(sound), 1.0F)); } - @SubscribeEvent - public void onChunkUnload(ChunkEvent.Unload event) + public static void playSound(ISound sound) { - if(event.getChunk() != null) - { - for(Object obj : event.getChunk().chunkTileEntityMap.values()) - { - if(obj instanceof TileEntity) - { - TileEntity tileEntity = (TileEntity)obj; - - if(tileEntity instanceof IHasSound) - { - if(getMap(tileEntity) != null) - { - if(soundMaps.containsKey(tileEntity)) - { - getMap(tileEntity).kill(); - } - } - } - } - } - } + mc.getSoundHandler().playSound(sound); } } diff --git a/src/main/java/mekanism/client/sound/SoundMap.java b/src/main/java/mekanism/client/sound/SoundMap.java deleted file mode 100644 index de024ece3..000000000 --- a/src/main/java/mekanism/client/sound/SoundMap.java +++ /dev/null @@ -1,83 +0,0 @@ -package mekanism.client.sound; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import mekanism.client.MekanismClient; - -public class SoundMap implements Iterable -{ - public Map soundMap = new HashMap(); - - public Object objRef; - - public SoundMap(Object obj) - { - objRef = obj; - } - - public SoundMap(Object obj, String channel, Sound sound) - { - this(obj); - - soundMap.put(channel, sound); - } - - @Override - public Iterator iterator() - { - return soundMap.values().iterator(); - } - - public Sound getSound(String channel) - { - return soundMap.get(channel); - } - - public boolean hasSound(String channel) - { - return soundMap.containsKey(channel); - } - - public void remove(String channel) - { - soundMap.remove(channel); - } - - public void add(String channel, Sound sound) - { - soundMap.put(channel, sound); - } - - public void stopLoops() - { - for(Sound sound : soundMap.values()) - { - if(sound.isPlaying) - { - sound.stopLoop(); - } - } - } - - public void kill() - { - for(Sound sound : soundMap.values()) - { - sound.remove(); - } - - MekanismClient.audioHandler.soundMaps.remove(objRef); - } - - public boolean isEmpty() - { - return soundMap.isEmpty(); - } - - public int size() - { - return soundMap.size(); - } -} diff --git a/src/main/java/mekanism/client/sound/SoundTile.java b/src/main/java/mekanism/client/sound/TileSound.java similarity index 81% rename from src/main/java/mekanism/client/sound/SoundTile.java rename to src/main/java/mekanism/client/sound/TileSound.java index c325f606f..5456c1b18 100644 --- a/src/main/java/mekanism/client/sound/SoundTile.java +++ b/src/main/java/mekanism/client/sound/TileSound.java @@ -1,9 +1,8 @@ package mekanism.client.sound; -import net.minecraft.client.audio.ITickableSound; import net.minecraft.util.ResourceLocation; -public class SoundTile extends SoundBase implements ITickableSound { +public class TileSound extends Sound implements IResettableSound { IHasSound source; boolean beginFadeOut; @@ -13,28 +12,28 @@ public class SoundTile extends SoundBase implements ITickableSound { int fadeOut = 50; float baseVolume = 1.0F; - public SoundTile(IHasSound source, ISoundSource values) + public TileSound(IHasSound source, ISoundSource values) { this(source, values.getSoundLocation(), values.getVolume(), values.getPitch(), values.shouldRepeat(), values.getRepeatDelay(), values.getSoundPosition().xPos, values.getSoundPosition().yPos, values.getSoundPosition().zPos); } - public SoundTile(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 SoundTile(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, AttenuationType attenuation) { this(source, new ResourceLocation(sound), volume, pitch, repeat, repeatDelay, x, y, z, attenuation); } - public SoundTile(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 SoundTile(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, AttenuationType attenuation) { super(sound, volume, pitch, repeat, repeatDelay, x, y, z, attenuation); @@ -42,13 +41,13 @@ public class SoundTile extends SoundBase implements ITickableSound { this.baseVolume = volume; } - public SoundTile setFadeIn(int fadeIn) { + public TileSound setFadeIn(int fadeIn) { this.fadeIn = Math.min(0, fadeIn); return this; } - public SoundTile setFadeOut(int fadeOut) { + public TileSound setFadeOut(int fadeOut) { this.fadeOut = Math.min(0, fadeOut); return this; @@ -93,10 +92,12 @@ public class SoundTile extends SoundBase implements ITickableSound { return donePlaying; } + @Override public void reset() { donePlaying = false; beginFadeOut = false; + volume = baseVolume; ticks = 0; } } diff --git a/src/main/java/mekanism/common/ObfuscatedNames.java b/src/main/java/mekanism/common/ObfuscatedNames.java index 6728d2c0e..649e0611e 100644 --- a/src/main/java/mekanism/common/ObfuscatedNames.java +++ b/src/main/java/mekanism/common/ObfuscatedNames.java @@ -14,4 +14,5 @@ public final class ObfuscatedNames public static String[] NetHandlerPlayServer_floatingTickCount = new String[] {"floatingTickCount", "field_147365_f"}; public static String[] SoundHandler_sndManager = new String[] {"sndManager", "field_147694_f"}; public static String[] SoundManager_sndSystem = new String[] {"sndSystem", "field_148620_e"}; + public static String[] SoundManager_invPlayingSounds = new String[] {"invPlayingSounds", "field_148630_i"}; } \ No newline at end of file diff --git a/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java b/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java index 2a219bfb8..1ddceedc8 100644 --- a/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java +++ b/src/main/java/mekanism/common/tile/TileEntityBasicMachine.java @@ -8,10 +8,6 @@ import mekanism.api.Coord4D; import mekanism.api.Pos3D; import mekanism.api.Range4D; import mekanism.api.MekanismConfig.general; -import mekanism.client.sound.IHasSound; -import mekanism.client.sound.ISoundSource; -import mekanism.client.sound.SoundTile; -import mekanism.client.sound.TestSound; import mekanism.common.Mekanism; import mekanism.common.SideData; import mekanism.common.base.IActiveState; diff --git a/src/main/java/mekanism/common/tile/TileEntityCrusher.java b/src/main/java/mekanism/common/tile/TileEntityCrusher.java index df2250209..19bef9c94 100644 --- a/src/main/java/mekanism/common/tile/TileEntityCrusher.java +++ b/src/main/java/mekanism/common/tile/TileEntityCrusher.java @@ -3,17 +3,9 @@ package mekanism.common.tile; import java.util.Map; import mekanism.api.MekanismConfig.usage; -import mekanism.client.sound.TestSound; -import mekanism.common.Mekanism; import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.recipe.RecipeHandler.Recipe; -import net.minecraft.client.audio.ISound.AttenuationType; -import net.minecraft.client.audio.PositionedSound; -import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.util.ResourceLocation; -import cpw.mods.fml.client.FMLClientHandler; - public class TileEntityCrusher extends TileEntityElectricMachine { public TileEntityCrusher() diff --git a/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java b/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java index 71af7b727..5ee9540d8 100644 --- a/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityNoisyElectricBlock.java @@ -2,15 +2,17 @@ package mekanism.common.tile; import mekanism.api.Pos3D; import mekanism.client.sound.IHasSound; +import mekanism.client.sound.IResettableSound; import mekanism.client.sound.ISoundSource; -import mekanism.client.sound.SoundTile; -import mekanism.common.Mekanism; +import mekanism.client.sound.SoundHandler; +import mekanism.client.sound.TileSound; +import mekanism.common.Upgrade; import mekanism.common.base.IActiveState; +import mekanism.common.base.IUpgradeTile; import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.ISound.AttenuationType; import net.minecraft.util.ResourceLocation; -import cpw.mods.fml.client.FMLClientHandler; public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlock implements IHasSound, ISoundSource, IActiveState { @@ -18,7 +20,7 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo public ResourceLocation soundURL; /** The bundled URL of this machine's sound effect */ - public SoundTile sound; + public IResettableSound sound; /** * The base of all blocks that deal with electricity and make noise. @@ -60,6 +62,11 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo @Override public float getPitch() { + if(this instanceof IUpgradeTile) + { + float speedUpgrades = ((IUpgradeTile)this).getComponent().getUpgrades(Upgrade.SPEED); + return 1F + 20 * speedUpgrades / (float)Upgrade.SPEED.getMax(); + } return 1F; } @@ -91,17 +98,16 @@ public abstract class TileEntityNoisyElectricBlock extends TileEntityElectricBlo public void validate() { super.validate(); - sound = new SoundTile(this, this); + sound = new TileSound(this, this); } @Override public void onUpdate() { - if(worldObj.isRemote && shouldPlaySound() && sound.isDonePlaying()) + if(worldObj.isRemote && shouldPlaySound() && SoundHandler.canRestartSound(sound)) { - Mekanism.logger.info("Playing " + this.fullName + " noise"); sound.reset(); - FMLClientHandler.instance().getClient().getSoundHandler().playSound(sound); + SoundHandler.playSound(sound); } } } diff --git a/src/main/java/mekanism/common/util/MekanismUtils.java b/src/main/java/mekanism/common/util/MekanismUtils.java index 4bb484eb5..214484aae 100644 --- a/src/main/java/mekanism/common/util/MekanismUtils.java +++ b/src/main/java/mekanism/common/util/MekanismUtils.java @@ -608,7 +608,7 @@ public final class MekanismUtils */ public static int getTicks(IUpgradeTile mgmt, int def) { - return def * (int)Math.pow(general.maxUpgradeMultiplier, (float)-mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax()); + return (int)(def * Math.pow(general.maxUpgradeMultiplier, (float)-mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax())); } /** diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java index 6c8dd4898..068aedcf7 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityGenerator.java @@ -6,26 +6,21 @@ import java.util.ArrayList; import java.util.EnumSet; import mekanism.api.Coord4D; -import mekanism.api.Pos3D; import mekanism.api.Range4D; import mekanism.api.MekanismConfig.general; import mekanism.client.sound.IHasSound; import mekanism.client.sound.ISoundSource; -import mekanism.client.sound.SoundTile; +import mekanism.client.sound.TileSound; import mekanism.common.Mekanism; import mekanism.common.base.IActiveState; import mekanism.common.base.IRedstoneControl; import mekanism.common.network.PacketTileEntity.TileEntityMessage; -import mekanism.common.tile.TileEntityElectricBlock; import mekanism.common.tile.TileEntityNoisyElectricBlock; import mekanism.common.util.CableUtils; import mekanism.common.util.MekanismUtils; -import net.minecraft.client.audio.ISound; -import net.minecraft.client.audio.ISound.AttenuationType; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Method; @@ -130,7 +125,7 @@ public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock i { super.validate(); - sound = new SoundTile(this, this); + sound = new TileSound(this, this); } /** diff --git a/src/main/resources/assets/mekanism/sounds.json b/src/main/resources/assets/mekanism/sounds.json index 299a1e81a..c4e25c43e 100644 --- a/src/main/resources/assets/mekanism/sounds.json +++ b/src/main/resources/assets/mekanism/sounds.json @@ -1,38 +1,49 @@ { - "etc.Beep": {"category": "master","sounds": [{"name": "etc/Beep","stream": false}]}, - "etc.Click": {"category": "master","sounds": [{"name": "etc/Click","stream": false}]}, - "etc.Ding": {"category": "master","sounds": [{"name": "etc/Ding","stream": false}]}, - "etc.Error": {"category": "master","sounds": [{"name": "etc/Error","stream": false}]}, - "etc.GasMask": {"category": "master","sounds": [{"name": "etc/GasMask","stream": false}]}, - "etc.Hydraulic": {"category": "master","sounds": [{"name": "etc/Hydraulic","stream": false}]}, - "etc.Pop": {"category": "master","sounds": [{"name": "etc/Pop","stream": false}]}, - "etc.Success": {"category": "master","sounds": [{"name": "etc/Success","stream": false}]}, + "etc.Beep": {"category": "master", "sounds": [{"name": "etc/Beep", "stream": false}]}, + "etc.Click": {"category": "master", "sounds": [{"name": "etc/Click", "stream": false}]}, + "etc.Ding": {"category": "master", "sounds": [{"name": "etc/Ding", "stream": false}]}, + "etc.Error": {"category": "master", "sounds": [{"name": "etc/Error", "stream": false}]}, + "etc.GasMask": {"category": "master", "sounds": [{"name": "etc/GasMask", "stream": false}]}, + "etc.Hydraulic": {"category": "master", "sounds": [{"name": "etc/Hydraulic", "stream": false}]}, + "etc.Pop": {"category": "master", "sounds": [{"name": "etc/Pop", "stream": false}]}, + "etc.Success": {"category": "master", "sounds": [{"name": "etc/Success", "stream": false}]}, + "etc.cj": {"category": "block", "sounds": [ + {"name": "cj/CJ_1", "stream": false}, + {"name": "cj/CJ_2", "stream": false}, + {"name": "cj/CJ_3", "stream": false}, + {"name": "cj/CJ_4", "stream": false}, + {"name": "cj/CJ_5", "stream": false}, + {"name": "cj/CJ_6", "stream": false}, + {"name": "cj/CJ_7", "stream": false}, + {"name": "cj/CJ_8", "stream": false} + ] + }, - "tile.machine.chargepad": {"category": "block", "sounds": [{"name": "Chargepad","stream": false}]}, - "tile.machine.crystallizer": {"category": "block", "sounds": [{"name": "ChemicalCrystallizer","stream": false}]}, - "tile.machine.dissolution": {"category": "block", "sounds": [{"name": "ChemicalDissolutionChamber","stream": false}]}, - "tile.machine.cheminfuser": {"category": "block", "sounds": [{"name": "ChemicalInfuser","stream": false}]}, - "tile.machine.injection": {"category": "block", "sounds": [{"name": "ChemicalInjectionChamber","stream": false}]}, - "tile.machine.oxidizer": {"category": "block", "sounds": [{"name": "ChemicalOxidizer","stream": false}]}, - "tile.machine.washer": {"category": "block", "sounds": [{"name": "ChemicalWasher","stream": false}]}, - "tile.machine.combiner": {"category": "block", "sounds": [{"name": "Combiner","stream": false}]}, - "tile.machine.compressor": {"category": "block", "sounds": [{"name": "Compressor","stream": false}]}, - "tile.machine.crusher": {"category": "block", "sounds": [{"name": "Crusher","stream": false}]}, - "tile.machine.enrichment": {"category": "block", "sounds": [{"name": "EnrichmentChamber","stream": false}]}, - "tile.machine.metalinfuser": {"category": "block", "sounds": [{"name": "MetallurgicInfuser","stream": false}]}, - "tile.machine.sawmill": {"category": "block", "sounds": [{"name": "PrecisionSawmill","stream": false}]}, - "tile.machine.prc": {"category": "block", "sounds": [{"name": "PressurizedReactionChamber","stream": false}]}, - "tile.machine.purification": {"category": "block", "sounds": [{"name": "PurificationChamber","stream": false}]}, - "tile.machine.smelter": {"category": "block", "sounds": [{"name": "Smelter","stream": false}]}, + "tile.machine.chargepad": {"category": "block", "sounds": [{"name": "Chargepad", "stream": false}]}, + "tile.machine.crystallizer": {"category": "block", "sounds": [{"name": "ChemicalCrystallizer", "stream": false}]}, + "tile.machine.dissolution": {"category": "block", "sounds": [{"name": "ChemicalDissolutionChamber", "stream": false}]}, + "tile.machine.cheminfuser": {"category": "block", "sounds": [{"name": "ChemicalInfuser", "stream": false}]}, + "tile.machine.injection": {"category": "block", "sounds": [{"name": "ChemicalInjectionChamber", "stream": false}]}, + "tile.machine.oxidizer": {"category": "block", "sounds": [{"name": "ChemicalOxidizer", "stream": false}]}, + "tile.machine.washer": {"category": "block", "sounds": [{"name": "ChemicalWasher", "stream": false}]}, + "tile.machine.combiner": {"category": "block", "sounds": [{"name": "Combiner", "stream": false}]}, + "tile.machine.compressor": {"category": "block", "sounds": [{"name": "Compressor", "stream": false}]}, + "tile.machine.crusher": {"category": "block", "sounds": [{"name": "Crusher", "stream": false}]}, + "tile.machine.enrichment": {"category": "block", "sounds": [{"name": "EnrichmentChamber", "stream": false}]}, + "tile.machine.metalinfuser": {"category": "block", "sounds": [{"name": "MetallurgicInfuser", "stream": false}]}, + "tile.machine.sawmill": {"category": "block", "sounds": [{"name": "PrecisionSawmill", "stream": false}]}, + "tile.machine.prc": {"category": "block", "sounds": [{"name": "PressurizedReactionChamber", "stream": false}]}, + "tile.machine.purification": {"category": "block", "sounds": [{"name": "PurificationChamber", "stream": false}]}, + "tile.machine.smelter": {"category": "block", "sounds": [{"name": "Smelter", "stream": false}]}, - "tile.gen.bio": {"category": "block", "sounds": [{"name": "BioGenerator","stream": false}]}, - "tile.gen.gas": {"category": "block", "sounds": [{"name": "GasGenerator","stream": false}]}, - "tile.gen.heat": {"category": "block", "sounds": [{"name": "HeatGenerator","stream": false}]}, - "tile.gen.solar": {"category": "block", "sounds": [{"name": "SolarGenerator","stream": false}]}, - "tile.gen.wind": {"category": "block", "sounds": [{"name": "WindTurbine","stream": false}]}, + "tile.gen.bio": {"category": "block", "sounds": [{"name": "BioGenerator", "stream": false}]}, + "tile.gen.gas": {"category": "block", "sounds": [{"name": "GasGenerator", "stream": false}]}, + "tile.gen.heat": {"category": "block", "sounds": [{"name": "HeatGenerator", "stream": false}]}, + "tile.gen.solar": {"category": "block", "sounds": [{"name": "SolarGenerator", "stream": false}]}, + "tile.gen.wind": {"category": "block", "sounds": [{"name": "WindTurbine", "stream": false}]}, - "item.flamethrower.idle": {"category": "player", "sounds": [{"name": "FlamethrowerIdle","stream": false}]}, - "item.flamethrower.active": {"category": "player", "sounds": [{"name": "FlamethrowerActive","stream": false}]}, - "item.gasmask": {"category": "player", "sounds": [{"name": "GasMask","stream": false}]}, - "item.jetpack": {"category": "player", "sounds": [{"name": "Jetpack","stream": false}]} + "item.flamethrower.idle": {"category": "player", "sounds": [{"name": "FlamethrowerIdle", "stream": false}]}, + "item.flamethrower.active": {"category": "player", "sounds": [{"name": "FlamethrowerActive", "stream": false}]}, + "item.gasMask": {"category": "player", "sounds": [{"name": "GasMask", "stream": false}]}, + "item.jetpack": {"category": "player", "sounds": [{"name": "Jetpack", "stream": false}]} } \ No newline at end of file