compile errors
This commit is contained in:
@@ -139,49 +139,31 @@ namespace AbsorbentSoil
|
||||
|
||||
internal static class SoilHelper
|
||||
{
|
||||
private static readonly FieldInfo RemainingSoilUsesField =
|
||||
AccessTools.Field(typeof(GrowContainer), "_remainingSoilUses");
|
||||
|
||||
public static bool IsRetainingSoil(Pot pot)
|
||||
{
|
||||
string soilId = GetSoilId(pot);
|
||||
if (string.IsNullOrWhiteSpace(soilId))
|
||||
if (pot == null || string.IsNullOrWhiteSpace(pot.SoilID))
|
||||
return false;
|
||||
|
||||
soilId = soilId.ToLowerInvariant();
|
||||
return soilId.Contains("longlifesoil") || soilId.Contains("extralonglifesoil");
|
||||
string soilId = pot.SoilID.ToLowerInvariant();
|
||||
|
||||
return soilId.Contains("longlifesoil") ||
|
||||
soilId.Contains("extralonglifesoil");
|
||||
}
|
||||
|
||||
public static string GetSoilId(Pot pot)
|
||||
public static int GetRemainingSoilUses(Pot pot)
|
||||
{
|
||||
if (pot == null)
|
||||
return string.Empty;
|
||||
if (pot == null || RemainingSoilUsesField == null)
|
||||
return 0;
|
||||
|
||||
object soilId = ReadMember(pot, "SoilID") ?? ReadMember(pot, "soilID") ?? ReadMember(pot, "SoilId") ?? ReadMember(pot, "soilId");
|
||||
return soilId?.ToString() ?? string.Empty;
|
||||
return (int)RemainingSoilUsesField.GetValue(pot);
|
||||
}
|
||||
|
||||
private static object ReadMember(object instance, string name)
|
||||
public static bool CanRetainAdditives(Pot pot)
|
||||
{
|
||||
if (instance == null || string.IsNullOrWhiteSpace(name))
|
||||
return null;
|
||||
|
||||
Type type = instance.GetType();
|
||||
while (type != null)
|
||||
{
|
||||
PropertyInfo prop = AccessTools.Property(type, name);
|
||||
if (prop != null)
|
||||
{
|
||||
try { return prop.GetValue(instance); } catch { }
|
||||
}
|
||||
|
||||
FieldInfo field = AccessTools.Field(type, name);
|
||||
if (field != null)
|
||||
{
|
||||
try { return field.GetValue(instance); } catch { }
|
||||
}
|
||||
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
return null;
|
||||
return IsRetainingSoil(pot) && GetRemainingSoilUses(pot) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +233,7 @@ namespace AbsorbentSoil
|
||||
|
||||
Pot pot = __instance.Pot;
|
||||
|
||||
if (!SoilHelper.IsRetainingSoil(pot))
|
||||
if (!SoilHelper.CanRetainAdditives(pot))
|
||||
{
|
||||
AdditiveMemory.Forget(pot);
|
||||
return;
|
||||
@@ -276,21 +258,15 @@ namespace AbsorbentSoil
|
||||
[HarmonyPatch(typeof(Pot), "OnPlantFullyHarvested")]
|
||||
internal static class Pot_OnPlantFullyHarvested_Patch
|
||||
{
|
||||
public static void Postfix(Pot __instance)
|
||||
private static void Postfix(Pot __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (__instance == null)
|
||||
return;
|
||||
if (__instance == null)
|
||||
return;
|
||||
|
||||
// After the game's harvest logic runs, if soil was consumed/removed or is no longer retaining soil,
|
||||
// clear the retained additives so freshly re-poured soil starts clean.
|
||||
if (!SoilHelper.IsRetainingSoil(__instance))
|
||||
AdditiveMemory.Forget(__instance);
|
||||
}
|
||||
catch (Exception ex)
|
||||
if (!SoilHelper.CanRetainAdditives(__instance))
|
||||
{
|
||||
MelonLogger.Warning($"OnPlantFullyHarvested postfix failed: {ex}");
|
||||
AdditiveMemory.Forget(__instance);
|
||||
MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil has no retaining uses left.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user