removing the gate

This commit is contained in:
2026-05-18 21:03:13 -04:00
parent 7eba0a03f0
commit 4905fd318f
8 changed files with 39 additions and 19 deletions
+37 -17
View File
@@ -17,7 +17,7 @@ namespace AbsorbentSoil
{
public sealed class AbsorbentSoilMod : MelonMod
{
internal static bool VerboseLogging = false;
internal static bool VerboseLogging = true;
public override void OnInitializeMelon()
{
@@ -142,27 +142,37 @@ namespace AbsorbentSoil
internal static class SoilHelper
{
private static readonly FieldInfo RemainingSoilUsesField =
AccessTools.Field(typeof(GrowContainer), "_remainingSoilUses");
private static readonly Dictionary<string, int> RemainingUsesByPotKey = new();
public static void SetRemainingSoilUses(Pot pot, int uses)
{
if (pot == null)
return;
string key = PotKeyHelper.GetPotKey(pot);
if (string.IsNullOrWhiteSpace(key))
return;
RemainingUsesByPotKey[key] = uses;
if (AbsorbentSoilMod.VerboseLogging)
MelonLogger.Msg($"Tracked soil uses for pot '{key}': {uses}");
}
public static int GetRemainingSoilUses(Pot pot)
{
if (pot == null || RemainingSoilUsesField == null)
if (pot == null)
return 0;
try
{
return (int)RemainingSoilUsesField.GetValue(pot);
}
catch
{
string key = PotKeyHelper.GetPotKey(pot);
if (string.IsNullOrWhiteSpace(key))
return 0;
}
return RemainingUsesByPotKey.TryGetValue(key, out int uses) ? uses : 0;
}
public static bool CanCaptureNewAdditives(Pot pot)
{
// Normal soil should have 1 use, long-life should have more than 1.
return GetRemainingSoilUses(pot) > 1;
}
@@ -170,6 +180,13 @@ namespace AbsorbentSoil
{
return GetRemainingSoilUses(pot) > 0;
}
public static void Forget(Pot pot)
{
string key = PotKeyHelper.GetPotKey(pot);
if (!string.IsNullOrWhiteSpace(key))
RemainingUsesByPotKey.Remove(key);
}
}
[HarmonyPatch(typeof(Pot), "ApplyAdditive")]
@@ -273,15 +290,18 @@ namespace AbsorbentSoil
{
try
{
if (__instance == null || uses > 0)
return;
Pot pot = __instance.TryCast<Pot>();
if (pot == null)
return;
AdditiveMemory.Forget(pot);
MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil uses reached zero.");
SoilHelper.SetRemainingSoilUses(pot, uses);
if (uses <= 0)
{
AdditiveMemory.Forget(pot);
SoilHelper.Forget(pot);
MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil uses reached zero.");
}
}
catch (Exception ex)
{