mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-30 21:23:00 +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:
		| @@ -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 ) | ||||||
|   | |||||||
| @@ -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 | ||||||
|                 ); |                 ); | ||||||
|             } |             } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates