/// <summary>
        /// Add <paramref name="item"/> to the NonFull cache if qualified.
        /// </summary>
        /// <param name="item"> Item to add. </param>
        private void AddToNonFull(Thing item)
        {
            // Possible states:
            // 1. Item stack count equals to stack limit.
            // 2. Item not in cache.
            // 3. Item in cache.

            ThingDef def           = item.def;
            int      defStackLimit = def.stackLimit;

            // State 1
            if (item.stackCount == defStackLimit)
            {
                return;
            }

            // State 2
            if (!NonFullThings.TryGetValue(item, out Thing value))
            {
                NonFullThings[item] = item;
                return;
            }

            // State 3
            // Update() method will take care of the change related to value.
            // Note: Steps are taken to clean up the spawn setup for item if TryAbsorbStack() returns true,
            // because item is DeSpawned when in the process of spawning.
            // Detail can check in the Harmony patch to GenSpawn.Spawn() and Thing.SpawnSetup().
            if (!value.TryAbsorbStack(item, true))
            {
                this.NonFullThings[item] = item;
            }
        }
 /// <summary>
 /// Remove item from NonFull cache.
 /// </summary>
 /// <param name="item"> Item to remove. </param>
 /// <remarks> If the add and update operation runs correctly, there will always be only one or zero non-full stack per kind. </remarks>
 private void RemoveFromNonFull(Thing item)
 {
     if (NonFullThings.TryGetValue(item, out Thing nonFullThings) &&
         nonFullThings == item)
     {
         NonFullThings.Remove(item);
     }
 }
        public int SpareSpaceOnNonFull(Thing thing)
        {
            if (NonFullThings.TryGetValue(thing, out Thing value))
            {
                return(thing.def.stackLimit - value.stackCount);
            }

            return(0);
        }