////////////////

        public static void Implant(Chest chest, ChestImplanterItemDefinition info)
        {
            int addedAmount = ChestImplanter.GetImplantQuantity(info);

            if (addedAmount == 0)
            {
                return;
            }

            int itemType = info.ChestItem.Type;

            if (itemType == 0)
            {
                LogHelpers.Alert("Invalid item key " + info.ChestItem);
                return;
            }

            // Add or remove quantity of item, according to implanter spec
            if (addedAmount > 0)
            {
                ChestImplanter.PrependItemToChest(chest, itemType, addedAmount, info);
            }
            else if (addedAmount < 0)
            {
                ChestImplanter.ExtractItemFromChest(chest, itemType, -addedAmount);
            }
            else
            {
                throw new ModHelpersException("Invalid quantity.");
            }
        }
        ////////////////

        public static bool CanChestAcceptImplantItem(Tile chestTile, ChestImplanterItemDefinition info)
        {
            if (info.WallId != -1 && info.WallId != chestTile.wall)
            {
                return(false);
            }
            return(Main.rand.NextFloat() < info.ChancePerChest);
        }
        private static int GetImplantQuantity(ChestImplanterItemDefinition info)
        {
            int range = info.MaxQuantity - info.MinQuantity;

            if (range == 0)
            {
                return(info.MinQuantity);
            }

            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            return(info.MinQuantity + rand.Next(range));
        }
        public static void PrependItemToChest(Chest chest, int itemType, int amount, ChestImplanterItemDefinition info)
        {
            ChestImplanter.PrependItemToChest(chest, itemType, amount, info.Prefix);

            if (ChestImplantsConfig.Instance.DebugModeInfo)
            {
                Tile mytile = Main.tile[chest.x, chest.y];

                string chestName;
                if (!TileFrameHelpers.VanillaChestTypeNamesByFrame.TryGetValue(mytile.frameX / 36, out chestName))
                {
                    chestName = "Unknown (modded?) chest";
                }

                LogHelpers.Log(
                    " Implanted " + chestName + " (" + chest.x + ", " + chest.y + ") with " + amount + " " + info.ChestItem.ToString());
            }
        }