1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-27 15:43:23 +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 @@ protected MoveableSound( SoundEvent sound, Vector3d position, float volume, floa
setPosition( position );
this.volume = volume;
this.pitch = pitch;
attenuation = ISound.AttenuationType.LINEAR;
}
void setPosition( Vector3d position )

View File

@ -176,7 +176,8 @@ private synchronized boolean playSound( ILuaContext context, ResourceLocation na
World world = getWorld();
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( () -> {
MinecraftServer server = world.getServer();
@ -186,13 +187,13 @@ private synchronized boolean playSound( ILuaContext context, ResourceLocation na
{
server.getPlayerList().broadcast(
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
{
NetworkHandler.sendToAllAround(
new SpeakerPlayClientMessage( getSource(), pos, name, range, pitch ),
new SpeakerPlayClientMessage( getSource(), pos, name, actualVolume, pitch ),
world, pos, range
);
}