private void LoadEntity(List <KeyValuePair <string, string> > block, int index) { var className = GetClassName(block, index); var metaData = EntityDictionary.FindEntityMetaData(className); if (metaData == null) { throw new NoSuchEntityClassException(className); } BaseEntity entity = null; //The world always has index 0 if (index == 0) { entity = EntityList.CreateEntity(metaData, 0); } else { entity = EntityList.CreateEntity(metaData); } var initialized = false; try { foreach (var kv in block) { var key = kv.Key; var value = kv.Value; //Don't do this multiple times if (key != "classname") { //The engine does not allow values with the same content as the classname to be passed //No reason to impose this restriction here CheckKeyValue(entity, ref key, ref value); //TODO: implement //if (!KeyValueUtils.TrySetKeyValue(entity, metaData, key, value)) { entity.KeyValue(key, value); } } } _logger.Information($"Spawning entity {entity.ClassName} ({entity.GetType().FullName})"); entity.Initialize(); initialized = true; //TODO: can check if the entity is a template and do stuff here } finally { //On failure always free the entity if (!initialized || entity.PendingDestruction) { EntityList.DestroyEntity(entity); } } }