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,18 +120,15 @@ 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 );
@ -154,7 +151,6 @@ namespace ClassicalSharp {
} }
} }
} }
}
bool DidSlide( ref BoundingBox blockBB, ref Vector3 size, ref BoundingBox finalBB, bool DidSlide( ref BoundingBox blockBB, ref Vector3 size, ref BoundingBox finalBB,
ref BoundingBox entityBB, ref BoundingBox entityExtentBB ) { ref BoundingBox entityBB, ref BoundingBox entityExtentBB ) {