InventoryFramework
InventoryFramework provides a data and event layer for inventory management. Designed to be consumed by a separate UI assembly as it has no UI of its own.
模組介紹 作者原文
InventoryFramework
A MelonLoader mod that provides a data and event layer for inventory management. Designed to be consumed by a separate UI assembly as it has no UI of its own.
Getting Started
Add a reference to InventoryFramework.dll in your project. The framework initializes itself via MelonLoader. You do not need to instantiate anything.
Items must be registered before they can be added to any inventory:
InventoryManager.Instance.RegisterItem(new ItemDefinition("wood", "Wood"));
InventoryManager.Instance.PlayerInventory.AddItem("wood", 5);
That first argument is the ID, and the second is the display name.
InventoryManager
The main entry point. Access via InventoryManager.Instance.
Properties
| Property | Type | Description |
| ----------------- | --------------------------------------------- | ------------------------------------- |
| Instance | InventoryManager | Singleton. |
| PlayerInventory | Inventory | The player's inventory. |
| SelectedItem | InventoryItem? | The currently selected item, or null. |
| Registry | IReadOnlyDictionary | All registered item definitions. |
Methods
| Method | Description |
| ---------------------------------- | --------------------------------------------------------------------- |
| RegisterItem(ItemDefinition def) | Registers an item definition. Throws if the ID is already registered. |
| GetItem(string id) | Returns the definition for a registered item ID. Throws if not found. |
| SelectItem(InventoryItem? item) | Sets the selected item and fires OnItemSelected. |
Events
| Event | Signature | Description |
| -------------------- | ------------------------ | ------------------------------------- |
| OnItemSelected | Action | Fired when the selected item changes. |
| OnItemUsed | Action | Fired on left mouse button down. |
| OnItemAltUsed | Action | Fired on right mouse button down. |
| OnInventoryKeyDown | Action | Fired on any key down. |
| OnItemRegistered | Action | Fired when a new item is registered. |
Inventory
Manages a collection of InventoryItems. Access the player inventory via InventoryManager.Instance.PlayerInventory.
Properties
| Property | Type | Description |
| -------- | ------------------------------ | ----------------------------------- |
| Items | IReadOnlyList | The current items in the inventory. |
Methods
| Method | Description |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| AddItem(string id, int quantity = 1) | Adds quantity to an existing stack, or creates a new one. |
| RemoveItem(string id, int quantity = 1) | Removes quantity from a stack. Removes the stack entirely if it reaches zero. Throws if the item is not in the inventory. |
| GetItem(string id) | Returns the InventoryItem for the given ID. Throws if not found. |
| HasItem(string id, int quantity = 1) | Returns true if the inventory contains at least the given quantity. |
| Clear() | Fires OnCleared, then removes all items and fires OnChanged. |
Events
| Event | Signature | Description |
| ----------------------- | ----------------------- | -------------------------------------------------------------------------------- |
| OnChanged | Action | Fired after any change to the inventory. |
| OnCleared | Action | Fired before the inventory is cleared. Items are still readable at this point. |
| OnItemAdded | Action | Fired when a new item stack is created. |
| OnItemRemoved | Action | Fired when an item stack is fully removed. Does not fire when Clear() is called. |
| OnItemQuantityChanged | Action | Fired when an existing stack's quantity changes. |
ItemDefinition
Defines a type of item. Create one per item type and register it with InventoryManager.RegisterItem.
Constructor
new ItemDefinition(string id, string name, Sprite? image = null)
Properties
| Property | Type | Description |
| -------- | --------- | --------------------------------------------------- |
| Id |
安裝與使用 安裝:按包內說明操作
- 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
- 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
- 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
- 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。
不同模組的安裝位置差異較大,包內說明是最可靠的依據。
下面這些內容需要先安裝,否則該模組不會生效: