Files
AbsorbentSoil/AbsorbentSoil/Patches/PlantAdditiveAppliedPatch.cs
T

47 lines
1.4 KiB
C#

using System;
using HarmonyLib;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.ObjectScripts;
using MelonLoader;
namespace AbsorbentSoil
{
[HarmonyPatch(typeof(Plant), nameof(Plant.AdditiveApplied))]
public static class PlantAdditiveAppliedPatch
{
public static void Postfix(Plant __instance, AdditiveDefinition additive, bool isInitialApplication)
{
if (!RuntimeSafety.CanMutateState())
return;
if (__instance == null || additive == null)
return;
// Important cleanup:
// Initial applications are caused by load/init/reapply behavior.
// Do NOT treat them as a fresh additive pour.
if (isInitialApplication)
{
if (AbsorbentSoilMod.VerboseLogging)
MelonLogger.Msg($"[Absorbent Soil] Ignored initial additive fire: {additive.ID}");
return;
}
Pot pot = __instance.Pot;
if (pot == null)
return;
string potKey = PotKeyHelper.GetPotKey(pot);
if (string.IsNullOrWhiteSpace(potKey))
return;
AdditiveMemory.Remember(pot, additive.ID);
if (AbsorbentSoilMod.VerboseLogging)
MelonLogger.Msg($"[Absorbent Soil] Remembered player additive '{additive.ID}' for pot '{potKey}'");
}
}
}