From e43f3bf160a19733d1786808cab5d9727c60a3a1 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 5 Aug 2017 23:08:42 -0400 Subject: [PATCH] reimplement NoMorePets to simplify code & fix bugs --- GeneralMods/NoMorePets/NoMorePets.cs | 22 +++++++--------------- GeneralMods/NoMorePets/README.md | 2 ++ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/GeneralMods/NoMorePets/NoMorePets.cs b/GeneralMods/NoMorePets/NoMorePets.cs index 9cef3e18..a9a2f058 100644 --- a/GeneralMods/NoMorePets/NoMorePets.cs +++ b/GeneralMods/NoMorePets/NoMorePets.cs @@ -1,7 +1,9 @@ using System; +using System.Linq; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; +using StardewValley.Characters; namespace Omegasis.NoMorePets { @@ -15,30 +17,20 @@ namespace Omegasis.NoMorePets /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { - GameEvents.UpdateTick += this.GameEvents_UpdateTick; + SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; } /********* ** Private methods *********/ - /// The method invoked when the game updates (roughly 60 times per second). + /// The method invoked after the player loads a save. /// The event sender. /// The event data. - public void GameEvents_UpdateTick(object sender, EventArgs e) + public void SaveEvents_AfterLoad(object sender, EventArgs e) { - if (!Context.IsWorldReady) - return; - - string petName = Game1.player.getPetName(); - if (Game1.player.currentLocation is Farm) - { - foreach (NPC npc in Game1.player.currentLocation.characters.ToArray()) - { - if (npc.name == petName) - Game1.removeCharacterFromItsLocation(petName); - } - } + foreach (Pet pet in Utility.getAllCharacters().OfType().ToArray()) + pet.currentLocation.characters.Remove(pet); } } } diff --git a/GeneralMods/NoMorePets/README.md b/GeneralMods/NoMorePets/README.md index 739d530f..90ebc7f1 100644 --- a/GeneralMods/NoMorePets/README.md +++ b/GeneralMods/NoMorePets/README.md @@ -23,3 +23,5 @@ All your pets will be removed automatically when you play the save. 1.4: * Internal refactoring. +* Fixed villagers being removed if they match your pet name. +* Fixed pet not being removed if it's inside your house.