a temporary fix for the inventory lost?

        private static bool canreplace = false;
        private static List<int> type = new List<int>();
        private static List<int> stack = new List<int>();
        private static List<string> name = new List<string>();

        public static void Save()
        {

            if (!canreplace)
            {
                for (int num = 0; num < 40; num++)
                {
                    type.Add(Main.player[Main.myPlayer].inventory[num].type);
                    name.Add(Main.player[Main.myPlayer].inventory[num].name);
                    stack.Add(Main.player[Main.myPlayer].inventory[num].stack);
                }
                canreplace = true;
              
            }
         



        }

        public static void Restore()
        {
            if (canreplace)
            {
                for (int num = 0; num < 40; num++)
                {
                    Main.player[Main.myPlayer].inventory[num].SetDefaults(type[num],false);
                    Main.player[Main.myPlayer].inventory[num].SetDefaults(name[num]);
                    Main.player[Main.myPlayer].inventory[num].stack = stack[num];
                }
                type.Clear();
                name.Clear();
                stack.Clear();
                canreplace = false;
            }
        }