本文整理汇总了C#中SMP.World.GenerateChunk方法的典型用法代码示例。如果您正苦于以下问题:C# World.GenerateChunk方法的具体用法?C# World.GenerateChunk怎么用?C# World.GenerateChunk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMP.World
的用法示例。
在下文中一共展示了World.GenerateChunk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public static Chunk Load(int x, int z, World w, bool thread = true)
{
string file = String.Format("{0}/chunks/{1}/{2}/{3}.{4}.chunk", w.name, Convert.ToString(x & 0x3f, 16), Convert.ToString(z & 0x3f, 16), x.ToString(), z.ToString());
if (File.Exists(file))
{
if (thread)
{
World.chunker.QueueChunkLoad(x, z, false, w);
return null;
}
try
{
Chunk ch = new Chunk(x, z);
using (MemoryStream ms = new MemoryStream())
{
using (FileStream fs = new FileStream(file, FileMode.Open))
{
byte[] comp;
ms.SetLength(fs.Length);
fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
comp = ms.GetBuffer().Decompress();
ms.Write(comp, 0, comp.Length);
}
byte[] bytes = ms.ToArray();
Array.Copy(bytes, ch.blocks, 32768);
Array.Copy(bytes, 32768, ch.meta, 0, 16384);
Array.Copy(bytes, 49152, ch.SkyL, 0, 16384);
Array.Copy(bytes, 65536, ch.Light, 0, 16384);
int index = 81922;
short extraCount = BitConverter.ToInt16(bytes, index - 2);
if (extraCount > 0)
for (int i = 0; i < extraCount; i++)
{
ch.extra.Add(BitConverter.ToInt32(bytes, index), BitConverter.ToUInt16(bytes, index + 4));
index += 6;
}
short physCount = BitConverter.ToInt16(bytes, index); index += 2;
if (physCount > 0)
{
ch.physChecks = new Physics.Check[physCount];
for (int i = 0; i < physCount; i++)
{
ch.physChecks[i] = new Physics.Check(BitConverter.ToInt32(bytes, index), BitConverter.ToInt32(bytes, index + 4), BitConverter.ToInt32(bytes, index + 8), bytes[index + 14], BitConverter.ToInt16(bytes, index + 12));
index += 15;
}
}
}
//Console.WriteLine("LOADED " + x + " " + z);
return ch;
}
catch (Exception ex)
{
Server.ServerLogger.Log("Error loading chunk at " + x + "," + z + "! A new chunk will be generated in it's place.");
Server.ServerLogger.LogError(ex);
}
}
//Console.WriteLine("GENERATED " + x + " " + z);
if (thread)
World.chunker.QueueChunk(x, z, w);
else
return w.GenerateChunk(x, z);
return null;
}
示例2: Load
//.........这里部分代码省略.........
{
byte[] comp;
ms.SetLength(fs.Length);
fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
comp = ms.GetBuffer().Decompress(CompressionType.GZip);
ms.Write(comp, 0, comp.Length);
}
ms.Position = 0;
NbtTree nbt = new NbtTree(ms);
ch.generated = (nbt.Root["Generated"].ToTagByte().Data > 0);
ch.populated = (nbt.Root["Populated"].ToTagByte().Data > 0);
Array.Copy(nbt.Root["Blocks"].ToTagByteArray(), ch.blocks, ch.blocks.Length);
Array.Copy(nbt.Root["Meta"].ToTagByteArray(), ch.meta, ch.meta.Length);
Array.Copy(nbt.Root["BlockLight"].ToTagByteArray(), ch.Light, ch.Light.Length);
Array.Copy(nbt.Root["SkyLight"].ToTagByteArray(), ch.SkyL, ch.SkyL.Length);
Array.Copy(nbt.Root["HeightMap"].ToTagByteArray(), ch.heightMap, ch.heightMap.Length);
Array.Copy(nbt.Root["HeightMapPrec"].ToTagByteArray().Data.ToIntArray(), ch.precipitationHeightMap, ch.precipitationHeightMap.Length);
TagNodeCompound nbtCompound;
foreach (TagNode tag in nbt.Root["Extra"].ToTagList())
{
nbtCompound = tag.ToTagCompound();
ch.extra.Add(nbtCompound["Pos"].ToTagInt(), (ushort)nbtCompound["Value"].ToTagShort());
}
TagNodeList nbtList = nbt.Root["Physics"].ToTagList();
int count = nbtList.Count;
if (count > 0)
{
ch.physChecks = new Physics.Check[count]; TagNodeList nbtList2;
for (int i = 0; i < count; i++)
{
nbtCompound = nbtList[i].ToTagCompound();
nbtList2 = nbtCompound["Pos"].ToTagList();
ch.physChecks[i] = new Physics.Check(nbtList2[0].ToTagInt(), nbtList2[1].ToTagInt(), nbtList2[2].ToTagInt(), nbtCompound["Meta"].ToTagByte(), nbtCompound["Time"].ToTagShort());
}
}
AI ai; McObject obj; Item item; Entity e; TagNodeCompound nbtCompound2;
foreach (TagNode tag in nbt.Root["Entities"].ToTagList())
{
e = null;
nbtCompound = tag.ToTagCompound();
switch ((EntityType)(byte)nbtCompound["Type"].ToTagByte())
{
case EntityType.AI:
// TODO
break;
case EntityType.Object:
// TODO
break;
case EntityType.Item:
nbtCompound2 = nbtCompound["Data"].ToTagCompound();
item = new Item(true) { id = nbtCompound2["ID"].ToTagShort(), count = nbtCompound2["Count"].ToTagByte(), meta = nbtCompound2["Meta"].ToTagShort() };
item.e = new Entity(w) { isItem = true, I = item };
e = item.e;
break;
}
if (e != null)
{
nbtList = nbtCompound["Motion"].ToTagList();
e.velocity = new double[] { nbtList[0].ToTagDouble(), nbtList[1].ToTagDouble(), nbtList[2].ToTagDouble() };
nbtList = nbtCompound["Pos"].ToTagList();
e.pos = new Point3(nbtList[0].ToTagDouble(), nbtList[1].ToTagDouble(), nbtList[2].ToTagDouble());
nbtList = nbtCompound["Rotation"].ToTagList();
e.rot = new float[] { nbtList[0].ToTagFloat(), nbtList[1].ToTagFloat() };
e.age = nbtCompound["Age"].ToTagInt();
e.OnGround = (nbtCompound["OnGround"].ToTagByte() > 0);
e.health = nbtCompound["Health"].ToTagShort();
ch.entityLoad.Add(e);
}
}
Container c; Point3 point3;
foreach (TagNode tag in nbt.Root["Containers"].ToTagList())
{
nbtCompound = tag.ToTagCompound();
nbtList = nbtCompound["Pos"].ToTagList();
point3 = new Point3(nbtList[0].ToTagInt(), nbtList[1].ToTagInt(), nbtList[2].ToTagInt());
c = Container.CreateInstance((ContainerType)(byte)nbtCompound["Type"].ToTagByte(), w, point3);
c.LoadNBTData(nbtCompound["Items"].ToTagList());
if (!w.containers.ContainsKey(point3)) w.containers.Add(point3, c);
}
}
//Console.WriteLine("LOADED " + x + " " + z);
return ch;
}
catch (Exception ex)
{
Logger.LogToFile("Error loading chunk at " + x + "," + z + "! A new chunk will be generated in it's place.");
Logger.LogErrorToFile(ex);
}
}
//Console.WriteLine("GENERATED " + x + " " + z);
if (generate)
{
if (thread) World.chunker.QueueChunk(x, z, w);
else return w.GenerateChunk(x, z);
return null;
}
if (dummy) return new Chunk(x, z);
return null;
}
示例3: Load
public static Chunk Load(int x, int z, World w)
{
string file = w.name + "/chunks/" + Convert.ToString(x & 0x3f, 16) + "/" + Convert.ToString(z & 0x3f, 16) + "/" + x.ToString() + "." + z.ToString() + ".chunk";
if (File.Exists(file))
{
Chunk ch = new Chunk(x, z);
using (MemoryStream ms = new MemoryStream())
{
using (FileStream fs = new FileStream(file, FileMode.Open))
{
byte[] comp;
ms.SetLength(fs.Length);
fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
comp = ms.GetBuffer().Decompress();
ms.Write(comp, 0, comp.Length);
}
byte[] bytes = ms.ToArray();
Array.Copy(bytes, ch.blocks, 32768);
Array.Copy(bytes, 32768, ch.meta, 0, 16384);
Array.Copy(bytes, 49152, ch.SkyL, 0, 16384);
Array.Copy(bytes, 65536, ch.Light, 0, 16384);
int index = 81922;
short extraCount = BitConverter.ToInt16(bytes, index - 2);
lock (ch.extra)
for (int i = 0; i < extraCount; i++)
{
ch.extra.Add(BitConverter.ToInt32(bytes, index), BitConverter.ToUInt16(bytes, index + 4));
index += 6;
}
}
//Console.WriteLine("LOADED " + x + " " + z);
return ch;
}
//Console.WriteLine("GENERATED " + x + " " + z);
return w.GenerateChunk(x, z);
}