Skip to content

Commit

Permalink
Merge pull request #54 from Vapok/vapok/r1.6.1
Browse files Browse the repository at this point in the history
Release 1.6.1
  • Loading branch information
Vapok authored Feb 8, 2023
2 parents 1881245 + f5ad0a1 commit a237937
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
2 changes: 1 addition & 1 deletion AdventureBackpacks/AdventureBackpacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AdventureBackpacks : BaseUnityPlugin, IPluginInfo
//Module Constants
private const string _pluginId = "vapok.mods.adventurebackpacks";
private const string _displayName = "Adventure Backpacks";
private const string _version = "1.6.0";
private const string _version = "1.6.1";

//Interface Properties
public string PluginId => _pluginId;
Expand Down
65 changes: 46 additions & 19 deletions AdventureBackpacks/Features/QuickTransfer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using AdventureBackpacks.Configuration;
using AdventureBackpacks.Extensions;
using BepInEx.Bootstrap;
Expand All @@ -13,7 +14,13 @@ public static class QuickTransfer
{
public static bool FeatureInitialized = false;
public static ConfigEntry<bool> EnableQuickTransfer { get; private set;}


private static InventoryGui _inventoryGuiInstance;
private static Inventory _fromInventory;
private static Inventory _toInventory;

private static bool _processingRightClick = false;

static QuickTransfer()
{
ConfigRegistry.Waiter.StatusChanged += (_, _) => RegisterConfiguraitonFile();
Expand All @@ -25,58 +32,78 @@ private static void RegisterConfiguraitonFile()
new ConfigDescription("When enabled, can move items to/from player inventory to container, by right clicking.",
null,
new ConfigurationManagerAttributes { Order = 5 }));

}

[HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.OnRightClickItem))]
[HarmonyPriority(Priority.First)]
static class OnRightClickItemPatch
{
static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item)
static void Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item)
{
if (!FeatureInitialized)
return true;
return;

if (Player.m_localPlayer == null || __instance == null || item == null)
return false;
return;

if (__instance.m_currentContainer == null || !__instance.IsContainerOpen() || !EnableQuickTransfer.Value)
return true;
return;

if (Chainloader.PluginInfos.ContainsKey("blumaye.quicktransfer"))
{
AdventureBackpacks.Log.Warning("blumaye.quicktransfer mod is enabled. Adventure Backpack's Quick Transfer disabled.");
return true;
return;
}

if (item.m_equiped)
return true;
return;

var containerInventory = __instance.m_currentContainer.GetInventory();

if (item.IsBackpack() && containerInventory.IsBackPackInventory())
return true;
return;

var playerInventory = Player.m_localPlayer.GetInventory();

if (playerInventory == null || containerInventory == null || grid == null)
return true;

Inventory fromInventory;
Inventory toInventory;
return;

_inventoryGuiInstance = __instance;

if (grid.m_inventory == containerInventory)
{
fromInventory = containerInventory;
toInventory = playerInventory;
_fromInventory = containerInventory;
_toInventory = playerInventory;
}
else
{
fromInventory = playerInventory;
toInventory = containerInventory;
_fromInventory = playerInventory;
_toInventory = containerInventory;
}

toInventory.MoveItemToThis(fromInventory, item);
__instance.m_moveItemEffects.Create(__instance.transform.position, Quaternion.identity);
_processingRightClick = true;
}

static void Finalizer(Exception __exception)
{
_processingRightClick = false;
_toInventory = null;
_fromInventory = null;
_inventoryGuiInstance = null;
}
}

[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.UseItem))]
[HarmonyPriority(Priority.First)]
static class UseItemPatch
{
static bool Prefix(ItemDrop.ItemData item)
{
if (!_processingRightClick)
return true;

_toInventory.MoveItemToThis(_fromInventory, item);
_inventoryGuiInstance.m_moveItemEffects.Create(_inventoryGuiInstance.transform.position, Quaternion.identity);

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions AdventureBackpacks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
5 changes: 5 additions & 0 deletions PATCHNOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Adventure Backpacks Patchnotes

# 1.6.1.0 - Module Compatibility on Right Click Quick Transfer
* Reworked Logic to make Right Click Quick Transfer friendly to other inventory mods.
* Adds Compatibility to **[Auto Split Stack](https://www.nexusmods.com/valheim/mods/76?tab=files&file_id=7184)**, as well as **[Quick Stack Sort](https://www.nexusmods.com/valheim/mods/2094?tab=description)**
* May add additional compatibility to other mods not tested.

# 1.6.0.0
* Updating for Valheim Version 0.213.4
* Right Click Fast Item Transfer Fixes
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ stage of maturity. This includes a backpack progression that will start at Meado


# Current Patch Notes
# 1.6.0.0
* Updating for Valheim Version 0.213.4
* Right Click Fast Item Transfer Fixes
* Stacking Items when bags are full are fixed.
* Added vanilla effects on item transfer for crisper feel.
# 1.6.1.0 - Module Compatibility on Right Click Quick Transfer
* Reworked Logic to make Right Click Quick Transfer friendly to other inventory mods.
* Adds Compatibility to **[Auto Split Stack](https://www.nexusmods.com/valheim/mods/76?tab=files&file_id=7184)**, as well as **[Quick Stack Sort](https://www.nexusmods.com/valheim/mods/2094?tab=description)**
* May add additional compatibility to other mods not tested.

## 1.5.0.0
* Initial Release of Adventuring Backpacks introducing 6 New Backpack Prefabs (4 New Models and Designs)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AdventureBackpacks",
"version_number": "1.6.0",
"version_number": "1.6.1",
"website_url": "https://github.com/Vapok/AdventureBackpacks",
"description": "A Valheim Mod to add a catalogue of Adventuring Backpacks to the Game. These packs will grow and become more useful as the game progresses.",
"dependencies": [
Expand Down

0 comments on commit a237937

Please sign in to comment.