Repository navigation
[Mod] Amount Stacking
In most games with stackable inventory items you can Right click + Shift to give an amount to split your stack. In Terraria you can't, yet.
Since I don't know how to open up a new GUI window with a text field I use the chatbox as input for amount stacking.
-
Open ModClass.cs
-
Add a field on top:
public static int StackAmount; -
Add the next code to the switch statement in the onChat method:
case "amount": if (StackIndex != 0) { var amount = int.Parse(parameter); if (Main.mouseItem.type == 0) { Main.mouseItem = (Item)Main.player[Main.myPlayer].inventory[StackIndex].Clone(); Main.mouseItem.stack = 0; } Item item7 = Main.player[Main.myPlayer].inventory[StackIndex]; if (amount > item7.stack) { Main.mouseItem.stack = item7.stack; item7.stack = 0; } else { Main.mouseItem.stack += amount; item7.stack -= amount; } if (Main.player[Main.myPlayer].inventory[StackIndex].stack <= 0) { Main.player[Main.myPlayer].inventory[StackIndex] = new Item(); } Recipe.FindRecipes(); Main.soundInstanceMenuTick.Stop(); Main.soundInstanceMenuTick = Main.soundMenuTick.CreateInstance(); Main.PlaySound(12, -1, -1, 1); if (Main.stackSplit == 0) { Main.stackSplit = 15; } else { Main.stackSplit = Main.stackDelay; } } break;
-
Open Main.cs
-
Navigate to:
else if ((((stackSplit <= 1) && (mouseState.RightButton == ButtonState.Pressed)) && (Main.mouseItem.IsTheSameAs(player[myPlayer].inventory[index]) || (Main.mouseItem.type == 0))) && ((Main.mouseItem.stack < Main.mouseItem.maxStack) || (Main.mouseItem.type == 0)))around line 2806 -
Add the following to the top of the inner if statement:
if (keyState.IsKeyDown(Keys.LeftShift)) { PlaySound(10, -1, -1, 1); chatMode = true; Main.chatText = "/amount "; chatRelease = false; ModClass.StackIndex = index; } else { -
And don't forget to put a
}at the end of the inner if statement!