internal void loadBehaviors(Entity entity, EntityProperties properties, IWorldAccessor world) { if (BehaviorsAsJsonObj == null) { return; } this.Behaviors.Clear(); for (int i = 0; i < BehaviorsAsJsonObj.Length; i++) { string code = BehaviorsAsJsonObj[i]["code"].AsString(); if (code == null) { continue; } if (world.ClassRegistry.GetEntityBehaviorClass(code) != null) { EntityBehavior behavior = world.ClassRegistry.CreateEntityBehavior(entity, code); Behaviors.Add(behavior); behavior.Initialize(properties, BehaviorsAsJsonObj[i]); } else { world.Logger.Notification("Entity behavior {0} for entity {1} not found, will not load it.", code, properties.Code); } } }
/// <summary> /// Loads the shape of the entity. /// </summary> /// <param name="entityTypeForLogging">The entity to shape</param> /// <param name="api">The Core API</param> /// <returns>The loaded shape.</returns> public void LoadShape(EntityProperties entityTypeForLogging, ICoreAPI api) { LoadedShape = LoadShape(Shape, entityTypeForLogging, api); if (Shape?.Alternates != null) { LoadedAlternateShapes = new Shape[Shape.Alternates.Length]; for (int i = 0; i < Shape.Alternates.Length; i++) { LoadedAlternateShapes[i] = LoadShape(Shape.Alternates[i], entityTypeForLogging, api); } } }
/// <summary> /// Loads the shape of the entity. /// </summary> /// <param name="entityTypeForLogging">The entity to shape</param> /// <param name="api">The Core API</param> /// <returns>The loaded shape.</returns> public Shape LoadShape(EntityProperties entityTypeForLogging, ICoreAPI api) { AssetLocation shapePath; Shape entityShape = null; // Not using a shape, it seems, so whatev ^_^ if (Shape == null) { return(null); } if (Shape?.Base == null || Shape.Base.Path.Length == 0) { shapePath = new AssetLocation("shapes/block/basic/cube.json"); if (Shape?.VoxelizeTexture != true) { api.World.Logger.Warning("No entity shape supplied for entity {0}, using cube shape", entityTypeForLogging.Code); } Shape.Base = new AssetLocation("block/basic/cube"); } else { shapePath = Shape.Base.CopyWithPath("shapes/" + Shape.Base.Path + ".json"); } IAsset asset = api.Assets.TryGet(shapePath); if (asset == null) { api.World.Logger.Error("Entity shape {0} for entity {1} not found, was supposed to be at {2}. Entity will be invisible!", Shape, entityTypeForLogging.Code, shapePath); return(null); } try { entityShape = asset.ToObject <Shape>(); } catch (Exception e) { api.World.Logger.Error("Exception thrown when trying to load entity shape {0} for entity {1}. Entity will be invisible! Exception: {2}", Shape, entityTypeForLogging.Code, e); return(null); } entityShape.ResolveReferences(api.World.Logger, Shape.Base.ToString()); CacheInvTransforms(entityShape.Elements); return(entityShape); }
internal void loadBehaviors(Entity entity, EntityProperties properties, IWorldAccessor world) { if (BehaviorsAsJsonObj == null) { return; } this.Behaviors.Clear(); for (int i = 0; i < BehaviorsAsJsonObj.Length; i++) { string code = BehaviorsAsJsonObj[i]["code"].AsString(); if (code == null) { continue; } EntityBehavior behavior = world.ClassRegistry.CreateEntityBehavior(entity, code); Behaviors.Add(behavior); behavior.Initialize(properties, BehaviorsAsJsonObj[i]); } }
/// <summary> /// Initializes the entity. /// </summary> /// <param name="properties">The properties of this entity.</param> /// <param name="attributes">The attributes of this entity.</param> public virtual void Initialize(EntityProperties properties, JsonObject attributes) { }