public static void SetUpModConfigMenu(WateringGrantsXPConfig config, WateringGrantsXP mod) { GenericModConfigMenuAPI api = mod.Helper.ModRegistry.GetApi <GenericModConfigMenuAPI>("spacechase0.GenericModConfigMenu"); if (api == null) { return; } var manifest = mod.ModManifest; api.RegisterModConfig(manifest, () => config = new WateringGrantsXPConfig(), delegate { mod.Helper.WriteConfig(config); VerifyConfigValues(config, mod); }); api.RegisterLabel(manifest, "Watering Grants XP", null); api.RegisterSimpleOption(manifest, "Amount Of Experience", null, () => config.WateringExperienceAmount, (int val) => config.WateringExperienceAmount = val); api.RegisterClampedOption(manifest, "Chance To Get XP", null, () => config.WateringChanceToGetXP, (int val) => config.WateringChanceToGetXP = val, 0, 100); api.RegisterSimpleOption(manifest, "Forage Seed Watering\nGrants Foraging XP", null, () => config.ForageSeedWateringGrantsForagingXP, (bool val) => config.ForageSeedWateringGrantsForagingXP = val); // this is a spacer due to the line break above api.RegisterLabel(manifest, string.Empty, null); api.RegisterLabel(manifest, "Crops Die Without Water", null); api.RegisterSimpleOption(manifest, "Withering Feature Enabled", null, () => config.CropsCanDieWithoutWater, (bool val) => config.CropsCanDieWithoutWater = val); api.RegisterSimpleOption(manifest, "Days For Chance Of Withering", null, () => config.DaysWithoutWaterForChanceToDie, (int val) => config.DaysWithoutWaterForChanceToDie = val); api.RegisterClampedOption(manifest, "Chance For Withering", null, () => config.ChanceToDieWhenLeftForTooLong, (int val) => config.ChanceToDieWhenLeftForTooLong = val, 0, 100); }
public static void VerifyConfigValues(WateringGrantsXPConfig config, WateringGrantsXP mod) { bool invalidConfig = false; if (config.WateringExperienceAmount < 0) { invalidConfig = true; config.WateringExperienceAmount = 0; } if (config.ChanceToDieWhenLeftForTooLong < 0) { invalidConfig = true; config.ChanceToDieWhenLeftForTooLong = 0; } if (config.WateringChanceToGetXP > 100) { invalidConfig = true; config.WateringChanceToGetXP = 100; } if (config.DaysWithoutWaterForChanceToDie < 1) { invalidConfig = true; config.DaysWithoutWaterForChanceToDie = 1; } if (config.ChanceToDieWhenLeftForTooLong < 0) { invalidConfig = true; config.ChanceToDieWhenLeftForTooLong = 0; } if (config.ChanceToDieWhenLeftForTooLong > 100) { invalidConfig = true; config.ChanceToDieWhenLeftForTooLong = 100; } if (invalidConfig) { mod.DebugLog("At least one config value was out of range and was reset."); mod.Helper.WriteConfig(config); } }
public override void Entry(IModHelper helper) { mod = this; key = $"{this.ModManifest.UniqueID}/notWatered"; config = Helper.ReadConfig <WateringGrantsXPConfig>(); WateringGrantsXPConfig.VerifyConfigValues(config, this); Helper.Events.GameLoop.GameLaunched += delegate { WateringGrantsXPConfig.SetUpModConfigMenu(config, this); }; Helper.Events.GameLoop.DayEnding += delegate { CheckForUnwateredCrops(); }; var harmony = new Harmony(this.ModManifest.UniqueID); harmony.Patch( original: AccessTools.Method(typeof(HoeDirt), nameof(HoeDirt.performToolAction)), prefix: new HarmonyMethod(typeof(WateringGrantsXP), nameof(WateringGrantsXP.GiveWateringExp))); }