Fix Y offseting being incorrect for self teleportation packets, remove ugly hack in Entity.Physics and fixes #78.

This commit is contained in:
UnknownShadow200 2015-09-20 07:18:41 +10:00
parent 60b87b7a6f
commit 12da9e5d7a
2 changed files with 22 additions and 25 deletions

View File

@ -742,6 +742,7 @@ namespace ClassicalSharp {
void ReadAbsoluteLocation( byte playerId, bool interpolate ) { void ReadAbsoluteLocation( byte playerId, bool interpolate ) {
float x = reader.ReadInt16() / 32f; float x = reader.ReadInt16() / 32f;
float y = ( reader.ReadInt16() - 51 ) / 32f; // We have to do this. float y = ( reader.ReadInt16() - 51 ) / 32f; // We have to do this.
if( playerId == 255 ) y += 22/32f;
float z = reader.ReadInt16() / 32f; float z = reader.ReadInt16() / 32f;
float yaw = (float)Utils.PackedToDegrees( reader.ReadUInt8() ); float yaw = (float)Utils.PackedToDegrees( reader.ReadUInt8() );
float pitch = (float)Utils.PackedToDegrees( reader.ReadUInt8() ); float pitch = (float)Utils.PackedToDegrees( reader.ReadUInt8() );

View File

@ -120,37 +120,33 @@ namespace ClassicalSharp {
if( tx > 1 || ty > 1 || tz > 1 ) if( tx > 1 || ty > 1 || tz > 1 )
Utils.LogWarning( "t > 1 in physics calculation.. this shouldn't have happened." ); Utils.LogWarning( "t > 1 in physics calculation.. this shouldn't have happened." );
BoundingBox finalBB = entityBB.Offset( Velocity * new Vector3( tx, ty, tz ) ); BoundingBox finalBB = entityBB.Offset( Velocity * new Vector3( tx, ty, tz ) );
float pushUpOffset = (blockBB.Max.Y - blockBB.Min.Y) * 0.25f;
// Find which axis we collide with. if( finalBB.Min.Y >= blockBB.Max.Y ) {
if( finalBB.Min.Y >= blockBB.Min.Y + pushUpOffset ) {
Position.Y = blockBB.Max.Y + Adjustment; Position.Y = blockBB.Max.Y + Adjustment;
onGround = true; onGround = true;
ClipY( ref size, ref entityBB, ref entityExtentBB ); ClipY( ref size, ref entityBB, ref entityExtentBB );
} else if( finalBB.Max.Y <= blockBB.Min.Y ) { } else if( finalBB.Max.Y <= blockBB.Min.Y ) {
Position.Y = blockBB.Min.Y - size.Y - Adjustment; Position.Y = blockBB.Min.Y - size.Y - Adjustment;
ClipY( ref size, ref entityBB, ref entityExtentBB ); ClipY( ref size, ref entityBB, ref entityExtentBB );
} else { } else if( finalBB.Min.X >= blockBB.Max.X ) {
if( finalBB.Min.X >= blockBB.Max.X ) { if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) {
if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { Position.X = blockBB.Max.X + size.X / 2 + Adjustment;
Position.X = blockBB.Max.X + size.X / 2 + Adjustment; ClipX( ref size, ref entityBB, ref entityExtentBB );
ClipX( ref size, ref entityBB, ref entityExtentBB ); }
} } else if( finalBB.Max.X <= blockBB.Min.X ) {
} else if( finalBB.Max.X <= blockBB.Min.X ) { if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) {
if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { Position.X = blockBB.Min.X - size.X / 2 - Adjustment;
Position.X = blockBB.Min.X - size.X / 2 - Adjustment; ClipX( ref size, ref entityBB, ref entityExtentBB );
ClipX( ref size, ref entityBB, ref entityExtentBB ); }
} } else if( finalBB.Min.Z >= blockBB.Max.Z ) {
} else if( finalBB.Min.Z >= blockBB.Max.Z ) { if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) {
if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { Position.Z = blockBB.Max.Z + size.Z / 2 + Adjustment;
Position.Z = blockBB.Max.Z + size.Z / 2 + Adjustment; ClipZ( ref size, ref entityBB, ref entityExtentBB );
ClipZ( ref size, ref entityBB, ref entityExtentBB ); }
} } else if( finalBB.Max.Z <= blockBB.Min.Z ) {
} else if( finalBB.Max.Z <= blockBB.Min.Z ) { if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) {
if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { Position.Z = blockBB.Min.Z - size.Z / 2 - Adjustment;
Position.Z = blockBB.Min.Z - size.Z / 2 - Adjustment; ClipZ( ref size, ref entityBB, ref entityExtentBB );
ClipZ( ref size, ref entityBB, ref entityExtentBB );
}
} }
} }
} }
@ -162,7 +158,7 @@ namespace ClassicalSharp {
if( yDist > 0 && yDist <= StepSize + 0.01f ) { if( yDist > 0 && yDist <= StepSize + 0.01f ) {
// Adjust entity bounding box to include the block being tested // Adjust entity bounding box to include the block being tested
BoundingBox adjFinalBB = finalBB; BoundingBox adjFinalBB = finalBB;
adjFinalBB.Min.X = Math.Min( finalBB.Min.X, blockBB.Min.X + Adjustment ); adjFinalBB.Min.X = Math.Min( finalBB.Min.X, blockBB.Min.X + Adjustment );
adjFinalBB.Max.X = Math.Max( finalBB.Max.X, blockBB.Max.X - Adjustment ); adjFinalBB.Max.X = Math.Max( finalBB.Max.X, blockBB.Max.X - Adjustment );
adjFinalBB.Min.Y = (float)Math.Ceiling( blockBB.Max.Y ) + Adjustment; adjFinalBB.Min.Y = (float)Math.Ceiling( blockBB.Max.Y ) + Adjustment;