mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
Save/Load map generation seed to/from .cw files
This commit is contained in:
parent
431c3e427e
commit
543a991559
@ -623,6 +623,12 @@ static void Cw_Callback_1(struct NbtTag* tag) {
|
|||||||
|
|
||||||
static void Cw_Callback_2(struct NbtTag* tag) {
|
static void Cw_Callback_2(struct NbtTag* tag) {
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
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->parent, "Spawn")) return;
|
||||||
|
|
||||||
if (IsTag(tag, "X")) { p->Spawn.X = NbtTag_I16(tag); 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_WriteDict(cur, "ClassicWorld");
|
||||||
cur = Nbt_WriteUInt8(cur, "FormatVersion", 1);
|
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_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, "Y", World.Height);
|
||||||
cur = Nbt_WriteUInt16(cur, "Z", World.Length);
|
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? */
|
/* TODO: Maybe keep real spawn too? */
|
||||||
cur = Nbt_WriteDict(cur, "Spawn");
|
cur = Nbt_WriteDict(cur, "Spawn");
|
||||||
{
|
{
|
||||||
|
@ -1772,7 +1772,9 @@ static void GeneratingScreen_EndGeneration(void) {
|
|||||||
Gen_Done = false;
|
Gen_Done = false;
|
||||||
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
|
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
|
||||||
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
|
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
|
||||||
|
|
||||||
Gen_Blocks = NULL;
|
Gen_Blocks = NULL;
|
||||||
|
World.Seed = Gen_Seed;
|
||||||
|
|
||||||
x = (World.Width / 2) + 0.5f; z = (World.Length / 2) + 0.5f;
|
x = (World.Width / 2) + 0.5f; z = (World.Length / 2) + 0.5f;
|
||||||
p->Spawn = Respawn_FindSpawnPosition(x, z, p->Base.Size);
|
p->Spawn = Respawn_FindSpawnPosition(x, z, p->Base.Size);
|
||||||
|
@ -50,6 +50,7 @@ void World_Reset(void) {
|
|||||||
World_SetDimensions(0, 0, 0);
|
World_SetDimensions(0, 0, 0);
|
||||||
World.Loaded = false;
|
World.Loaded = false;
|
||||||
World.LastSave = -200;
|
World.LastSave = -200;
|
||||||
|
World.Seed = 0;
|
||||||
Env_Reset();
|
Env_Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ CC_VAR extern struct _WorldData {
|
|||||||
int ChunksX, ChunksY, ChunksZ;
|
int ChunksX, ChunksY, ChunksZ;
|
||||||
/* Number of chunks in the world, or ChunksX * ChunksY * ChunksZ */
|
/* Number of chunks in the world, or ChunksX * ChunksY * ChunksZ */
|
||||||
int ChunksCount;
|
int ChunksCount;
|
||||||
|
/* Seed world was generated with. May be 0 (unknown) */
|
||||||
|
int Seed;
|
||||||
} World;
|
} World;
|
||||||
|
|
||||||
/* Frees the blocks array, sets dimensions to 0, resets environment to default. */
|
/* Frees the blocks array, sets dimensions to 0, resets environment to default. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user