Issue Equipping items from Multi Stack collection using Hotbar

Mr. Singer

New member
Greetings. I've set up my player's inventory as a multi stack, and I have a Hotbar with hotkeys setup to equip items into a single equipment slot.

An odd behavior occurs when I attempt to equip a stackable item using this method. If I press the hotkey (1 in this case), the first stack of the item appears as equipped in the equipment slot, yet the second stack is the one that appears in the Hotbar:
1791848816318.png
As you can see, the stack of 2 items is in the equipment slot, and the stack of 3 items appears in the Hotbar. I would expect both the equipment slot and the Hotbar to display the same number.
If I unequip with the hotkey, now the hotbar displays the total number of items in the inventory, which is actually the desired functionality.
1791848909147.png
But if I equip again, now the stacks in the inventory are merged into one, and all collections show the correct total number.
1791848967455.png
If I unequip again, the stacks separate again once in the inventory, and the cycle repeats.
What could be causing this behavior? What I would want in this scenario is for the Hotbar and equipment slot to always display the total number of items (5), but for the stacks to remain separated in the inventory (one of 2 and the other of 3).
 
Hello Mr.Singer

From what I understand in your setup you have an ItemHotbar and an Equipment Panel.

Equipment panels use the SlotItemCollection to know what item to display
The Hotbar points to an ItemStack within the Inventory.

If you have multiple stacks of the same Item I assume your item is a Mutable&Common item and that you have a MultiStackItemCollection for your main itemCollection.

The truth is what you want to achieve is not default behaviour so you'll need to use ItemVIewModules to show the count you want.

Right now your ItemView shows the ItemIcon and Amount of the ItemInfo/ItemStack it's provided. But in your case you don't want to show the Amount of the ItemInfo/ItemStack you want to show the amount of the itemDefinition within your Inventory.
So you need to use an ItemViewModule that computes the number of that item in the Inventory and display it, instead of displaying the amount it's provided from the ItemInfo/ItemStack.

There is some limitation with this approach. If using the item consumes it, then your ItemHotbar might still keep reference to the second ItemStack as it automatically searches for a new match when it's amount changes, But the ItemSlotCollection doesn't do that. So as soon as you use all the amount from the ItemStack referenced then it will remove it, even though there might still be some left in another stack. To deal with that you'll want actions that consume the item to consume amount from other stacks first OR have the item action (or an event listener on item remove) to reassign a new stack if the current one is depleted.

I know this might be a bit complicated but I hope this makes sense. If you have any futher questions let me know
 
Back
Top