From eb73f460ab99896217d7b5e694c19e6c5b3d16e2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 11 Oct 2015 09:13:46 +1100 Subject: [PATCH] Fix skating effect with liquids. --- ClassicalSharp/Entities/Entity.cs | 37 +++++++++++++------------- ClassicalSharp/Entities/LocalPlayer.cs | 13 ++++++++- ClassicalSharp/Entities/Player.cs | 3 +-- ClassicalSharp/Map/Map.cs | 19 ++++++++----- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/ClassicalSharp/Entities/Entity.cs b/ClassicalSharp/Entities/Entity.cs index 58e0b22e9..11621bcfa 100644 --- a/ClassicalSharp/Entities/Entity.cs +++ b/ClassicalSharp/Entities/Entity.cs @@ -51,24 +51,11 @@ namespace ClassicalSharp { public abstract void Render( double deltaTime, float t ); - public bool TouchesAnyLava() { - return TouchesAny( b => b == (byte)Block.Lava || b == (byte)Block.StillLava ); - } - - public bool TouchesAnyRope() { - return TouchesAny( b => b == (byte)Block.Rope ); - } - - public bool TouchesAnyWater() { - return TouchesAny( b => b == (byte)Block.Water || b == (byte)Block.StillWater ); - } - - public bool TouchesAnyOf( byte blockType ) { - return TouchesAny( b => b == blockType ); - } - public bool TouchesAny( Predicate condition ) { - BoundingBox bounds = CollisionBounds; + return TouchesAny( CollisionBounds, condition ); + } + + public bool TouchesAny( BoundingBox bounds, Predicate condition ) { Vector3I bbMin = Vector3I.Floor( bounds.Min ); Vector3I bbMax = Vector3I.Floor( bounds.Max ); @@ -90,6 +77,20 @@ namespace ClassicalSharp { return false; } - public const float Adjustment = 0.001f; + public const float Adjustment = 0.001f; + protected bool TouchesAnyLava() { + return TouchesAny( CollisionBounds, + b => b == (byte)Block.Lava || b == (byte)Block.StillLava ); + } + + protected bool TouchesAnyRope() { + return TouchesAny( CollisionBounds, + b => b == (byte)Block.Rope ); + } + + protected bool TouchesAnyWater() { + return TouchesAny( CollisionBounds, + b => b == (byte)Block.Water || b == (byte)Block.StillWater ); + } } } \ No newline at end of file diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index bbf795440..9bc745de4 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -123,8 +123,19 @@ namespace ClassicalSharp { } if( jumping ) { + Vector3I p = Vector3I.Floor( Position ); + if( TouchesAnyWater() || TouchesAnyLava() ) { - Velocity.Y += speeding ? 0.08f : 0.04f; + BoundingBox bounds = CollisionBounds; + bounds.Min.Y += 1; + + bool isAir = !TouchesAny( bounds, + b => info.CollideType[b] != BlockCollideType.WalkThrough ); + bool pastJumpPoint = Position.Y % 1 >= 0.4; + if( !isAir || !pastJumpPoint ) + Velocity.Y += speeding ? 0.08f : 0.04f; + else if( (collideX || collideZ) && isAir && pastJumpPoint ) + Velocity.Y += 0.10f; } else if( useLiquidGravity ) { Velocity.Y += speeding ? 0.08f : 0.04f; } else if( TouchesAnyRope() ) { diff --git a/ClassicalSharp/Entities/Player.cs b/ClassicalSharp/Entities/Player.cs index 1d21e285b..f6015aabb 100644 --- a/ClassicalSharp/Entities/Player.cs +++ b/ClassicalSharp/Entities/Player.cs @@ -33,8 +33,7 @@ namespace ClassicalSharp { } protected Block GetBlock( Vector3 coords ) { - Vector3I p = Vector3I.Floor( coords ); - return (Block)game.Map.SafeGetBlock( p.X, p.Y, p.Z ); + return (Block)game.Map.SafeGetBlock( Vector3I.Floor( coords ) ); } public abstract void Tick( double delta ); diff --git a/ClassicalSharp/Map/Map.cs b/ClassicalSharp/Map/Map.cs index ead877ab3..11430920b 100644 --- a/ClassicalSharp/Map/Map.cs +++ b/ClassicalSharp/Map/Map.cs @@ -195,16 +195,21 @@ namespace ClassicalSharp { } public byte GetBlock( int x, int y, int z ) { - return mapData[( y * Length + z ) * Width + x]; - } - - public byte SafeGetBlock( int x, int y, int z ) { - return IsValidPos( x, y, z ) ? mapData[( y * Length + z ) * Width + x] - : (byte)0; + return mapData[(y * Length + z) * Width + x]; } public byte GetBlock( Vector3I p ) { - return mapData[( p.Y * Length + p.Z ) * Width + p.X]; + return mapData[(p.Y * Length + p.Z) * Width + p.X]; + } + + public byte SafeGetBlock( int x, int y, int z ) { + return IsValidPos( x, y, z ) ? + mapData[(y * Length + z) * Width + x] : (byte)0; + } + + public byte SafeGetBlock( Vector3I p ) { + return IsValidPos( p.X, p.Y, p.Z ) ? + mapData[(p.Y * Length + p.Z) * Width + p.X] : (byte)0; } public bool IsValidPos( int x, int y, int z ) {