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 ec5341f33..146977bc2 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 f0d639768..e01552273 100644 --- a/src/main/scala/li/cil/oc/server/PacketSender.scala +++ b/src/main/scala/li/cil/oc/server/PacketSender.scala @@ -586,7 +586,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) { @@ -599,7 +599,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/server/component/Agent.scala b/src/main/scala/li/cil/oc/server/component/Agent.scala index 5c92ef30f..6dd6c5337 100644 --- a/src/main/scala/li/cil/oc/server/component/Agent.scala +++ b/src/main/scala/li/cil/oc/server/component/Agent.scala @@ -70,7 +70,7 @@ trait Agent extends traits.WorldControl with traits.InventoryControl with traits @Callback(doc = "function():string -- Get the name of the agent.") def name(context: Context, args: Arguments): Array[AnyRef] = result(agent.name) - @Callback + @Callback(doc = "function(side:number[, face:number=side[, sneaky:boolean=false]]):boolean, string -- Perform a 'left click' towards the specified side. The `face' allows a more precise click calibration, and is relative to the targeted blockspace.") def swing(context: Context, args: Arguments): Array[AnyRef] = { // Swing the equipped tool (left click). val facing = checkSideForAction(args, 0) @@ -154,7 +154,7 @@ trait Agent extends traits.WorldControl with traits.InventoryControl with traits result(false, reason.orNull) } - @Callback + @Callback(doc = "function(side:number[, face:number=side[, sneaky:boolean=false[, duration:number=0]]]):boolean, string -- Perform a 'right click' towards the specified side. The `face' allows a more precise click calibration, and is relative to the targeted blockspace.") def use(context: Context, args: Arguments): Array[AnyRef] = { val facing = checkSideForAction(args, 0) val sides = @@ -233,7 +233,7 @@ trait Agent extends traits.WorldControl with traits.InventoryControl with traits result(false) } - @Callback + @Callback(doc = "function(side:number[, face:number=side[, sneaky:boolean=false]]):boolean -- Place a block towards the specified side. The `face' allows a more precise click calibration, and is relative to the targeted blockspace.") def place(context: Context, args: Arguments): Array[AnyRef] = { val facing = checkSideForAction(args, 0) val sides = diff --git a/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala b/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala index 46423a470..f01f866d1 100644 --- a/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala +++ b/src/main/scala/li/cil/oc/server/component/traits/InventoryWorldControl.scala @@ -12,7 +12,7 @@ import net.minecraft.item.ItemBlock import net.minecraft.util.EnumFacing trait InventoryWorldControl extends InventoryAware with WorldAware with SideRestricted { - @Callback + @Callback(doc = "function(side:number):boolean -- Compare the block on the specified side with the one in the selected slot. Returns true if equal.") def compare(context: Context, args: Arguments): Array[AnyRef] = { val side = checkSideForAction(args, 0) stackInSlot(selectedSlot) match { @@ -30,7 +30,7 @@ trait InventoryWorldControl extends InventoryAware with WorldAware with SideRest result(false) } - @Callback + @Callback(doc = "function(side:number[, count:number=64]):boolean -- Drops items from the selected slot towards the specified side.") def drop(context: Context, args: Arguments): Array[AnyRef] = { val facing = checkSideForAction(args, 0) val count = args.optionalItemCount(1) @@ -66,7 +66,7 @@ trait InventoryWorldControl extends InventoryAware with WorldAware with SideRest else result(false) } - @Callback + @Callback(doc = "function(side:number[, count:number=64]):boolean -- Suck up items from the specified side.") def suck(context: Context, args: Arguments): Array[AnyRef] = { val facing = checkSideForAction(args, 0) val count = args.optionalItemCount(1) diff --git a/src/main/scala/li/cil/oc/server/component/traits/TankControl.scala b/src/main/scala/li/cil/oc/server/component/traits/TankControl.scala index cb4cc3ba2..a57293d32 100644 --- a/src/main/scala/li/cil/oc/server/component/traits/TankControl.scala +++ b/src/main/scala/li/cil/oc/server/component/traits/TankControl.scala @@ -7,10 +7,10 @@ import li.cil.oc.util.ExtendedArguments._ import li.cil.oc.util.ResultWrapper.result trait TankControl extends TankAware { - @Callback + @Callback(doc = "function():number -- The number of tanks installed in the device.") def tankCount(context: Context, args: Arguments): Array[AnyRef] = result(tank.tankCount) - @Callback + @Callback(doc = "function([index:number]):number -- Select a tank and/or get the number of the currently selected tank.") def selectTank(context: Context, args: Arguments): Array[AnyRef] = { if (args.count > 0 && args.checkAny(0) != null) { selectedTank = args.checkTank(tank, 0) @@ -18,7 +18,7 @@ trait TankControl extends TankAware { result(selectedTank + 1) } - @Callback(direct = true) + @Callback(direct = true, doc = "function([index:number]):number -- Get the fluid amount in the specified or selected tank.") def tankLevel(context: Context, args: Arguments): Array[AnyRef] = { val index = if (args.count > 0 && args.checkAny(0) != null) args.checkTank(tank, 0) @@ -29,7 +29,7 @@ trait TankControl extends TankAware { }) } - @Callback(direct = true) + @Callback(direct = true, doc = "function([index:number]):number -- Get the remaining fluid capacity in the specified or selected tank.") def tankSpace(context: Context, args: Arguments): Array[AnyRef] = { val index = if (args.count > 0 && args.checkAny(0) != null) args.checkTank(tank, 0) @@ -40,7 +40,7 @@ trait TankControl extends TankAware { }) } - @Callback + @Callback(doc = "function(index:number):boolean -- Compares the fluids in the selected and the specified tank. Returns true if equal.") def compareFluidTo(context: Context, args: Arguments): Array[AnyRef] = { val index = args.checkTank(tank, 0) result((fluidInTank(selectedTank), fluidInTank(index)) match { @@ -50,7 +50,7 @@ trait TankControl extends TankAware { }) } - @Callback + @Callback(doc = "function(index:number[, count:number=1000]):boolean -- Move the specified amount of fluid from the selected tank into the specified tank.") def transferFluidTo(context: Context, args: Arguments): Array[AnyRef] = { val index = args.checkTank(tank, 0) val count = args.optionalFluidCount(1) diff --git a/src/main/scala/li/cil/oc/server/component/traits/TankWorldControl.scala b/src/main/scala/li/cil/oc/server/component/traits/TankWorldControl.scala index 5f07e7892..5024723bb 100644 --- a/src/main/scala/li/cil/oc/server/component/traits/TankWorldControl.scala +++ b/src/main/scala/li/cil/oc/server/component/traits/TankWorldControl.scala @@ -14,7 +14,7 @@ import net.minecraftforge.fluids.IFluidBlock import net.minecraftforge.fluids.IFluidHandler trait TankWorldControl extends TankAware with WorldAware with SideRestricted { - @Callback + @Callback(doc = "function(side:number):boolean -- Compare the fluid in the selected tank with the fluid on the specified side. Returns true if equal.") def compareFluid(context: Context, args: Arguments): Array[AnyRef] = { val side = checkSideForAction(args, 0) fluidInTank(selectedTank) match { @@ -33,7 +33,7 @@ trait TankWorldControl extends TankAware with WorldAware with SideRestricted { } } - @Callback + @Callback(doc = "function(side:boolean[, amount:number=1000]):boolean, number or string -- Drains the specified amount of fluid from the specified side. Returns the amount drained, or an error message.") def drain(context: Context, args: Arguments): Array[AnyRef] = { val facing = checkSideForAction(args, 0) val count = args.optionalFluidCount(1) @@ -94,7 +94,7 @@ trait TankWorldControl extends TankAware with WorldAware with SideRestricted { } } - @Callback + @Callback(doc = "function(side:number[, amount:number=1000]):boolean, number of string -- Eject the specified amount of fluid to the specified side. Returns the amount ejected or an error message.") def fill(context: Context, args: Arguments): Array[AnyRef] = { val facing = checkSideForAction(args, 0) val count = args.optionalFluidCount(1) diff --git a/src/main/scala/li/cil/oc/server/component/traits/WorldControl.scala b/src/main/scala/li/cil/oc/server/component/traits/WorldControl.scala index 2e0c657f6..a0076068e 100644 --- a/src/main/scala/li/cil/oc/server/component/traits/WorldControl.scala +++ b/src/main/scala/li/cil/oc/server/component/traits/WorldControl.scala @@ -6,7 +6,7 @@ import li.cil.oc.api.machine.Context import li.cil.oc.util.ResultWrapper.result trait WorldControl extends WorldAware with SideRestricted { - @Callback + @Callback(doc = "function(side:number):boolean, string -- Checks the contents of the block on the specified sides and returns the findings.") def detect(context: Context, args: Arguments): Array[AnyRef] = { val side = checkSideForAction(args, 0) val (something, what) = blockContent(side) diff --git a/src/main/scala/li/cil/oc/util/Audio.scala b/src/main/scala/li/cil/oc/util/Audio.scala index 1a8b645c2..144ecffa8 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()