From 12da9e5d7a07cdd265f8354e2ca9d091f59a22f6 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 20 Sep 2015 07:18:41 +1000 Subject: [PATCH] Fix Y offseting being incorrect for self teleportation packets, remove ugly hack in Entity.Physics and fixes #78. --- ClassicalSharp/Network/NetworkProcessor.cs | 1 + ClassicalSharp/Physics/Entity.Physics.cs | 46 ++++++++++------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/ClassicalSharp/Network/NetworkProcessor.cs b/ClassicalSharp/Network/NetworkProcessor.cs index 5c3b1a3c9..f7e032716 100644 --- a/ClassicalSharp/Network/NetworkProcessor.cs +++ b/ClassicalSharp/Network/NetworkProcessor.cs @@ -742,6 +742,7 @@ namespace ClassicalSharp { void ReadAbsoluteLocation( byte playerId, bool interpolate ) { float x = reader.ReadInt16() / 32f; float y = ( reader.ReadInt16() - 51 ) / 32f; // We have to do this. + if( playerId == 255 ) y += 22/32f; float z = reader.ReadInt16() / 32f; float yaw = (float)Utils.PackedToDegrees( reader.ReadUInt8() ); float pitch = (float)Utils.PackedToDegrees( reader.ReadUInt8() ); diff --git a/ClassicalSharp/Physics/Entity.Physics.cs b/ClassicalSharp/Physics/Entity.Physics.cs index 35a64e529..908b6e1c6 100644 --- a/ClassicalSharp/Physics/Entity.Physics.cs +++ b/ClassicalSharp/Physics/Entity.Physics.cs @@ -120,37 +120,33 @@ namespace ClassicalSharp { if( tx > 1 || ty > 1 || tz > 1 ) Utils.LogWarning( "t > 1 in physics calculation.. this shouldn't have happened." ); 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.Min.Y + pushUpOffset ) { + if( finalBB.Min.Y >= blockBB.Max.Y ) { Position.Y = blockBB.Max.Y + Adjustment; onGround = true; ClipY( ref size, ref entityBB, ref entityExtentBB ); } else if( finalBB.Max.Y <= blockBB.Min.Y ) { Position.Y = blockBB.Min.Y - size.Y - Adjustment; ClipY( ref size, ref entityBB, ref entityExtentBB ); - } else { - if( finalBB.Min.X >= blockBB.Max.X ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { - Position.X = blockBB.Max.X + size.X / 2 + Adjustment; - ClipX( ref size, ref entityBB, ref entityExtentBB ); - } - } else if( finalBB.Max.X <= blockBB.Min.X ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { - Position.X = blockBB.Min.X - size.X / 2 - Adjustment; - ClipX( ref size, ref entityBB, ref entityExtentBB ); - } - } else if( finalBB.Min.Z >= blockBB.Max.Z ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { - Position.Z = blockBB.Max.Z + size.Z / 2 + Adjustment; - ClipZ( ref size, ref entityBB, ref entityExtentBB ); - } - } else if( finalBB.Max.Z <= blockBB.Min.Z ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { - Position.Z = blockBB.Min.Z - size.Z / 2 - Adjustment; - ClipZ( ref size, ref entityBB, ref entityExtentBB ); - } + } else if( finalBB.Min.X >= blockBB.Max.X ) { + if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + Position.X = blockBB.Max.X + size.X / 2 + Adjustment; + ClipX( ref size, ref entityBB, ref entityExtentBB ); + } + } else if( finalBB.Max.X <= blockBB.Min.X ) { + if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + Position.X = blockBB.Min.X - size.X / 2 - Adjustment; + ClipX( ref size, ref entityBB, ref entityExtentBB ); + } + } else if( finalBB.Min.Z >= blockBB.Max.Z ) { + if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + Position.Z = blockBB.Max.Z + size.Z / 2 + Adjustment; + ClipZ( ref size, ref entityBB, ref entityExtentBB ); + } + } else if( finalBB.Max.Z <= blockBB.Min.Z ) { + if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + Position.Z = blockBB.Min.Z - size.Z / 2 - Adjustment; + ClipZ( ref size, ref entityBB, ref entityExtentBB ); } } } @@ -162,7 +158,7 @@ namespace ClassicalSharp { if( yDist > 0 && yDist <= StepSize + 0.01f ) { // 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.Max.X = Math.Max( finalBB.Max.X, blockBB.Max.X - Adjustment ); adjFinalBB.Min.Y = (float)Math.Ceiling( blockBB.Max.Y ) + Adjustment;