Fix skating effect with liquids.

This commit is contained in:
UnknownShadow200 2015-10-11 09:13:46 +11:00
parent 00945a6095
commit eb73f460ab
4 changed files with 44 additions and 28 deletions

View File

@ -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<byte> condition ) {
BoundingBox bounds = CollisionBounds;
return TouchesAny( CollisionBounds, condition );
}
public bool TouchesAny( BoundingBox bounds, Predicate<byte> 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 );
}
}
}

View File

@ -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() ) {

View File

@ -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 );

View File

@ -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 ) {