From cbe7b2c840a1c0cf41e1d507e80b585c554ed8c2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 15 Dec 2015 13:49:15 +1100 Subject: [PATCH] Fix picking up 'walk through' speed modifiers from blocks below you, even though you should only pick up from those intersecting you. --- ClassicalSharp/Entities/LocalPlayer.cs | 43 +++++++++++++++----------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index 2d086b1d2..f2989efb3 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -11,21 +11,21 @@ namespace ClassicalSharp { /// Position the player's position is set to when the 'respawn' key binding is pressed. public Vector3 SpawnPoint; - /// The distance (in blocks) that players are allowed to + /// The distance (in blocks) that players are allowed to /// reach to and interact/modify blocks in. public float ReachDistance = 5f; - /// The speed that the player move at, relative to normal speed, + /// The speed that the player move at, relative to normal speed, /// when the 'speeding' key binding is held down. public float SpeedMultiplier = 10; public byte UserType; - /// Whether blocks that the player places that intersect themselves + /// Whether blocks that the player places that intersect themselves /// should cause the player to be pushed back in the opposite direction of the placed block. public bool PushbackPlacing; - /// Whether the player has allowed hacks usage as an option. + /// Whether the player has allowed hacks usage as an option. /// Note that all 'can use X' set by the server override this. public bool HacksEnabled = true; @@ -406,24 +406,31 @@ namespace ClassicalSharp { float LowestSpeedModifier() { BoundingBox bounds = CollisionBounds; - bounds.Min.Y -= 0.1f; // block standing on + useLiquidGravity = false; + float baseModifier = HighestModifier( bounds, false ); + bounds.Min.Y -= 0.1f; // also check block standing on + float solidModifier = HighestModifier( bounds, true ); + return Math.Max( baseModifier, solidModifier ); + } + + float HighestModifier( BoundingBox bounds, bool checkSolid ) { Vector3I bbMin = Vector3I.Floor( bounds.Min ); Vector3I bbMax = Vector3I.Floor( bounds.Max ); float modifier = float.PositiveInfinity; - useLiquidGravity = false; - for( int x = bbMin.X; x <= bbMax.X; x++ ) { - for( int y = bbMin.Y; y <= bbMax.Y; y++ ) { - for( int z = bbMin.Z; z <= bbMax.Z; z++ ) { - byte block = game.Map.SafeGetBlock( x, y, z ); - if( block == 0 ) continue; - - modifier = Math.Min( modifier, info.SpeedMultiplier[block] ); - if( block >= BlockInfo.CpeBlocksCount && - info.CollideType[block] == BlockCollideType.SwimThrough ) - useLiquidGravity = true; - } - } + for( int y = bbMin.Y; y <= bbMax.Y; y++ ) + for( int z = bbMin.Z; z <= bbMax.Z; z++ ) + for( int x = bbMin.X; x <= bbMax.X; x++ ) + { + byte block = game.Map.SafeGetBlock( x, y, z ); + if( block == 0 ) continue; + BlockCollideType type = info.CollideType[block]; + if( type == BlockCollideType.Solid && !checkSolid ) + continue; + + modifier = Math.Min( modifier, info.SpeedMultiplier[block] ); + if( block >= BlockInfo.CpeBlocksCount && type == BlockCollideType.SwimThrough ) + useLiquidGravity = true; } return modifier == float.PositiveInfinity ? 1 : modifier; }