private void setupSnapshot()
 {
     if (Main.LocalPlayer.name.Equals(this.player.name))
     {
         this.playerData = new DataHolder();
         buildData(ref this.playerData.inventoryState, this.player.inventory);
         buildData(ref this.playerData.equipState, this.player.armor);
         buildData(ref this.playerData.miscState, this.player.miscEquips);
         buildData(ref this.playerData.equipDye, this.player.dye);
         buildData(ref this.playerData.miscDye, this.player.miscDyes);
         this.resetCache = false;
     }
 }
        public override bool OnPickup(Item item, Player player)
        {
            Inventory  inven = player.GetModPlayer <Inventory>();
            DataHolder data  = inven.playerData;

            // Only goes in here if the player has died and not if inventory has already been handled (What happens if they die again? New dataholder will be built.)
            if (data != null && player.difficulty == 1 && this.CanPickup(item, player) && data.inventoryState.Values.Any(v => - 1 != v))
            {
                bool foundSwap = false;
                if (item.bodySlot > 0 || item.headSlot > 0 || item.legSlot > 0 || item.accessory || item.vanity)
                {
                    foundSwap = handleSwap(item, data.equipState, ref player.armor, ref player.inventory);
                }
                else if (item.dye > 0)
                {
                    // Handle when same dyes stack
                    if (item.stack > 1)
                    {
                        Item cloneSingleStack = item.Clone();
                        cloneSingleStack.stack = 1;
                        for (int i = 0; i < item.stack; i++)
                        {
                            foundSwap = handleSwap(cloneSingleStack, data.equipDye, ref player.dye, ref player.inventory) || handleSwap(cloneSingleStack, data.miscDye, ref player.miscDyes, ref player.inventory);
                        }
                    }
                    else
                    {
                        foundSwap = handleSwap(item, data.equipDye, ref player.dye, ref player.inventory) || handleSwap(item, data.miscDye, ref player.miscDyes, ref player.inventory);
                    }
                }
                else
                {
                    foundSwap = handleSwap(item, data.miscState, ref player.miscEquips, ref player.inventory) || handleSwap(item, data.inventoryState, ref player.inventory, ref player.inventory);
                }
                return(foundSwap ? false : base.OnPickup(item, player));
            }
            return(base.OnPickup(item, player));
        }