Allow changing radius in which beeps can be heard in config (up to 32), closes #1180.

This commit is contained in:
Florian Nücke 2015-05-28 12:11:41 +02:00
parent 5977b92a06
commit cf83f5d82b
4 changed files with 11 additions and 3 deletions

View File

@ -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.

View File

@ -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

View File

@ -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 = {

View File

@ -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()