removing the gate
This commit is contained in:
@@ -17,7 +17,7 @@ namespace AbsorbentSoil
|
|||||||
{
|
{
|
||||||
public sealed class AbsorbentSoilMod : MelonMod
|
public sealed class AbsorbentSoilMod : MelonMod
|
||||||
{
|
{
|
||||||
internal static bool VerboseLogging = false;
|
internal static bool VerboseLogging = true;
|
||||||
|
|
||||||
public override void OnInitializeMelon()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
@@ -142,27 +142,37 @@ namespace AbsorbentSoil
|
|||||||
|
|
||||||
internal static class SoilHelper
|
internal static class SoilHelper
|
||||||
{
|
{
|
||||||
private static readonly FieldInfo RemainingSoilUsesField =
|
private static readonly Dictionary<string, int> RemainingUsesByPotKey = new();
|
||||||
AccessTools.Field(typeof(GrowContainer), "_remainingSoilUses");
|
|
||||||
|
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)
|
public static int GetRemainingSoilUses(Pot pot)
|
||||||
{
|
{
|
||||||
if (pot == null || RemainingSoilUsesField == null)
|
if (pot == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
try
|
string key = PotKeyHelper.GetPotKey(pot);
|
||||||
{
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
return (int)RemainingSoilUsesField.GetValue(pot);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
return RemainingUsesByPotKey.TryGetValue(key, out int uses) ? uses : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CanCaptureNewAdditives(Pot pot)
|
public static bool CanCaptureNewAdditives(Pot pot)
|
||||||
{
|
{
|
||||||
// Normal soil should have 1 use, long-life should have more than 1.
|
|
||||||
return GetRemainingSoilUses(pot) > 1;
|
return GetRemainingSoilUses(pot) > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +180,13 @@ namespace AbsorbentSoil
|
|||||||
{
|
{
|
||||||
return GetRemainingSoilUses(pot) > 0;
|
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")]
|
[HarmonyPatch(typeof(Pot), "ApplyAdditive")]
|
||||||
@@ -273,16 +290,19 @@ namespace AbsorbentSoil
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (__instance == null || uses > 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Pot pot = __instance.TryCast<Pot>();
|
Pot pot = __instance.TryCast<Pot>();
|
||||||
if (pot == null)
|
if (pot == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
SoilHelper.SetRemainingSoilUses(pot, uses);
|
||||||
|
|
||||||
|
if (uses <= 0)
|
||||||
|
{
|
||||||
AdditiveMemory.Forget(pot);
|
AdditiveMemory.Forget(pot);
|
||||||
|
SoilHelper.Forget(pot);
|
||||||
MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil uses reached zero.");
|
MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil uses reached zero.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MelonLogger.Warning($"SetRemainingSoilUses postfix failed: {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.AssemblyCompanyAttribute("AbsorbentSoil")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("AbsorbentSoil")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
b331521ed94e421a5866942ca81a55cff8e0735dcb4bc556f934ca310386ca0f
|
27eaa669f94faac9705255117bf2c7e16542b7864e4480e4b988fcdf9942abbc
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user