/// <summary> /// Loads the chunk from save data. /// </summary> /// <param name="det">The block data.</param> /// <param name="ents">The entity data.</param> public void LoadFromSaveData(ChunkDetails det, ChunkDetails ents) { if (det.Version != 2 || ents.Version != 2) { throw new Exception("invalid save data VERSION: " + det.Version + " and " + ents.Version + "!"); } Flags = det.Flags & ~(ChunkFlags.POPULATING); SetBlockAt(0, 0, 0, BlockInternal.AIR); // Ensure generated if (det.Blocks.Length > 0) { for (int i = 0; i < BlocksInternal.Length; i++) { BlocksInternal[i]._BlockMaterialInternal = Utilities.BytesToUShort(Utilities.BytesPartial(det.Blocks, i * 2, 2)); BlocksInternal[i].BlockData = det.Blocks[BlocksInternal.Length * 2 + i]; BlocksInternal[i].BlockLocalData = det.Blocks[BlocksInternal.Length * 3 + i]; BlocksInternal[i]._BlockPaintInternal = det.Blocks[BlocksInternal.Length * 4 + i]; } FromFile = true; } for (int i = 0; i < Reachability.Length; i++) { Reachability[i] = det.Reachables[i] == 1; } if (ents.Blocks != null && ents.Blocks.Length > 0 && entsToSpawn.Count == 0) { BsonDocument bsd = BsonSerializer.Deserialize(ents.Blocks); if (bsd.ContainsKey("list")) { List <BsonValue> docs = bsd["list"]; for (int i = 0; i < docs.Count; i++) { BsonDocument ent = (BsonDocument)docs[i]; EntityType etype = (EntityType)Enum.Parse(typeof(EntityType), ent["ENTITY_TYPE"].AsString); try { Entity e = OwningRegion.ConstructorFor(etype).Create(OwningRegion, ent); e.EID = ent["ENTITY_ID"].AsInt64; entsToSpawn.Add(e); } catch (Exception ex) { Utilities.CheckException(ex); SysConsole.Output("Spawning an entity of type " + etype, ex); } } } } }