Example #1
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            // init
            ModEntry.Config   = helper.ReadConfig <ModConfig>();
            ModEntry.SHelper  = helper;
            ModEntry.SMonitor = this.Monitor;

            // Event listeners
            helper.Events.GameLoop.SaveLoaded += this.LoadSkinMap;
            helper.Events.GameLoop.Saving     += this.SaveSkinMap;
            helper.Events.GameLoop.Saved      += this.LoadSkinMap;

            // add commands
            helper.ConsoleCommands.Add("abandon_pet", "Remove a pet with the given name.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("abandon_all_pets", "Remove all pets adopted using this mod, you monster.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("list_animal_types", "Lists all animal types on your farm.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("list_animal_skins", "Lists all animal skins used on your farm.", this.OnCommandReceived);
            helper.ConsoleCommands.Add("reset_animal_skins", "Lists all animal skins used on your farm.", this.OnCommandReceived);

            // Prepare BabyDuck override
            try
            {
                string asset = this.Helper.Content.GetActualAssetKey(Path.Combine("assets", "skins", "BabyDuck.png"));
                Game1.content.Load <Texture2D>(asset);
                BabyDuck = new AnimalSkin("BabyDuck", 0, asset);
            }
            catch (Exception e)
            {
                this.Monitor.Log("Unable to patch BabyDuck due to exception:", LogLevel.Error, e);
            }

            // Register default supported animal types
            Api.RegisterAnimalType("Blue Chicken");
            Api.RegisterAnimalType("Brown Chicken");
            Api.RegisterAnimalType("Brown Cow");
            Api.RegisterAnimalType("Dinosaur", false);
            Api.RegisterAnimalType("Duck");
            Api.RegisterAnimalType("Goat");
            Api.RegisterAnimalType("Pig");
            Api.RegisterAnimalType("Rabbit");
            Api.RegisterAnimalType("Sheep", true, true);
            Api.RegisterAnimalType("Void Chicken");
            Api.RegisterAnimalType("White Chicken");
            Api.RegisterAnimalType("White Cow");

            if (Config.ExtraTypes != null && Config.ExtraTypes.Length > 0)
            {
                foreach (string type in Config.ExtraTypes)
                {
                    Api.RegisterAnimalType(type, false);
                }
            }

            // Register default supported pet types
            Api.RegisterPetType("cat", typeof(Cat));
            Api.RegisterPetType("dog", typeof(Dog));

            // configure bus replacement
            if (ModEntry.Config.AnimalsOnly)
            {
                this.ReplaceBus = false;
            }
            if (this.ReplaceBus)
            {
                try
                {
                    string asset = this.Helper.Content.GetActualAssetKey(Path.Combine("assets", "box.png"));
                    Game1.content.Load <Texture2D>(asset);
                }
                catch (Exception e)
                {
                    this.ReplaceBus = false;
                    this.Monitor.Log("Unable to patch BusStop due to exception:", LogLevel.Error, e);
                }
            }

            // hook events
            helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
        }
        /// <summary>Raised after the game is launched, right before the first update tick. This happens once per game session (unrelated to loading saves). All mods are loaded and initialised at this point, so this is a good time to set up mod integrations.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
        {
            // Prepare BabyDuck override
            try
            {
                string asset = this.Helper.Content.GetActualAssetKey(Path.Combine("assets", "skins", "BabyDuck.png"));
                Game1.content.Load <Texture2D>(asset);
                BabyDuck = new AnimalSkin("BabyDuck", 0, asset);
            }
            catch (Exception ex)
            {
                this.Monitor.Log("Unable to patch BabyDuck due to exception:", LogLevel.Error, ex);
            }

            // Register default supported animal types
            Api.RegisterAnimalType("Blue Chicken");
            Api.RegisterAnimalType("Brown Chicken");
            Api.RegisterAnimalType("Brown Cow");
            Api.RegisterAnimalType("Dinosaur", false);
            Api.RegisterAnimalType("Duck");
            Api.RegisterAnimalType("Goat");
            Api.RegisterAnimalType("Pig");
            Api.RegisterAnimalType("Rabbit");
            Api.RegisterAnimalType("Sheep", true, true);
            Api.RegisterAnimalType("Void Chicken");
            Api.RegisterAnimalType("White Chicken");
            Api.RegisterAnimalType("White Cow");

            if (Config.ExtraTypes != null && Config.ExtraTypes.Length > 0)
            {
                foreach (string type in Config.ExtraTypes)
                {
                    Api.RegisterAnimalType(type, false);
                }
            }

            // Register default supported pet types
            Api.RegisterPetType("cat", typeof(Cat));
            Api.RegisterPetType("dog", typeof(Dog));

            // Trigger setup
            this.DoSetup();
        }