diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 593b7237c..fe45447c6 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -97,6 +97,9 @@ opencomputers { # range of [0, 127], where 0 means mute (the sound will not even be # generated), and 127 means maximum amplitude / volume. beepVolume: 32 + + # The radius in which computer beeps can be heard. + beepRadius: 16 } # Computer related settings, concerns server performance and security. diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index fbb310f49..f957f9a55 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -37,6 +37,7 @@ class Settings(val config: Config) { val fontRenderer = config.getString("client.fontRenderer") val beepSampleRate = config.getInt("client.beepSampleRate") val beepAmplitude = config.getInt("client.beepVolume") max 0 min Byte.MaxValue + val beepRadius = config.getDouble("client.beepRadius").toFloat max 1 min 32 // ----------------------------------------------------------------------- // // computer diff --git a/src/main/scala/li/cil/oc/server/PacketSender.scala b/src/main/scala/li/cil/oc/server/PacketSender.scala index 3347c0b2d..7847db5e3 100644 --- a/src/main/scala/li/cil/oc/server/PacketSender.scala +++ b/src/main/scala/li/cil/oc/server/PacketSender.scala @@ -593,7 +593,7 @@ object PacketSender { pb.writeShort(frequency.toShort) pb.writeShort(duration.toShort) - pb.sendToNearbyPlayers(world, x, y, z, Option(16)) + pb.sendToNearbyPlayers(world, x, y, z, Option(32)) } def sendSound(world: World, x: Double, y: Double, z: Double, pattern: String) { @@ -606,7 +606,7 @@ object PacketSender { pb.writeInt(blockPos.z) pb.writeUTF(pattern) - pb.sendToNearbyPlayers(world, x, y, z, Option(16)) + pb.sendToNearbyPlayers(world, x, y, z, Option(32)) } def sendWaypointLabel(t: Waypoint): Unit = { diff --git a/src/main/scala/li/cil/oc/util/Audio.scala b/src/main/scala/li/cil/oc/util/Audio.scala index 517be611e..96548701c 100644 --- a/src/main/scala/li/cil/oc/util/Audio.scala +++ b/src/main/scala/li/cil/oc/util/Audio.scala @@ -30,6 +30,8 @@ object Audio { private def amplitude = Settings.get.beepAmplitude + private def maxDistance = Settings.get.beepRadius + private val sources = mutable.Set.empty[Source] private def volume = Minecraft.getMinecraft.gameSettings.getSoundLevel(SoundCategory.BLOCKS) @@ -42,7 +44,7 @@ object Audio { def play(x: Float, y: Float, z: Float, pattern: String, frequencyInHz: Int = 1000, durationInMilliseconds: Int = 200): Unit = { val mc = Minecraft.getMinecraft - val distanceBasedGain = math.max(0, 1 - mc.thePlayer.getDistance(x, y, z) / 12).toFloat + val distanceBasedGain = math.max(0, 1 - mc.thePlayer.getDistance(x, y, z) / maxDistance).toFloat val gain = distanceBasedGain * volume if (gain <= 0 || amplitude <= 0) return @@ -142,6 +144,8 @@ object Audio { checkALError() AL10.alSource3f(source, AL10.AL_POSITION, x, y, z) + AL10.alSourcef(source, AL10.AL_REFERENCE_DISTANCE, maxDistance) + AL10.alSourcef(source, AL10.AL_MAX_DISTANCE, maxDistance) AL10.alSourcef(source, AL10.AL_GAIN, gain * 0.3f) checkALError()