This commit is contained in:
BruceChen 2022-08-31 19:50:11 +08:00
parent 9089bb4cdb
commit 0a689e407e
3 changed files with 21 additions and 27 deletions

View file

@ -46,7 +46,7 @@ namespace MinecraftClient.Mapping
{
Tuple<int, int> chunkCoord = new(chunkX, chunkZ);
if (value == null)
chunks.Remove(chunkCoord, out _);
chunks.TryRemove(chunkCoord, out _);
else
chunks.AddOrUpdate(chunkCoord, value, (_, _) => value);
}
@ -83,11 +83,17 @@ namespace MinecraftClient.Mapping
/// <param name="loadCompleted">Whether the ChunkColumn has been fully loaded</param>
public void StoreChunk(int chunkX, int chunkY, int chunkZ, int chunkColumnSize, Chunk? chunk, bool loadCompleted)
{
ChunkColumn chunkColumn = chunks.GetOrAdd(new(chunkX, chunkZ), (_) => new(chunkColumnSize));
Tuple<int, int> chunkCoord = new(chunkX, chunkZ);
if (chunk == null)
chunks.TryRemove(chunkCoord, out _);
else
{
ChunkColumn chunkColumn = chunks.GetOrAdd(chunkCoord, (_) => new(chunkColumnSize));
chunkColumn[chunkY] = chunk;
if (loadCompleted)
chunkColumn.FullyLoaded = true;
}
}
/// <summary>
/// Get chunk column at the specified location

View file

@ -191,12 +191,12 @@ namespace MinecraftClient.Protocol.Handlers
y = (int)((locEncoded >> 26) & 0xFFF);
z = (int)(locEncoded << 38 >> 38);
}
if (x >= 33554432)
x -= 67108864;
if (y >= 2048)
y -= 4096;
if (z >= 33554432)
z -= 67108864;
if (x >= 0x02000000) // 33,554,432
x -= 0x04000000; // 67,108,864
if (y >= 0x00000800) // 2048
y -= 0x00001000; // 4096
if (z >= 0x02000000) // 33,554,432
z -= 0x04000000; // 67,108,864
return new Location(x, y, z);
}

View file

@ -189,10 +189,7 @@ namespace MinecraftClient.Protocol.Handlers
Chunk? chunk = ReadBlockStatesField(cache);
//We have our chunk, save the chunk into the world
handler.InvokeOnMainThread(() =>
{
world.StoreChunk(chunkX, chunkY, chunkZ, chunkColumnSize, chunk, chunkY == lastChunkY);
});
// Skip Read Biomes (Type: Paletted Container) - 1.18(1.18.1) and above
if (protocolversion >= Protocol18Handler.MC_1_18_1_Version)
@ -364,10 +361,7 @@ namespace MinecraftClient.Protocol.Handlers
}
//We have our chunk, save the chunk into the world
handler.InvokeOnMainThread(() =>
{
world.StoreChunk(chunkX, chunkY, chunkZ, chunkColumnSize, chunk, chunkY == maxChunkY);
});
//Pre-1.14 Lighting data
if (protocolversion < Protocol18Handler.MC_1_14_Version)
@ -415,10 +409,7 @@ namespace MinecraftClient.Protocol.Handlers
chunk.SetWithoutCheck(blockX, blockY, blockZ, new Block(queue.Dequeue()));
//We have our chunk, save the chunk into the world
handler.InvokeOnMainThread(() =>
{
world.StoreChunk(chunkX, chunkY, chunkZ, chunkColumnSize, chunk, chunkY == maxChunkY);
});
}
}
@ -497,10 +488,7 @@ namespace MinecraftClient.Protocol.Handlers
for (int blockX = 0; blockX < Chunk.SizeX; blockX++)
chunk.SetWithoutCheck(blockX, blockY, blockZ, new Block(blockTypes.Dequeue(), blockMeta.Dequeue()));
handler.InvokeOnMainThread(() =>
{
world.StoreChunk(chunkX, chunkY, chunkZ, chunkColumnSize, chunk, chunkY == maxChunkY);
});
}
}
}