From 5fc02e45366c4db8c8e0f8b268d379d3ecac5f1c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 25 Dec 2015 23:34:47 +1100 Subject: [PATCH] Make sounds nicer - there is less of an audible gap between step sounds, also play step sounds when landing from a jump or fly. --- ClassicalSharp/Entities/LocalPlayer.cs | 29 +++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index b6ddda249..8047ae15a 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -102,6 +102,7 @@ namespace ClassicalSharp { lastPos = Position = nextPos; lastYaw = nextYaw; lastPitch = nextPitch; + bool wasOnGround = onGround; HandleInput( ref xMoving, ref zMoving ); UpdateVelocityState( xMoving, zMoving ); @@ -112,18 +113,36 @@ namespace ClassicalSharp { UpdateAnimState( lastPos, nextPos, delta ); CheckSkin(); - Vector3 soundPos = Position; - byte blockUnder = (byte)BlockUnderFeet; - if( blockUnder == 0 ) soundPos = new Vector3( -100000 ); + Vector3 soundPos = nextPos; + bool anyNonAir = false; + SoundType type = GetSoundUnder( ref anyNonAir ); + if( !anyNonAir ) soundPos = new Vector3( -100000 ); float distSq = (lastSoundPos - soundPos).LengthSquared; - if( onGround && distSq > 2 * 2 ) { - SoundType type = game.BlockInfo.StepSounds[blockUnder]; + if( onGround && (distSq > 1.75f * 1.75f || !wasOnGround) ) { game.AudioPlayer.PlayStepSound( type ); lastSoundPos = soundPos; } } + SoundType GetSoundUnder( ref bool anyNonAir ) { + Vector3 pos = new Vector3( nextPos.X, nextPos.Y - 0.01f, nextPos.Z ); + Vector3 size = CollisionSize; + BoundingBox bounds = new BoundingBox( pos - size / 2, pos + size / 2); + bounds.Max.Y = bounds.Min.Y = pos.Y; + + SoundType type = SoundType.None; + bool nonAir = false; + TouchesAny( bounds, b => { + SoundType newType = game.BlockInfo.StepSounds[b]; + if( newType != SoundType.None ) type = newType; + if( b != 0 ) nonAir = true; + return false; + }); + anyNonAir = nonAir; + return type; + } + public override void RenderModel( double deltaTime, float t ) { GetCurrentAnimState( t ); curSwing = Utils.Lerp( swingO, swingN, t );