diff --git a/src/main/scala/li/cil/oc/client/Proxy.scala b/src/main/scala/li/cil/oc/client/Proxy.scala index 4949f1e7d..6f3541607 100644 --- a/src/main/scala/li/cil/oc/client/Proxy.scala +++ b/src/main/scala/li/cil/oc/client/Proxy.scala @@ -34,9 +34,7 @@ private[oc] class Proxy extends CommonProxy { api.API.manual = client.Manual - MinecraftForge.EVENT_BUS.register(Sound) MinecraftForge.EVENT_BUS.register(Textures) - MinecraftForge.EVENT_BUS.register(HighlightRenderer) ModelInitialization.preInit() } @@ -73,8 +71,10 @@ private[oc] class Proxy extends CommonProxy { ClientRegistry.registerKeyBinding(KeyBindings.materialCosts) ClientRegistry.registerKeyBinding(KeyBindings.clipboardPaste) + MinecraftForge.EVENT_BUS.register(HighlightRenderer) MinecraftForge.EVENT_BUS.register(PetRenderer) MinecraftForge.EVENT_BUS.register(ServerRack) + MinecraftForge.EVENT_BUS.register(Sound) MinecraftForge.EVENT_BUS.register(TextBuffer) MinecraftForge.EVENT_BUS.register(WirelessNetworkDebugRenderer) @@ -83,6 +83,7 @@ private[oc] class Proxy extends CommonProxy { FMLCommonHandler.instance.bus.register(Audio) FMLCommonHandler.instance.bus.register(HologramRenderer) FMLCommonHandler.instance.bus.register(PetRenderer) + FMLCommonHandler.instance.bus.register(Sound) FMLCommonHandler.instance.bus.register(TextBufferRenderCache) } diff --git a/src/main/scala/li/cil/oc/client/Sound.scala b/src/main/scala/li/cil/oc/client/Sound.scala index 529199f7a..f6b22e9ed 100644 --- a/src/main/scala/li/cil/oc/client/Sound.scala +++ b/src/main/scala/li/cil/oc/client/Sound.scala @@ -40,12 +40,16 @@ object Sound { if (Settings.get.soundVolume > 0) { updateTimer.scheduleAtFixedRate(new TimerTask { override def run() { - updateVolume() - processQueue() + sources.synchronized(updateCallable = Some(() => { + updateVolume() + processQueue() + })) } }, 500, 50) } + private var updateCallable = None: Option[() => Unit] + // Set in init event. var manager: SoundManager = _ @@ -115,26 +119,33 @@ object Sound { @SubscribeEvent def onTick(e: ClientTickEvent) { - if (!hasPreloaded && soundSystem != null) { - hasPreloaded = true - new Thread(new Runnable() { - override def run(): Unit = { - val preloadConfigLocation = new ResourceLocation(Settings.resourceDomain, "sounds/preload.cfg") - val preloadConfigResource = Minecraft.getMinecraft.getResourceManager.getResource(preloadConfigLocation) - for (location <- Source.fromInputStream(preloadConfigResource.getInputStream)(Charsets.UTF_8).getLines()) { - val url = getClass.getClassLoader.getResource(location) - if (url != null) try { - val sourceName = "preload_" + location - soundSystem.newSource(false, sourceName, url, location, true, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, 16) - soundSystem.activate(sourceName) - soundSystem.removeSource(sourceName) - } catch { - case _: Throwable => // Meh. + if (soundSystem != null) { + if (!hasPreloaded) { + hasPreloaded = true + new Thread(new Runnable() { + override def run(): Unit = { + val preloadConfigLocation = new ResourceLocation(Settings.resourceDomain, "sounds/preload.cfg") + val preloadConfigResource = Minecraft.getMinecraft.getResourceManager.getResource(preloadConfigLocation) + for (location <- Source.fromInputStream(preloadConfigResource.getInputStream)(Charsets.UTF_8).getLines()) { + val url = getClass.getClassLoader.getResource(location) + if (url != null) try { + val sourceName = "preload_" + location + soundSystem.newSource(false, sourceName, url, location, true, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, 16) + soundSystem.activate(sourceName) + soundSystem.removeSource(sourceName) + } catch { + case _: Throwable => // Meh. + } + else OpenComputers.log.warn(s"Couldn't preload sound $location!") } - else OpenComputers.log.warn(s"Couldn't preload sound $location!") } - } - }) + }) + } + + sources.synchronized { + updateCallable.foreach(_()) + updateCallable = None + } } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala b/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala index b5ebafb9f..45a489c00 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Microcontroller.scala @@ -132,6 +132,7 @@ class Microcontroller extends traits.PowerAcceptor with traits.Hub with traits.C override protected def connectItemNode(node: Node) { if (machine.node != null && node != null) { + api.Network.joinNewNetwork(machine.node) machine.node.connect(node) } }