diff --git a/ClassicalSharp/Entities/Entity.cs b/ClassicalSharp/Entities/Entity.cs index 26a193297..8056dbcbb 100644 --- a/ClassicalSharp/Entities/Entity.cs +++ b/ClassicalSharp/Entities/Entity.cs @@ -73,15 +73,12 @@ namespace ClassicalSharp.Entities { public abstract void RenderName(); public virtual void ContextLost() { } + public virtual void ContextRecreated() { } - public virtual void ContextRecreated() { } - - - /// Gets the position of the player's eye in the world. public Vector3 EyePosition { - get { return new Vector3(Position.X, - Position.Y + Model.GetEyeY(this) * ModelScale.Y, Position.Z); } + get { return new Vector3(Position.X, Position.Y + EyeHeight, Position.Z); } } + public float EyeHeight { get { return Model.GetEyeY(this) * ModelScale.Y; } } public Matrix4 TransformMatrix(Vector3 scale, Vector3 pos) { Matrix4 m = Matrix4.Identity, tmp; diff --git a/ClassicalSharp/MeshBuilder/CuboidDrawer.cs b/ClassicalSharp/MeshBuilder/CuboidDrawer.cs index 80f7ca908..df6af8a69 100644 --- a/ClassicalSharp/MeshBuilder/CuboidDrawer.cs +++ b/ClassicalSharp/MeshBuilder/CuboidDrawer.cs @@ -19,7 +19,6 @@ namespace ClassicalSharp { const float uv2Scale = 15.99f/16f; - /// Draws the left face of the given cuboid region. public void Left(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) { float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize; float u1 = minBB.Z, u2 = (count - 1) + maxBB.Z * uv2Scale; @@ -34,7 +33,6 @@ namespace ClassicalSharp { v.Z = z2 + (count - 1); v.U = u2; vertices[index++] = v; } - /// Draws the right face of the given cuboid region. public void Right(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) { float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize; float u1 = (count - minBB.Z), u2 = (1 - maxBB.Z) * uv2Scale; @@ -49,7 +47,6 @@ namespace ClassicalSharp { v.Z = z1; v.U = u1; vertices[index++] = v; } - /// Draws the front face of the given cuboid region. public void Front(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) { float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize; float u1 = (count - minBB.X), u2 = (1 - maxBB.X) * uv2Scale; @@ -64,7 +61,6 @@ namespace ClassicalSharp { v.X = x2 + (count - 1); v.U = u2; vertices[index++] = v; } - /// Draws the back face of the given cuboid region. public void Back(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) { float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize; float u1 = minBB.X, u2 = (count - 1) + maxBB.X * uv2Scale; @@ -79,7 +75,6 @@ namespace ClassicalSharp { v.X = x2 + (count - 1); v.U = u2; vertices[index++] = v; } - /// Draws the bottom face of the given cuboid region. public void Bottom(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) { float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize; float u1 = minBB.X, u2 = (count - 1) + maxBB.X * uv2Scale; @@ -94,7 +89,6 @@ namespace ClassicalSharp { v.X = x2 + (count - 1); v.U = u2; vertices[index++] = v; } - /// Draws the top face of the given cuboid region. public void Top(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) { float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize; float u1 = minBB.X, u2 = (count - 1) + maxBB.X * uv2Scale; diff --git a/ClassicalSharp/Network/CPESupport.cs b/ClassicalSharp/Network/CPESupport.cs index d6c78df8c..1bc8475b6 100644 --- a/ClassicalSharp/Network/CPESupport.cs +++ b/ClassicalSharp/Network/CPESupport.cs @@ -21,8 +21,6 @@ namespace ClassicalSharp.Network { game.SupportsCPEBlocks = false; } - /// Sets fields / updates network handles based on the server - /// indicating it supports the given CPE extension. public void HandleEntry(string ext, int version, NetworkProcessor net) { ServerExtensionsCount--; diff --git a/ClassicalSharp/Rendering/HeldBlockRenderer.cs b/ClassicalSharp/Rendering/HeldBlockRenderer.cs index 766dbf866..52994aca3 100644 --- a/ClassicalSharp/Rendering/HeldBlockRenderer.cs +++ b/ClassicalSharp/Rendering/HeldBlockRenderer.cs @@ -86,7 +86,7 @@ namespace ClassicalSharp.Renderers { static Vector3 sOffset = new Vector3(0.46f, -0.52f, -0.72f); void SetMatrix() { Player p = game.LocalPlayer; - Vector3 eyePos = p.EyePosition; + Vector3 eyePos = Vector3.Zero; eyePos.Y = p.EyeHeight; Matrix4 m, lookAt; Matrix4.LookAt(eyePos, eyePos - Vector3.UnitZ, Vector3.UnitY, out lookAt); @@ -97,7 +97,8 @@ namespace ClassicalSharp.Renderers { void ResetHeldState() { // Based off details from http://pastebin.com/KFV0HkmD (Thanks goodlyay!) Player p = game.LocalPlayer; - held.Position = p.EyePosition; + Vector3 eyePos = Vector3.Zero; eyePos.Y = p.EyeHeight; + held.Position = eyePos; held.Position.X -= game.Camera.bobbingHor; held.Position.Y -= game.Camera.bobbingVer; diff --git a/ClassicalSharp/Utils/Utils.cs b/ClassicalSharp/Utils/Utils.cs index e3870827d..6f50b99da 100644 --- a/ClassicalSharp/Utils/Utils.cs +++ b/ClassicalSharp/Utils/Utils.cs @@ -29,7 +29,6 @@ namespace ClassicalSharp { public const int StringLength = 64; - /// Returns a string with all the colour codes stripped from it. public static string StripColours(string value) { if (value.IndexOf('&') == -1) return value; char[] output = new char[value.Length]; @@ -81,8 +80,6 @@ namespace ClassicalSharp { } #if !LAUNCHER - /// Attempts to caselessly parse the given string as a Key enum member, - /// returning defValue if there was an error parsing. public static bool TryParseEnum(string value, T defValue, out T result) { T mapping; try { @@ -128,7 +125,6 @@ namespace ClassicalSharp { return SkinType.Invalid; } - /// Returns whether the specified string starts with http:// or https:// public static bool IsUrlPrefix(string value, int index) { int http = value.IndexOf("http://", index); int https = value.IndexOf("https://", index); diff --git a/src/Client/Entity.c b/src/Client/Entity.c index 538945332..9f37728b8 100644 --- a/src/Client/Entity.c +++ b/src/Client/Entity.c @@ -83,9 +83,11 @@ void Entity_Init(Entity* entity) { } Vector3 Entity_GetEyePosition(Entity* entity) { - Vector3 pos = entity->Position; - pos.Y += entity->Model->GetEyeY(entity) * entity->ModelScale.Y; - return pos; + Vector3 pos = entity->Position; pos.Y += Entity_GetEyeHeight(entity); return pos; +} + +Real32 Entity_GetEyeHeight(Entity* entity) { + return entity->Model->GetEyeY(entity) * entity->ModelScale.Y; } void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale) { diff --git a/src/Client/Entity.h b/src/Client/Entity.h index bbcb0d593..278ff2fc5 100644 --- a/src/Client/Entity.h +++ b/src/Client/Entity.h @@ -90,6 +90,7 @@ typedef struct Entity_ { void Entity_Init(Entity* entity); Vector3 Entity_GetEyePosition(Entity* entity); +Real32 Entity_GetEyeHeight(Entity* entity); void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale); void Entity_GetPickingBounds(Entity* entity, AABB* bb); void Entity_GetBounds(Entity* entity, AABB* bb); diff --git a/src/Client/HeldBlockRenderer.c b/src/Client/HeldBlockRenderer.c index 15a4c3cc1..4cd7bb4ca 100644 --- a/src/Client/HeldBlockRenderer.c +++ b/src/Client/HeldBlockRenderer.c @@ -44,8 +44,8 @@ static void HeldBlockRenderer_RenderModel(void) { } static void HeldBlockRenderer_SetMatrix(void) { - Entity* player = &LocalPlayer_Instance.Base; - Vector3 eyePos = Entity_GetEyePosition(player); + Entity* player = &LocalPlayer_Instance.Base; + Vector3 eyePos = VECTOR3_CONST(0.0f, Entity_GetEyeHeight(player), 0.0f); Vector3 up = Vector3_UnitY; Vector3 target = eyePos; target.Z -= 1.0f; /* Look straight down*/ @@ -58,7 +58,8 @@ static void HeldBlockRenderer_SetMatrix(void) { static void HeldBlockRenderer_ResetHeldState(void) { /* Based off details from http://pastebin.com/KFV0HkmD (Thanks goodlyay!) */ Entity* player = &LocalPlayer_Instance.Base; - held_entity.Position = Entity_GetEyePosition(player); + Vector3 eyePos = VECTOR3_CONST(0.0f, Entity_GetEyeHeight(player), 0.0f); + held_entity.Position = eyePos; held_entity.Position.X -= Camera_BobbingHor; held_entity.Position.Y -= Camera_BobbingVer;