tAPI Vanilla Items - Altering maxStack

octium

Terrarian
How would I go about altering the maxStack size for a vanilla item? Some example code if possible.

My aim is to have most items stack up to 999 or whatever the limit might be as to avoid having to restock and reorganize my inventory so frequently. I play the game as background noise while listening to audiobooks or radio shows, so I want the experience to be as mindless as possible.
 
How would I go about altering the maxStack size for a vanilla item? Some example code if possible.

My aim is to have most items stack up to 999 or whatever the limit might be as to avoid having to restock and reorganize my inventory so frequently. I play the game as background noise while listening to audiobooks or radio shows, so I want the experience to be as mindless as possible.
Im Not Exactly Sure How But This Guy @Neojin Probrably Knows
 
How would I go about altering the maxStack size for a vanilla item? Some example code if possible.

My aim is to have most items stack up to 999 or whatever the limit might be as to avoid having to restock and reorganize my inventory so frequently. I play the game as background noise while listening to audiobooks or radio shows, so I want the experience to be as mindless as possible.
Well, in my MBase.cs file I created this private function
Code:
// itemType is the ID (or Type) of the item to alter
// maxStack is the new max stack value
private static void AlterMaxStack(int itemType, int maxStack) {
    ItemDef.byType[itemType].maxStack = maxStack;
}
Then in another MBase.cs private function I alter this and that maxStack value.
Code:
private static void AlterMaxStacks() {

    AlterMaxStack(4, 999);
    AlterMaxStack(1584, 250);
    AlterMaxStack(456, 99);

    // etc.

}
But what you're probably looking for is this...
Code:
private static void AlterAllMaxStacks() {

    foreach (KeyValuePair<int, Item> keyValuePair in ItemDef.byType)
        keyValuePair.Value.maxStack = 999;

}

In your MBase.cs file make sure to run this function from the OnAllModsLoaded function. That way it modifies the maxStack for all mod items as well. Otherwise it might only get the mod items that were loaded previous to your mod loading.
 
Thank you kindly for your helpful replies. Having a place to start is what I needed, and now I have it. :)
 
Back
Top Bottom