本文整理汇总了C#中MinecraftClient.OnChunkRecieved方法的典型用法代码示例。如果您正苦于以下问题:C# MinecraftClient.OnChunkRecieved方法的具体用法?C# MinecraftClient.OnChunkRecieved怎么用?C# MinecraftClient.OnChunkRecieved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MinecraftClient
的用法示例。
在下文中一共展示了MinecraftClient.OnChunkRecieved方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapChunkBulk
public static void MapChunkBulk(MinecraftClient client, IPacket _packet)
{
var packet = (MapChunkBulkPacket)_packet;
var metadataStrem = new MemoryStream(packet.ChunkMetadata);
var minecraftStream = new MinecraftStream(metadataStrem);
var data = ZlibStream.UncompressBuffer(packet.ChunkData);
int chunkLength = BlockDataLength + (NibbleDataLength * 2) + (Chunk.Width * Chunk.Depth);
if (packet.LightIncluded)
chunkLength += NibbleDataLength;
for (int i = 0; i < packet.ChunkCount; i++)
{
int x = minecraftStream.ReadInt32();
int z = minecraftStream.ReadInt32();
ushort primaryBitMap = minecraftStream.ReadUInt16();
ushort addBitMap = minecraftStream.ReadUInt16(); // TODO
int offset = i * chunkLength;
// Read chunk data
var chunk = new Chunk(World.GetRelativeChunkPosition(new Vector3(x, 0, z)));
var sectionCount = 0;
// Get the total sections included in the packet
for (int y = 0; y < 16; y++)
{
if ((primaryBitMap & (1 << y)) > 0)
sectionCount++;
}
// Run through the sections
// TODO: Support block IDs >255
for (int y = 0; y < 16; y++)
{
if ((primaryBitMap & (1 << y)) > 0)
{
// Add this section
Array.Copy(data, offset + (y * BlockDataLength), chunk.Sections[y].Blocks, 0, BlockDataLength);
Array.Copy(data, offset + (y * BlockDataLength + (BlockDataLength * sectionCount)),
chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
Array.Copy(data, offset + (y * BlockDataLength + (BlockDataLength * sectionCount + NibbleDataLength)),
chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
if (packet.LightIncluded)
{
Array.Copy(data, offset + (y * BlockDataLength + (BlockDataLength * sectionCount + (NibbleDataLength * 2))),
chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
}
}
}
Array.Copy(data, offset + chunkLength - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
client.World.SetChunk(new Vector3(x, 0, z), chunk);
client.OnChunkRecieved(new ChunkRecievedEventArgs(new Vector3(x, 0, z), new ReadOnlyChunk(chunk)));
}
}
示例2: AddChunk
private static void AddChunk(MinecraftClient client, int x, int z, ushort primaryBitMap, ushort addBitMap, bool lightIncluded, bool groundUp, byte[] data)
{
var position = new Vector3(x, 0, z);
var relativePosition = World.GetRelativeChunkPosition(position);
var chunk = new Chunk(relativePosition);
var sectionCount = GetSectionCount(primaryBitMap);
// Run through the sections
// TODO: Support block IDs >255
for (int y = 0; y < 16; y++)
{
if ((primaryBitMap & (1 << y)) > 0)
{
// Add this section
// Blocks
Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);
// Metadata
Array.Copy(data, (BlockDataLength * sectionCount) + (y * NibbleDataLength),
chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
// Light
Array.Copy(data, ((BlockDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
// Sky light
if (lightIncluded)
Array.Copy(data, ((BlockDataLength + NibbleDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
}
}
// biomes
if (groundUp)
Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
client.World.SetChunk(position, chunk);
client.OnChunkRecieved(new ChunkRecievedEventArgs(position, new ReadOnlyChunk(chunk)));
}
示例3: ChunkData
public static void ChunkData(MinecraftClient client, IPacket _packet)
{
var packet = (ChunkDataPacket)_packet;
if (packet.Data == ChunkRemovalSequence)
{
client.World.RemoveChunk(packet.X, packet.Z);
return;
}
var chunk = new Chunk(World.GetRelativeChunkPosition(new Vector3(packet.X, 0, packet.Z)));
var data = ZlibStream.UncompressBuffer(packet.Data);
var sectionCount = 0;
// Get the total sections included in the packet
for (int y = 0; y < 16; y++)
{
if ((packet.PrimaryBitMap & (1 << y)) > 0)
sectionCount++;
}
// Run through the sections
// TODO: Support block IDs >255
for (int y = 0; y < 16; y++)
{
if ((packet.PrimaryBitMap & (1 << y)) > 0)
{
// Add this section
Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);
Array.Copy(data, y * BlockDataLength + (BlockDataLength * sectionCount),
chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
Array.Copy(data, y * BlockDataLength + (BlockDataLength * sectionCount + NibbleDataLength),
chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
Array.Copy(data, y * BlockDataLength + (BlockDataLength * sectionCount + (NibbleDataLength * 2)),
chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
}
}
if (packet.GroundUpContinuous)
Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
client.World.SetChunk(new Vector3(packet.X, 0, packet.Z), chunk);
client.OnChunkRecieved(new ChunkRecievedEventArgs(new Vector3(packet.X, 0, packet.Z), new ReadOnlyChunk(chunk)));
}