Skip to content

Commit a5794fe

Browse files
authored
Carry Chests 1.2.1 (#11)
* Bump version to 1.2.1 and enhance mod functionality Updated the version number in `CarryChests.csproj` to `1.2.1`. Changed `ModConfig` to a sealed class and added a `GetSummary()` method. Modified the `Entry` method in `ModEntry` to handle configuration changes. Improved button press handling in `OnButtonPressed` for better user experience. Refined chest menu display logic and added new patches for `SObject` location handling. Updated commit hash for the FauxCore subproject. * Update subproject to new commit version Updated the subproject commit from `123fb98f960c40b74eef46543c1258b26ee5aade` to `708006982a2c373ead6db808867083d4bc16b194`, integrating the latest changes and improvements.
1 parent ab7866b commit a5794fe

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

CarryChests/CarryChests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PropertyGroup>
77
<Name>Carry Chests</Name>
88
<Description>Allows you to pick up placed chests with items.</Description>
9-
<Version>1.2.0</Version>
9+
<Version>1.2.1</Version>
1010
<EnableHarmony>true</EnableHarmony>
1111
<RootNamespace>LeFauxMods.CarryChest</RootNamespace>
1212
<UniqueId>furyx639.CarryChest</UniqueId>

CarryChests/ModConfig.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace LeFauxMods.CarryChest;
77

88
/// <inheritdoc cref="IModConfig{TConfig}" />
9-
internal class ModConfig : IModConfig<ModConfig>, IConfigWithLogAmount
9+
internal sealed class ModConfig : IModConfig<ModConfig>, IConfigWithLogAmount
1010
{
1111
/// <summary>Gets or sets a value indicating whether held chests can be opened.</summary>
1212
public bool OpenHeldChest { get; set; } = true;
@@ -45,6 +45,7 @@ public void CopyTo(ModConfig other)
4545
other.TotalLimit = this.TotalLimit;
4646
}
4747

48+
/// <inheritdoc />
4849
public string GetSummary() =>
4950
new StringBuilder()
5051
.AppendLine(CultureInfo.InvariantCulture, $"{nameof(this.GrabEmptyAsItem),25}: {this.GrabEmptyAsItem}")

CarryChests/ModEntry.cs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal sealed class ModEntry : Mod
1919
/// <inheritdoc />
2020
public override void Entry(IModHelper helper)
2121
{
22-
// Apply
22+
// Init
2323
ModEvents.Subscribe<ConfigChangedEventArgs<ModConfig>>(this.OnConfigChanged);
2424
I18n.Init(helper.Translation);
2525
ModState.Init(helper);
@@ -83,6 +83,9 @@ private void OnCommandReceived(CommandReceivedEventArgs e)
8383
case "backup":
8484
Game1.activeClickableMenu = new ItemGrabMenu(ModState.Backups);
8585
return;
86+
default:
87+
Log.Warn(I18n.Command_Unknown_Description());
88+
break;
8689
}
8790
}
8891

@@ -91,12 +94,7 @@ private void OnGameLaunched(object? sender, GameLaunchedEventArgs e) =>
9194

9295
private void OnButtonPressed(object? sender, ButtonPressedEventArgs e)
9396
{
94-
if (!Context.IsPlayerFree)
95-
{
96-
return;
97-
}
98-
99-
if (e.Button.IsUseToolButton())
97+
if (e.Button.IsUseToolButton() && Context.IsPlayerFree)
10098
{
10199
if (Game1.player.CurrentItem is Tool && !ModState.Config.OverrideTool)
102100
{
@@ -129,16 +127,47 @@ private void OnButtonPressed(object? sender, ButtonPressedEventArgs e)
129127
return;
130128
}
131129

132-
if (e.Button.IsActionButton())
130+
if (!e.Button.IsActionButton() || !ModState.Config.OpenHeldChest)
131+
{
132+
return;
133+
}
134+
135+
if (Context.IsPlayerFree && Game1.player.ActiveObject is Chest heldChest)
136+
{
137+
this.Helper.Input.Suppress(e.Button);
138+
heldChest.ShowMenu();
139+
return;
140+
}
141+
142+
Game1.InUIMode(() =>
133143
{
134-
if (!ModState.Config.OpenHeldChest || Game1.player.ActiveObject is not Chest heldChest)
144+
var (mouseX, mouseY) = e.Cursor.GetScaledScreenPixels().ToPoint();
145+
var inventoryMenu = Game1.activeClickableMenu switch
146+
{
147+
ItemGrabMenu { ItemsToGrabMenu: { } itemsToGrabMenu } when itemsToGrabMenu.isWithinBounds(mouseX,
148+
mouseY) => itemsToGrabMenu,
149+
ItemGrabMenu { inventory: { } inventory } when inventory.isWithinBounds(mouseX, mouseY) =>
150+
inventory,
151+
GameMenu gameMenu when gameMenu.GetCurrentPage() is InventoryPage { inventory: { } inventory } &&
152+
inventory.isWithinBounds(mouseX, mouseY) => inventory,
153+
_ => null
154+
};
155+
156+
if (inventoryMenu is not { inventory: { } slots, actualInventory: { } items })
157+
{
158+
return;
159+
}
160+
161+
var slot = slots.FirstOrDefault(slot => slot.containsPoint(mouseX, mouseY));
162+
if (slot is null || !int.TryParse(slot.name, out var index) ||
163+
items[index] is not Chest chest)
135164
{
136165
return;
137166
}
138167

139168
this.Helper.Input.Suppress(e.Button);
140-
heldChest.ShowMenu();
141-
}
169+
chest.ShowMenu();
170+
});
142171
}
143172

144173
private void OnConfigChanged(ConfigChangedEventArgs<ModConfig> e)

CarryChests/Services/ModPatches.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public static void Apply()
4646
AccessTools.DeclaredMethod(typeof(SObject), nameof(SObject.drawWhenHeld)),
4747
new HarmonyMethod(typeof(ModPatches), nameof(Object_drawWhenHeld_prefix)));
4848

49+
_ = Harmony.Patch(
50+
AccessTools.DeclaredPropertyGetter(typeof(SObject), nameof(SObject.Location)),
51+
postfix: new HarmonyMethod(typeof(ModPatches), nameof(Object_Location_postfix)));
52+
4953
_ = Harmony.Patch(
5054
AccessTools.DeclaredMethod(typeof(SObject), nameof(SObject.maximumStackSize)),
5155
postfix: new HarmonyMethod(typeof(ModPatches), nameof(Object_maximumStackSize_postfix)));
@@ -190,4 +194,13 @@ private static void Object_placementAction_postfix(
190194
chest.ToLocalInventory();
191195
}
192196
}
197+
198+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony")]
199+
private static void Object_Location_postfix(SObject __instance, ref GameLocation __result)
200+
{
201+
if (__instance is Chest)
202+
{
203+
__result ??= Game1.player.currentLocation;
204+
}
205+
}
193206
}

0 commit comments

Comments
 (0)