diff --git a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs index 29b717288..bde947241 100644 --- a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs @@ -31,7 +31,7 @@ namespace ClassicalSharp.Gui { MakeOpt( -1, 0, "Jump height", OnWidgetClick, g => g.LocalPlayer.JumpHeight.ToString( "F3" ), - (g, v) => g.LocalPlayer.physics.CalculateJumpVelocity( Single.Parse( v ) ) ), + (g, v) => g.LocalPlayer.physics.CalculateJumpVelocity( true, Single.Parse( v ) ) ), MakeBool( -1, 50, "Double jump", OptionsKey.DoubleJump, OnWidgetClick, g => g.LocalPlayer.Hacks.DoubleJump, diff --git a/ClassicalSharp/Entities/Components/HacksComponent.cs b/ClassicalSharp/Entities/Components/HacksComponent.cs index 73660d50b..018cb14fb 100644 --- a/ClassicalSharp/Entities/Components/HacksComponent.cs +++ b/ClassicalSharp/Entities/Components/HacksComponent.cs @@ -70,6 +70,8 @@ namespace ClassicalSharp.Entities { /// Whether the player is currently walking at base speed * 0.5 * speed multiplier. public bool HalfSpeeding; + public bool CanJumpHigher { get { return Enabled && CanAnyHacks && CanSpeed; } } + /// Parses hack flags specified in the motd and/or name of the server. /// Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax, and horspeed=xyz public void ParseHackFlags( string name, string motd ) { diff --git a/ClassicalSharp/Entities/Components/PhysicsComponent.cs b/ClassicalSharp/Entities/Components/PhysicsComponent.cs index 77e5b930d..7a2585f17 100644 --- a/ClassicalSharp/Entities/Components/PhysicsComponent.cs +++ b/ClassicalSharp/Entities/Components/PhysicsComponent.cs @@ -13,7 +13,8 @@ namespace ClassicalSharp.Entities { Entity entity; Game game; BlockInfo info; - internal float jumpVel = 0.42f, serverJumpVel = 0.42f; + + internal float jumpVel = 0.42f, userJumpVel = 0.42f, serverJumpVel = 0.42f; internal HacksComponent hacks; internal CollisionsComponent collisions; @@ -233,7 +234,7 @@ namespace ClassicalSharp.Entities { /// Calculates the jump velocity required such that when a client presses /// the jump binding they will be able to jump up to the given height. - internal void CalculateJumpVelocity( float jumpHeight ) { + internal void CalculateJumpVelocity( bool userVel, float jumpHeight ) { jumpVel = 0; if( jumpHeight >= 256 ) jumpVel = 10.0f; if( jumpHeight >= 512 ) jumpVel = 16.5f; @@ -241,6 +242,7 @@ namespace ClassicalSharp.Entities { while( GetMaxHeight( jumpVel ) <= jumpHeight ) jumpVel += 0.001f; + if( userVel ) userJumpVel = jumpVel; } public static double GetMaxHeight( float u ) { diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index faa1e6f47..23c454018 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -106,7 +106,7 @@ namespace ClassicalSharp.Entities { /// Disables any hacks if their respective CanHackX value is set to false. public void CheckHacksConsistency() { Hacks.CheckHacksConsistency(); - if( !Hacks.Enabled || !Hacks.CanAnyHacks || !Hacks.CanSpeed ) + if( !Hacks.CanJumpHigher ) physics.jumpVel = physics.serverJumpVel; } diff --git a/ClassicalSharp/Network/NetworkProcessor.CPE.cs b/ClassicalSharp/Network/NetworkProcessor.CPE.cs index 3e777ecef..4c0f74d2c 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPE.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPE.cs @@ -299,8 +299,10 @@ namespace ClassicalSharp.Network { p.CheckHacksConsistency(); float jumpHeight = reader.ReadInt16() / 32f; - if( jumpHeight < 0 ) p.physics.jumpVel = 0.42f; - else p.physics.CalculateJumpVelocity( jumpHeight ); + if( jumpHeight < 0 ) + p.physics.jumpVel = p.Hacks.CanJumpHigher ? p.physics.userJumpVel : 0.42f; + else + p.physics.CalculateJumpVelocity( false, jumpHeight ); p.physics.serverJumpVel = p.physics.jumpVel; game.Events.RaiseHackPermissionsChanged(); } diff --git a/ClassicalSharp/Rendering/ChunkSorter.cs b/ClassicalSharp/Rendering/ChunkSorter.cs index 61e3891a0..8c00b21ad 100644 --- a/ClassicalSharp/Rendering/ChunkSorter.cs +++ b/ClassicalSharp/Rendering/ChunkSorter.cs @@ -12,26 +12,19 @@ namespace ClassicalSharp.Renderers { Vector3I newChunkPos = Vector3I.Floor( cameraPos ); newChunkPos.X = (newChunkPos.X & ~0x0F) + 8; newChunkPos.Y = (newChunkPos.Y & ~0x0F) + 8; - newChunkPos.Z = (newChunkPos.Z & ~0x0F) + 8; + newChunkPos.Z = (newChunkPos.Z & ~0x0F) + 8; if( newChunkPos == updater.chunkPos ) return; ChunkInfo[] chunks = game.MapRenderer.chunks; - int[] distances = updater.distances; - updater.chunkPos = newChunkPos; - - for( int i = 0; i < distances.Length; i++ ) { - ChunkInfo info = chunks[i]; - distances[i] = Utils.DistanceSquared( info.CentreX, info.CentreY, info.CentreZ, - updater.chunkPos.X, updater.chunkPos.Y, updater.chunkPos.Z ); - } - - // NOTE: Over 5x faster compared to normal comparison of IComparer.Compare - if( distances.Length > 1 ) - QuickSort( distances, chunks, 0, chunks.Length - 1 ); - + int[] distances = updater.distances; Vector3I pPos = newChunkPos; + updater.chunkPos = pPos; + for( int i = 0; i < chunks.Length; i++ ) { ChunkInfo info = chunks[i]; + distances[i] = Utils.DistanceSquared( info.CentreX, info.CentreY, info.CentreZ, + pPos.X, pPos.Y, pPos.Z ); + int dX1 = (info.CentreX - 8) - pPos.X, dX2 = (info.CentreX + 8) - pPos.X; int dY1 = (info.CentreY - 8) - pPos.Y, dY2 = (info.CentreY + 8) - pPos.Y; int dZ1 = (info.CentreZ - 8) - pPos.Z, dZ2 = (info.CentreZ + 8) - pPos.Z; @@ -44,6 +37,10 @@ namespace ClassicalSharp.Renderers { info.DrawBottom = !(dY1 <= 0 && dY2 <= 0); info.DrawTop = !(dY1 >= 0 && dY2 >= 0); } + + // NOTE: Over 5x faster compared to normal comparison of IComparer.Compare + if( distances.Length > 1 ) + QuickSort( distances, chunks, 0, chunks.Length - 1 ); updater.ResetUsedFlags(); //SimpleOcclusionCulling(); }