From 919c0fa98ca47978dd9a273626e571315bbaaa72 Mon Sep 17 00:00:00 2001 From: Khoi Doan Date: Mon, 8 Apr 2024 00:44:43 +0000 Subject: [PATCH] Add support for big chests (and update to 1.6) (#1) --- AutomateChests/AutomateChests.csproj | 2 +- AutomateChests/IGenericModConfigMenuApi.cs | 19 +++----------- AutomateChests/ModConfig.cs | 3 +-- AutomateChests/ModEntry.cs | 29 ++++++---------------- AutomateChests/ObjectPatches.cs | 2 +- AutomateChests/manifest.json | 8 +++--- 6 files changed, 18 insertions(+), 45 deletions(-) diff --git a/AutomateChests/AutomateChests.csproj b/AutomateChests/AutomateChests.csproj index cf4562c..0984204 100644 --- a/AutomateChests/AutomateChests.csproj +++ b/AutomateChests/AutomateChests.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 true diff --git a/AutomateChests/IGenericModConfigMenuApi.cs b/AutomateChests/IGenericModConfigMenuApi.cs index ef4376f..901aae0 100644 --- a/AutomateChests/IGenericModConfigMenuApi.cs +++ b/AutomateChests/IGenericModConfigMenuApi.cs @@ -23,26 +23,15 @@ public interface IGenericModConfigMenuApi /// The paragraph text to display. void AddParagraph(IManifest mod, Func text); - /// Add a boolean option at the current position in the form. + /// Add a string option at the current position in the form. /// The mod's manifest. /// Get the current value from the mod config. /// Set a new value in the mod config. /// The label text to show in the form. /// The tooltip text shown when the cursor hovers on the field, or null to disable the tooltip. + /// The values that can be selected, or null to allow any. + /// Get the display text to show for a value from , or null to show the values as-is. /// The unique field ID for use with , or null to auto-generate a randomized ID. - void AddBoolOption(IManifest mod, Func getValue, Action setValue, Func name, Func tooltip = null, string fieldId = null); - - /// Add an integer option at the current position in the form. - /// The mod's manifest. - /// Get the current value from the mod config. - /// Set a new value in the mod config. - /// The label text to show in the form. - /// The tooltip text shown when the cursor hovers on the field, or null to disable the tooltip. - /// The minimum allowed value, or null to allow any. - /// The maximum allowed value, or null to allow any. - /// The interval of values that can be selected. - /// Get the display text to show for a value, or null to show the number as-is. - /// The unique field ID for use with , or null to auto-generate a randomized ID. - void AddNumberOption(IManifest mod, Func getValue, Action setValue, Func name, Func tooltip = null, int? min = null, int? max = null, int? interval = null, Func formatValue = null, string fieldId = null); + void AddTextOption(IManifest mod, Func getValue, Action setValue, Func name, Func tooltip = null, string[] allowedValues = null, Func formatAllowedValue = null, string fieldId = null); } } diff --git a/AutomateChests/ModConfig.cs b/AutomateChests/ModConfig.cs index f6c65fa..44d6540 100644 --- a/AutomateChests/ModConfig.cs +++ b/AutomateChests/ModConfig.cs @@ -8,7 +8,6 @@ namespace AutomateChests { internal class ModConfig { - public bool ActivationItemIsBigCraftable { get; set; } = true; - public int ActivationItemIndex { get; set; } = 275; + public string ActivationItemId { get; set; } = "(BC)275"; } } diff --git a/AutomateChests/ModEntry.cs b/AutomateChests/ModEntry.cs index 478d278..e7fef87 100644 --- a/AutomateChests/ModEntry.cs +++ b/AutomateChests/ModEntry.cs @@ -59,19 +59,11 @@ private void OnGameLaunched(object sender, GameLaunchedEventArgs e) configMenu.AddParagraph( mod: this.ModManifest, text: () => "The following config is for controlling the item required to enable a chest for automation, and the item you get back when undoing the chest automation. If you change the config while having chests automated, if you remove the item you will get the new configs item instead"); - // add some config options - configMenu.AddBoolOption( + configMenu.AddTextOption( mod: this.ModManifest, - name: () => "Activation Item is BigCraftable", - tooltip: () => "This controls whether to interpret ActivationItemIndex as a BigCraftable or as an Object", - getValue: () => this.Config.ActivationItemIsBigCraftable, - setValue: value => this.Config.ActivationItemIsBigCraftable = value - ); - configMenu.AddNumberOption( - mod: this.ModManifest, - name: () => "Activation Item Index", - getValue: () => this.Config.ActivationItemIndex, - setValue: value => this.Config.ActivationItemIndex = value + name: () => "Activation Item ID", + getValue: () => this.Config.ActivationItemId, + setValue: value => this.Config.ActivationItemId = value ); } @@ -86,11 +78,11 @@ private void OnButtonPressed(object sender, ButtonPressedEventArgs e) return; Game1.currentLocation.objects.TryGetValue(e.Cursor.GrabTile, out SObject obj); - if (obj != null && obj is Chest { SpecialChestType: Chest.SpecialChestTypes.None} chest) + if (obj != null && obj is Chest { SpecialChestType: Chest.SpecialChestTypes.None or Chest.SpecialChestTypes.BigChest } chest) { var heldItem = Game1.player.ActiveObject; // if the player is holding a hopper and the chest isn't tagged by us, it should be now - if (heldItem != null && heldItem.ParentSheetIndex == Config.ActivationItemIndex && heldItem.bigCraftable.Value == Config.ActivationItemIsBigCraftable && !chest.modData.ContainsKey(this.ModDataFlag)) + if (heldItem != null && heldItem.QualifiedItemId == Config.ActivationItemId && !chest.modData.ContainsKey(this.ModDataFlag)) { chest.Tint = Color.DarkViolet; chest.modData[this.ModDataFlag] = "1"; @@ -110,14 +102,7 @@ private void OnButtonPressed(object sender, ButtonPressedEventArgs e) chest.heldObject.Value = null; chest.modData.Remove(this.ModDataFlag); - Item item; - if (Config.ActivationItemIsBigCraftable) - { - item = new SObject(Vector2.Zero, Config.ActivationItemIndex, false); - } else - { - item = new SObject(Config.ActivationItemIndex, 1, false); - } + Item item = ItemRegistry.Create(Config.ActivationItemId); Game1.player.addItemByMenuIfNecessary(item); Game1.playSound("shiny4"); diff --git a/AutomateChests/ObjectPatches.cs b/AutomateChests/ObjectPatches.cs index 49ac3dc..2fd71d1 100644 --- a/AutomateChests/ObjectPatches.cs +++ b/AutomateChests/ObjectPatches.cs @@ -29,7 +29,7 @@ public static void Automate_AutomationFactory_GetFor_SObject__Postfix(ref IAutom { var obj = container.Location.getObjectAtTile(__result.TileArea.X, __result.TileArea.Y); // if it is a normal ordinary chest and isn't flagged by AutomateChests, it is no longer a valid container (but if it is flagged, don't alter it (keeping it automated) - if (obj is Chest { SpecialChestType: Chest.SpecialChestTypes.None } chest && !chest.modData.ContainsKey("SinZ.AutomateChests")) + if (obj is Chest { SpecialChestType: Chest.SpecialChestTypes.None or Chest.SpecialChestTypes.BigChest } chest && !chest.modData.ContainsKey("SinZ.AutomateChests")) { __result = null; } diff --git a/AutomateChests/manifest.json b/AutomateChests/manifest.json index c867a09..f0feab3 100644 --- a/AutomateChests/manifest.json +++ b/AutomateChests/manifest.json @@ -1,16 +1,16 @@ { "Name": "AutomateChests", "Author": "SinZ", - "Version": "1.1.0", + "Version": "2.0.0", "Description": "Changes Automate to only use this mods defined chest instead of normal chests for storage", "UniqueID": "SinZ.AutomateChests", "EntryDll": "AutomateChests.dll", - "MinimumApiVersion": "3.0.0", + "MinimumApiVersion": "4.0.0", "UpdateKeys": [ "Nexus:11727" ], "Dependencies": [ { "UniqueID": "Pathoschild.Automate", - "MinimumVersion": "1.25.3" + "MinimumVersion": "2.0.0" } ] -} \ No newline at end of file +}