From f0d3848f8a0c79527524d290ea7791edf5e76c12 Mon Sep 17 00:00:00 2001
From: "Aidan C. Brady" <aidancbrady@aol.com>
Date: Tue, 3 Jun 2014 20:57:59 +0200
Subject: [PATCH] Sounds work! Also got tick handlers set up, still have to do
 a few things

---
 .../java/mekanism/client/ClientProxy.java     |  8 ++--
 .../mekanism/client/ClientTickHandler.java    |  2 +-
 .../java/mekanism/client/MekKeyHandler.java   | 16 -------
 .../mekanism/client/MekanismKeyHandler.java   | 22 +++++++++
 .../java/mekanism/client/sound/Sound.java     |  5 +-
 .../mekanism/client/sound/SoundHandler.java   | 47 ++++++++++---------
 .../java/mekanism/common/CommonProxy.java     |  6 ++-
 .../resources/assets/mekanism/lang/en_US.lang |  1 +
 8 files changed, 61 insertions(+), 46 deletions(-)

diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java
index 3c393983e..f4f05d4a7 100644
--- a/src/main/java/mekanism/client/ClientProxy.java
+++ b/src/main/java/mekanism/client/ClientProxy.java
@@ -46,6 +46,7 @@ import mekanism.client.gui.GuiTeleporter;
 import mekanism.client.render.MekanismRenderer;
 import mekanism.client.render.RenderGlowPanel;
 import mekanism.client.render.RenderPartTransmitter;
+import mekanism.client.render.RenderTickHandler;
 import mekanism.client.render.block.BasicRenderingHandler;
 import mekanism.client.render.block.MachineRenderingHandler;
 import mekanism.client.render.entity.RenderBalloon;
@@ -131,7 +132,6 @@ import net.minecraft.item.ItemStack;
 import net.minecraft.tileentity.TileEntity;
 import net.minecraft.world.World;
 import net.minecraftforge.client.MinecraftForgeClient;
-import net.minecraftforge.common.MinecraftForge;
 import net.minecraftforge.common.config.Configuration;
 import cpw.mods.fml.client.FMLClientHandler;
 import cpw.mods.fml.client.registry.ClientRegistry;
@@ -478,10 +478,12 @@ public class ClientProxy extends CommonProxy
 	@Override
 	public void loadUtilities()
 	{
-		super.loadUtilities();
-		
 		FMLCommonHandler.instance().bus().register(new ClientConnectionHandler());
 		FMLCommonHandler.instance().bus().register(new ClientPlayerTracker());
+		FMLCommonHandler.instance().bus().register(new ClientTickHandler());
+		FMLCommonHandler.instance().bus().register(new RenderTickHandler());
+		
+		new MekanismKeyHandler();
 
 		HolidayManager.init();
 	}
diff --git a/src/main/java/mekanism/client/ClientTickHandler.java b/src/main/java/mekanism/client/ClientTickHandler.java
index 6a39e9513..24466fd60 100644
--- a/src/main/java/mekanism/client/ClientTickHandler.java
+++ b/src/main/java/mekanism/client/ClientTickHandler.java
@@ -92,7 +92,7 @@ public class ClientTickHandler
 
 	public void tickStart()
 	{
-		if(!preloadedSounds && MekanismClient.enableSounds && MekanismClient.audioHandler != null)
+		if(!preloadedSounds && MekanismClient.enableSounds && MekanismClient.audioHandler != null && MekanismClient.audioHandler.isSystemLoaded())
 		{
 			new Thread(new Runnable() {
 				@Override
diff --git a/src/main/java/mekanism/client/MekKeyHandler.java b/src/main/java/mekanism/client/MekKeyHandler.java
index c2b06e692..ba56a73b6 100644
--- a/src/main/java/mekanism/client/MekKeyHandler.java
+++ b/src/main/java/mekanism/client/MekKeyHandler.java
@@ -51,22 +51,6 @@ public abstract class MekKeyHandler
 		return keyBindings;
 	}
 
-	@SubscribeEvent
-	public void onTick(ClientTickEvent event)
-	{
-		if(event.side == Side.CLIENT)
-		{
-			if(event.phase == Phase.START)
-			{
-				keyTick(event.type, false);
-			}
-			else if(event.phase == Phase.END)
-			{
-				keyTick(event.type, true);
-			}
-		}
-	}
-
 	public void keyTick(Type type, boolean tickEnd)
 	{
 		for(int i = 0; i < keyBindings.length; i++)
diff --git a/src/main/java/mekanism/client/MekanismKeyHandler.java b/src/main/java/mekanism/client/MekanismKeyHandler.java
index 2b4d451f1..836028ea1 100644
--- a/src/main/java/mekanism/client/MekanismKeyHandler.java
+++ b/src/main/java/mekanism/client/MekanismKeyHandler.java
@@ -4,6 +4,10 @@ import net.minecraft.client.settings.KeyBinding;
 
 import org.lwjgl.input.Keyboard;
 
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
+import cpw.mods.fml.common.gameevent.TickEvent.Phase;
 import cpw.mods.fml.common.gameevent.TickEvent.Type;
 import cpw.mods.fml.relauncher.Side;
 import cpw.mods.fml.relauncher.SideOnly;
@@ -18,6 +22,24 @@ public class MekanismKeyHandler extends MekKeyHandler
 	public MekanismKeyHandler()
 	{
 		super(new KeyBinding[] {modeSwitchKey, voiceKey}, new boolean[] {false, false});
+		
+		FMLCommonHandler.instance().bus().register(this);
+	}
+	
+	@SubscribeEvent
+	public void onTick(ClientTickEvent event)
+	{
+		if(event.side == Side.CLIENT)
+		{
+			if(event.phase == Phase.START)
+			{
+				keyTick(event.type, false);
+			}
+			else if(event.phase == Phase.END)
+			{
+				keyTick(event.type, true);
+			}
+		}
 	}
 
 	@Override
diff --git a/src/main/java/mekanism/client/sound/Sound.java b/src/main/java/mekanism/client/sound/Sound.java
index 607f8d2bd..94389fb89 100644
--- a/src/main/java/mekanism/client/sound/Sound.java
+++ b/src/main/java/mekanism/client/sound/Sound.java
@@ -44,7 +44,7 @@ public abstract class Sound
 			identifier = id;
 			objRef = obj;
 
-			URL url = getClass().getClassLoader().getResource("assets/mekanism/sound/" + sound);
+			URL url = getClass().getClassLoader().getResource("assets/mekanism/sounds/" + sound);
 
 			if(url == null)
 			{
@@ -150,8 +150,7 @@ public abstract class Sound
 			try {
 				float multiplier = getMultiplier();
 				float volume = 0;
-				float masterVolume = MekanismClient.audioHandler.masterVolume;
-
+				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, MekanismClient.baseSoundVolume));
diff --git a/src/main/java/mekanism/client/sound/SoundHandler.java b/src/main/java/mekanism/client/sound/SoundHandler.java
index a335174ec..21f782acc 100644
--- a/src/main/java/mekanism/client/sound/SoundHandler.java
+++ b/src/main/java/mekanism/client/sound/SoundHandler.java
@@ -46,9 +46,6 @@ public class SoundHandler
 	/** All the sound references in the Minecraft game. */
 	public Map<Object, Sound> sounds = Collections.synchronizedMap(new HashMap<Object, Sound>());
 
-	/** The current base volume Minecraft is using. */
-	public float masterVolume = 0;
-
 	public static Minecraft mc = Minecraft.getMinecraft();
 
 	/**
@@ -84,20 +81,6 @@ public class SoundHandler
 
 		Mekanism.logger.info("Preloaded " + listings.size() + " object sounds.");
 
-		/*listings = listFiles(corePath.replace("%20", " ").replace(".jar!", ".jar").replace("file:", ""), "assets/mekanism/sounds/etc");
-
-		for(String s : listings)
-		{
-			if(s.contains("/mekanism/sounds/etc/"))
-			{
-				s = s.split("/mekanism/sounds/etc/")[1];
-			}
-
-			mc.sndManager.addSound("mekanism:etc/" + s);
-		}
-
-		Mekanism.logger.info("Initialized " + listings.size() + " sound effects.");*/
-
 		if(MekanismClient.holidays)
 		{
 			listings = listFiles(corePath.replace("%20", " ").replace(".jar!", ".jar").replace("file:", ""), "assets/mekanism/sounds/holiday");
@@ -223,8 +206,6 @@ public class SoundHandler
 							sound.updateVolume();
 						}
 					}
-
-					masterVolume = FMLClientHandler.instance().getClient().gameSettings.getSoundLevel(SoundCategory.MASTER);
 				}
 				else {
 					for(Sound sound : sounds.values())
@@ -319,19 +300,41 @@ public class SoundHandler
 		}
 
 		String s = getSoundSystem().quickPlay(false, url, soundPath, false, object.xCoord, object.yCoord, object.zCoord, 0, 16F);
-		getSoundSystem().setVolume(s, masterVolume);
+		getSoundSystem().setVolume(s, getMasterVolume());
+	}
+	
+	public float getMasterVolume()
+	{
+		return FMLClientHandler.instance().getClient().gameSettings.getSoundLevel(SoundCategory.MASTER);
 	}
 
 	public static SoundSystem getSoundSystem()
 	{
 		try {
-			SoundManager manager = (SoundManager)MekanismUtils.getPrivateValue(mc.getSoundHandler(), SoundManager.class, ObfuscatedNames.SoundHandler_sndManager);
-			return (SoundSystem)MekanismUtils.getPrivateValue(manager, SoundSystem.class, ObfuscatedNames.SoundManager_sndSystem);
+			return (SoundSystem)MekanismUtils.getPrivateValue(getSoundManager(), SoundManager.class, ObfuscatedNames.SoundManager_sndSystem);
 		} catch(Exception e) {
 			return null;
 		}
 	}
 	
+	public static SoundManager getSoundManager()
+	{
+		try {
+			return (SoundManager)MekanismUtils.getPrivateValue(mc.getSoundHandler(), net.minecraft.client.audio.SoundHandler.class, ObfuscatedNames.SoundHandler_sndManager);
+		} catch(Exception e) {
+			return null;
+		}
+	}
+	
+	public static boolean isSystemLoaded()
+	{
+		try {
+			return (Boolean)MekanismUtils.getPrivateValue(getSoundManager(), net.minecraft.client.audio.SoundManager.class, new String[] {"loaded"});
+		} catch(Exception e) {
+			return false;
+		}
+	}
+	
 	public static void playSound(String sound)
 	{
         mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(sound), 1.0F));
diff --git a/src/main/java/mekanism/common/CommonProxy.java b/src/main/java/mekanism/common/CommonProxy.java
index cecda1e49..ee28d816f 100644
--- a/src/main/java/mekanism/common/CommonProxy.java
+++ b/src/main/java/mekanism/common/CommonProxy.java
@@ -78,6 +78,7 @@ import net.minecraft.inventory.Container;
 import net.minecraft.tileentity.TileEntity;
 import net.minecraft.world.World;
 import net.minecraftforge.common.config.Configuration;
+import cpw.mods.fml.common.FMLCommonHandler;
 import cpw.mods.fml.common.registry.GameRegistry;
 import cpw.mods.fml.relauncher.FMLInjectionData;
 
@@ -238,7 +239,10 @@ public class CommonProxy
 	/**
 	 * Set up and load the utilities this mod uses.
 	 */
-	public void loadUtilities() {}
+	public void loadUtilities() 
+	{
+		FMLCommonHandler.instance().bus().register(new CommonWorldTickHandler());
+	}
 
 	/**
 	 * Set up and load the sound handler.
diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang
index 6b843017b..c927373a4 100644
--- a/src/main/resources/assets/mekanism/lang/en_US.lang
+++ b/src/main/resources/assets/mekanism/lang/en_US.lang
@@ -439,6 +439,7 @@ tooltip.PrecisionSawmill=A machine used to process logs and other !nwood-based i
 tooltip.ChemicalDissolutionChamber=An ultimate machine used to !nchemically dissolve all impurities of an !nore, leaving an unprocessed slurry !nbehind.
 tooltip.ChemicalWasher=An ultimate machine that cleans unprocessed !nslurry and prepares it for crystallization.
 tooltip.ChemicalCrystallizer=An ultimate machine used to crystallize !npurified ore slurry into ore crystals.
+tooltip.SeismicVibrator=A machine that uses seismic vibrations to !nprovide information on differing layers !of the world.
 
 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.