1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-29 23:40:46 +00:00

Several fixes to speaker volume

- Use linear attenuation.
 - Fix speakers being 16 times as loud as they should be. They correctly
   cut off at the right distance, but didn't fade out as one might
   expect.
 - Clamp volume at 0, not 1. Fixes #892
This commit is contained in:
Jonathan Coates 2021-08-12 18:17:12 +01:00
parent 62172c6049
commit fa78818069
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 5 additions and 3 deletions

View File

@ -61,6 +61,7 @@ public class SoundManager
setPosition( position ); setPosition( position );
this.volume = volume; this.volume = volume;
this.pitch = pitch; this.pitch = pitch;
attenuation = ISound.AttenuationType.LINEAR;
} }
void setPosition( Vector3d position ) void setPosition( Vector3d position )

View File

@ -176,7 +176,8 @@ public abstract class SpeakerPeripheral implements IPeripheral
World world = getWorld(); World world = getWorld();
Vector3d pos = getPosition(); Vector3d pos = getPosition();
float range = MathHelper.clamp( volume, 1.0f, 3.0f ) * 16; float actualVolume = MathHelper.clamp( volume, 0.0f, 3.0f );
float range = actualVolume * 16;
context.issueMainThreadTask( () -> { context.issueMainThreadTask( () -> {
MinecraftServer server = world.getServer(); MinecraftServer server = world.getServer();
@ -186,13 +187,13 @@ public abstract class SpeakerPeripheral implements IPeripheral
{ {
server.getPlayerList().broadcast( server.getPlayerList().broadcast(
null, pos.x, pos.y, pos.z, range, world.dimension(), null, pos.x, pos.y, pos.z, range, world.dimension(),
new SPlaySoundPacket( name, SoundCategory.RECORDS, pos, range, pitch ) new SPlaySoundPacket( name, SoundCategory.RECORDS, pos, actualVolume, pitch )
); );
} }
else else
{ {
NetworkHandler.sendToAllAround( NetworkHandler.sendToAllAround(
new SpeakerPlayClientMessage( getSource(), pos, name, range, pitch ), new SpeakerPlayClientMessage( getSource(), pos, name, actualVolume, pitch ),
world, pos, range world, pos, range
); );
} }