From d2fa018b17560ba318323e47b9b3e0c8ad95fd4a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 8 Jan 2019 20:23:27 +1100 Subject: [PATCH] Fix launcher crash when completely missing resume info, port respawn changes by goodly to C client --- ClassicalSharp/Entities/LocalPlayer.cs | 36 +++++++++++++------------- src/Entity.c | 27 ++++++++++++++----- src/LScreens.c | 10 +++---- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index 4ceb1bb96..ceca8ac2f 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -179,21 +179,20 @@ namespace ClassicalSharp.Entities { Vector3I P = Vector3I.Floor(spawn); AABB bb; - // Spawn player at highest valid position - if (Hacks.CanNoclip) { - if (game.World.IsValidPos(P)) { - bb = AABB.Make(spawn, Size); - for (int y = P.Y; y <= game.World.Height; y++) { - float spawnY = Respawn.HighestFreeY(game, ref bb); - if (spawnY == float.NegativeInfinity) { - BlockID block = game.World.GetPhysicsBlock(P.X, y, P.Z); - float height = BlockInfo.Collide[block] == CollideType.Solid ? BlockInfo.MaxBB[block].Y : 0; - spawn.Y = y + height + Entity.Adjustment; - break; - } - bb.Min.Y += 1; bb.Max.Y += 1; - } - } + // Spawn player at highest solid position to match vanilla Minecraft classic + // Only when player can noclip, since this can let you 'clip' to above solid blocks + if (Hacks.CanNoclip && game.World.IsValidPos(P)) { + bb = AABB.Make(spawn, Size); + for (int y = P.Y; y <= game.World.Height; y++) { + float spawnY = Respawn.HighestFreeY(game, ref bb); + if (spawnY == float.NegativeInfinity) { + BlockID block = game.World.GetPhysicsBlock(P.X, y, P.Z); + float height = BlockInfo.Collide[block] == CollideType.Solid ? BlockInfo.MaxBB[block].Y : 0; + spawn.Y = y + height + Entity.Adjustment; + break; + } + bb.Min.Y += 1; bb.Max.Y += 1; + } } spawn.Y += 2/16f; @@ -224,15 +223,16 @@ namespace ClassicalSharp.Entities { game.Chat.Add("&cCannot set spawn midair when noclip is disabled"); return false; } + + // Spawn is normally centered to match vanilla Minecraft classic if (!Hacks.CanNoclip) { - Spawn.X = Position.X; - Spawn.Y = Position.Y; - Spawn.Z = Position.Z; + Spawn = Position; } else { Spawn.X = Utils.Floor(Position.X) + 0.5f; Spawn.Y = Position.Y; Spawn.Z = Utils.Floor(Position.Z) + 0.5f; } + SpawnRotY = RotY; SpawnHeadX = HeadX; } diff --git a/src/Entity.c b/src/Entity.c index a68deeb2a..297b0de68 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -958,8 +958,9 @@ static void LocalPlayer_DoRespawn(void) { if (!World_Blocks) return; Vector3I_Floor(&pos, &spawn); - /* Spawn player at highest valid position */ - if (World_IsValidPos_3I(pos)) { + /* Spawn player at highest solid position to match vanilla Minecraft classic */ + /* Only when player can noclip, since this can let you 'clip' to above solid blocks */ + if (p->Hacks.CanNoclip && World_IsValidPos_3I(pos)) { AABB_Make(&bb, &spawn, &p->Base.Size); for (y = pos.Y; y <= World_Height; y++) { spawnY = Respawn_HighestSolidY(&bb); @@ -1000,11 +1001,23 @@ static bool LocalPlayer_HandleRespawn(void) { static bool LocalPlayer_HandleSetSpawn(void) { struct LocalPlayer* p = &LocalPlayer_Instance; if (p->Hacks.CanRespawn) { - p->Spawn.X = Math_Floor(p->Base.Position.X) + 0.5f; - p->Spawn.Y = p->Base.Position.Y; - p->Spawn.Z = Math_Floor(p->Base.Position.Z) + 0.5f; - p->SpawnRotY = p->Base.RotY; - p->SpawnHeadX = p->Base.HeadX; + + if (!p->Hacks.CanNoclip && !p->Base.OnGround) { + Chat_AddRaw("&cCannot set spawn midair when noclip is disabled"); + return false; + } + + /* Spawn is normally centered to match vanilla Minecraft classic */ + if (!p->Hacks.CanNoclip) { + p->Spawn = p->Base.Position; + } else { + p->Spawn.X = Math_Floor(p->Base.Position.X) + 0.5f; + p->Spawn.Y = p->Base.Position.Y; + p->Spawn.Z = Math_Floor(p->Base.Position.Z) + 0.5f; + } + + p->SpawnRotY = p->Base.RotY; + p->SpawnHeadX = p->Base.HeadX; } return LocalPlayer_HandleRespawn(); } diff --git a/src/LScreens.c b/src/LScreens.c index e233b32f3..232ab8626 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -665,14 +665,14 @@ struct ResumeInfo { CC_NOINLINE static void MainScreen_GetResume(struct ResumeInfo* info, bool full) { String_InitArray(info->Server, info->_serverBuffer); - Options_Get("launcher-server", &info->Server, NULL); + Options_Get("launcher-server", &info->Server, ""); String_InitArray(info->User, info->_userBuffer); - Options_Get("launcher-username", &info->User, NULL); + Options_Get("launcher-username", &info->User, ""); String_InitArray(info->Ip, info->_ipBuffer); - Options_Get("launcher-ip", &info->Ip, NULL); + Options_Get("launcher-ip", &info->Ip, ""); String_InitArray(info->Port, info->_portBuffer); - Options_Get("launcher-port", &info->Port, NULL); + Options_Get("launcher-port", &info->Port, ""); if (!full) return; String_InitArray(info->Mppass, info->_mppassBuffer); @@ -683,7 +683,7 @@ CC_NOINLINE static void MainScreen_GetResume(struct ResumeInfo* info, bool full) info->Ip.length && info->Port.length; } -CC_NOINLINE void MainScreen_Error(struct LWebTask* task, const char* action) { +CC_NOINLINE static void MainScreen_Error(struct LWebTask* task, const char* action) { String str; char strBuffer[STRING_SIZE]; struct MainScreen* s = &MainScreen_Instance;