diff --git a/src/Formats.c b/src/Formats.c index f3d2b4de8..9e04d3823 100644 --- a/src/Formats.c +++ b/src/Formats.c @@ -623,6 +623,12 @@ static void Cw_Callback_1(struct NbtTag* tag) { static void Cw_Callback_2(struct NbtTag* tag) { struct LocalPlayer* p = &LocalPlayer_Instance; + + if (IsTag(tag->parent, "MapGenerator")) + { + if (IsTag(tag, "Seed")) { World.Seed = NbtTag_I32(tag); return; } + return; + } if (!IsTag(tag->parent, "Spawn")) return; if (IsTag(tag, "X")) { p->Spawn.X = NbtTag_I16(tag); return; } @@ -1410,10 +1416,16 @@ cc_result Cw_Save(struct Stream* stream) { cur = Nbt_WriteDict(cur, "ClassicWorld"); cur = Nbt_WriteUInt8(cur, "FormatVersion", 1); cur = Nbt_WriteArray(cur, "UUID", WORLD_UUID_LEN); Mem_Copy(cur, World.Uuid, WORLD_UUID_LEN); cur += WORLD_UUID_LEN; - cur = Nbt_WriteUInt16(cur, "X", World.Width ); + cur = Nbt_WriteUInt16(cur, "X", World.Width); cur = Nbt_WriteUInt16(cur, "Y", World.Height); cur = Nbt_WriteUInt16(cur, "Z", World.Length); + cur = Nbt_WriteDict(cur, "MapGenerator"); + { + cur = Nbt_WriteInt32(cur, "Seed", World.Seed); + } *cur++ = NBT_END; + + /* TODO: Maybe keep real spawn too? */ cur = Nbt_WriteDict(cur, "Spawn"); { diff --git a/src/Screens.c b/src/Screens.c index 101cbb03b..0319bbd97 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1772,7 +1772,9 @@ static void GeneratingScreen_EndGeneration(void) { Gen_Done = false; World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length); if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; } + Gen_Blocks = NULL; + World.Seed = Gen_Seed; x = (World.Width / 2) + 0.5f; z = (World.Length / 2) + 0.5f; p->Spawn = Respawn_FindSpawnPosition(x, z, p->Base.Size); diff --git a/src/World.c b/src/World.c index 4658857ae..a64a434bf 100644 --- a/src/World.c +++ b/src/World.c @@ -50,6 +50,7 @@ void World_Reset(void) { World_SetDimensions(0, 0, 0); World.Loaded = false; World.LastSave = -200; + World.Seed = 0; Env_Reset(); } diff --git a/src/World.h b/src/World.h index af1a8f027..190ebf3df 100644 --- a/src/World.h +++ b/src/World.h @@ -56,6 +56,8 @@ CC_VAR extern struct _WorldData { int ChunksX, ChunksY, ChunksZ; /* Number of chunks in the world, or ChunksX * ChunksY * ChunksZ */ int ChunksCount; + /* Seed world was generated with. May be 0 (unknown) */ + int Seed; } World; /* Frees the blocks array, sets dimensions to 0, resets environment to default. */