Modded in items: splitting stack breaks item

Discuss modding questions and implementation details.
Post Reply
User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Modded in items: splitting stack breaks item

Post by Ralzar »

I am trying to make my Paints&Dyes items stackable.

I add this code to the item:

Code: Select all

public override bool IsStackable()
{
     return true;
}
All stacking code seems to work exactly as intended. No problems. I use items from the stack and it ticks down etc. I can drop a stack, pick it up and it still works.

However, if I ctrl-click the stack and split it to a lootpile or wagon: the stack I split out stops working as a dye/paint. You can no longer use it. Looking at my save game, this is because the className is now set to null for that stack.

The save info shows working stacks with:
"className": "PaintsAndDyes.Dye"

While the bugged stack is:
"className": null

Apparently the code for splitting out stacks is not copying the class data from items created by a mod.
Is there a way around this? Except attempting to just override the stacking code, which seems like complete overkill?

The DFU stack split code is here and is honestly a bit beyond me to find exactly what piece of data i missing:
https://github.com/Interkarma/daggerfal ... on.cs#L258

Unless I am mistaken, the problem occurs when the new stack item is created using FromItem:
https://github.com/Interkarma/daggerfal ... m.cs#L1475

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Modded in items: splitting stack breaks item

Post by pango »

ItemCollection.SplitStack() calls the constructor DaggerfallUnityItem(DaggerfallUnityItem), that itselfs calls DaggerfallUnityItem.FromItem() to get an empty clone of the original stack; So if this does not clone some attributes, that's most likely what needs to be extended (or made moddable), not the stacking code.

About stackability, it's more complex that you seem to think, so make sure it really works as intended.
You must make sure you only stack items that can be considered "equivalent".
If you have two cows, in a strategy game where you only care about herds, you can consider them equivalent, and stack them as "2 cows". In a farm simulation, if one cow is brown and the other white with black splatter or are named, you'll probably consider them individually and keep them separate.
So how 2 items are considered equivalent is what the next thing you must check after marking some items stackable. If your mod introduce a new attribute to items, that could be yet another thing to compare to tell if two items are equivalent, and can stack together or not.

In code, FindExistingStack() calls DaggerfallUnityItem.IsStackable() that checks special cases (say, quest items are not stackable, no matter their nature), then calls FormulaHelper.IsItemStackable() that determines if the item is of some stackable class. The latter is even moddable, great.
However the list of attributes that are compared is hardcoded in FindExistingStack(), and is not moddable. I think that part could be improved to make the concept of stackability extensible thru modding.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

Post Reply