Patched the checkAction method instead to avoid the patch from executing multiple times
This commit is contained in:
		| @@ -309,8 +309,8 @@ namespace stardew_access | ||||
|                 ); | ||||
|  | ||||
|             harmony.Patch( | ||||
|                     original: AccessTools.Method(typeof(TrashBear), nameof(TrashBear.draw), new Type[] { typeof(SpriteBatch) }), | ||||
|                     prefix: new HarmonyMethod(typeof(TrashBearPatch), nameof(TrashBearPatch.DrawPatch)) | ||||
|                     original: AccessTools.Method(typeof(TrashBear), nameof(TrashBear.checkAction)), | ||||
|                     postfix: new HarmonyMethod(typeof(TrashBearPatch), nameof(TrashBearPatch.CheckActionPatch)) | ||||
|                 ); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -1,22 +1,23 @@ | ||||
| using StardewValley; | ||||
| using StardewValley.Characters; | ||||
|  | ||||
| namespace stardew_access.Patches | ||||
| { | ||||
|     internal class TrashBearPatch | ||||
|     { | ||||
|         internal static void DrawPatch(int ___itemWantedIndex, int ___showWantBubbleTimer) | ||||
|         internal static void CheckActionPatch(TrashBear __instance, bool __result, int ___itemWantedIndex, int ___showWantBubbleTimer) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (___showWantBubbleTimer >= 2900) | ||||
|                 { | ||||
|                     string itemName = Game1.objectInformation[___itemWantedIndex].Split('/')[4]; | ||||
|                     MainClass.ScreenReader.Say($"Trash Bear wants {itemName}!", true); | ||||
|                 } | ||||
|                 if (__result) return; // The true `true` value of __result indicates the bear is interactable i.e. when giving the bear the wanted item | ||||
|                 if (__instance.sprite.Value.CurrentAnimation != null) return; | ||||
|  | ||||
|                 string itemName = Game1.objectInformation[___itemWantedIndex].Split('/')[4]; | ||||
|                 MainClass.ScreenReader.Say($"Trash Bear wants {itemName}!", true); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 MainClass.ErrorLog($"An error occured TrashBearPatch::DrawPatch():\n{e.Message}\n{e.StackTrace}"); | ||||
|                 MainClass.ErrorLog($"An error occured TrashBearPatch::CheckActionPatch():\n{e.Message}\n{e.StackTrace}"); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user