Ejemplo n.º 1
0
 public static EntityType GetEntityType(Type type)
 {
     // get it...
     if (EntityTypes.ContainsKey(type))
     {
         return(EntityTypes[type]);
     }
     else
     {
         throw new Exception(string.Format("Failed to get entity type for '{0}'.", type));
     }
 }
Ejemplo n.º 2
0
        public void Deserialize(NbtTag value)
        {
            IsModified = true;
            var compound = value as NbtCompound;
            var chunk    = (Chunk)Serializer.Deserialize(value, true);

            this._TileEntities    = chunk._TileEntities;
            this.Biomes           = chunk.Biomes;
            this.HeightMap        = chunk.HeightMap;
            this.LastUpdate       = chunk.LastUpdate;
            this.Sections         = chunk.Sections;
            this.TerrainPopulated = chunk.TerrainPopulated;
            this.X = chunk.X;
            this.Z = chunk.Z;

            // Entities
            var entities = compound["Entities"] as NbtList;

            Entities = new List <IDiskEntity>();
            for (int i = 0; i < entities.Count; i++)
            {
                var         id = entities[i]["id"].StringValue;
                IDiskEntity entity;
                if (EntityTypes.ContainsKey(id.ToUpper()))
                {
                    entity = (IDiskEntity)Activator.CreateInstance(EntityTypes[id]);
                }
                else
                {
                    entity = new UnrecognizedEntity(id);
                }
                entity.Deserialize(entities[i]);
                Entities.Add(entity);
            }
            var serializer = new NbtSerializer(typeof(Section));

            foreach (var section in compound["Sections"] as NbtList)
            {
                int index = section["Y"].IntValue;
                Sections[index] = (Section)serializer.Deserialize(section);
                Sections[index].ProcessSection();
            }
        }