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
+35 -15
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,16 +290,19 @@ namespace AbsorbentSoil
{
try
{
if (__instance == null || uses > 0)
return;
Pot pot = __instance.TryCast<Pot>();
if (pot == null)
return;
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)
{
MelonLogger.Warning($"SetRemainingSoilUses postfix failed: {ex}");
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("AbsorbentSoil")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3c7ea09f730c3ca38d3c004961f111503e0905c8")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7eba0a03f019a3817f694cbae7ecb1d5f3104e45")]
[assembly: System.Reflection.AssemblyProductAttribute("AbsorbentSoil")]
[assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
b331521ed94e421a5866942ca81a55cff8e0735dcb4bc556f934ca310386ca0f
27eaa669f94faac9705255117bf2c7e16542b7864e4480e4b988fcdf9942abbc
Binary file not shown.
Binary file not shown.