private string GetIssueText(eIssues issue)
    {
        string txt         = "";
        string seeHandbook = "\n\nCheck handbook? (H)\n" + PersistentSettings.GetString("See_the_handbook_for_details");

        switch (issue)
        {
        case eIssues.Power:
            txt += "\nIssue: Low Power!" + seeHandbook;
            break;

        case eIssues.Input:
            txt += "\nIssue: Cannot find lenses!";
            txt += "\nAre hoppers locked?";
            txt += "\nPress T to insert lenses!" + seeHandbook;
            // ^^^ replace with dynamic text for "T"
            break;

        case eIssues.Output:
            txt += "\nIssue: Attached storage missing or full!" + seeHandbook;
            break;

        case eIssues.SetLens:
            txt += "\nIssue: (T)ell the machine what lens to use!";
            // ^^^ replace with dynamic text for "T"
            break;

        case eIssues.Ready:
            break;

        default:
            break;
        }
        return(txt);
    }
    public override void ReadNetworkUpdate(BinaryReader reader)
    {
        mrCurrentPower = NetworkServerIO.ByteToFloat(reader.ReadByte());
        mTargetLens    = ItemFile.DeserialiseItem(reader);
        mStoredLenses  = ItemFile.DeserialiseItem(reader);

        mIssue        = (eIssues)reader.ReadByte();
        mStatus       = (eStatuses)reader.ReadByte();
        mbHaltedEarly = reader.ReadBoolean();
        mbOnlySwap    = reader.ReadBoolean();
        mbTrashOld    = reader.ReadBoolean();
        mnTrackLPTs   = reader.ReadInt16();
        mnTrackSwaps  = reader.ReadInt16();
    }
    //Executing the namesake of the mod.
    //Function will confirm that all needs are met for swapping a lens.
    //Proper care needs to be taken here to never delete an "old lens", as the ALS has no
    //internal storage for oldLenses.
    //Must not have any mIssue or checkReady checks in this funtion; lest it become recursive/unreachable.
    private bool runSwapLens(LaserPowerTransmitter lpt)
    {
        if (lpt == null)
        {
            return(false);
        }

        ItemBase oldLens = lpt.GetLens();
        bool     hasLens = (oldLens != null);

        if (mbOnlySwap && !hasLens)
        {
            ++mnTrackLPTs;
            return(false);
        }

        if (hasLens)
        {
            if (oldLens.mnItemID == mStoredLenses.mnItemID)
            {
                ++mnTrackLPTs;
                return(false);
            }
            else
            {
                if (!CommunityUtil.GiveToSurrounding((MachineEntity)this, oldLens))
                {
                    Debug.LogWarning("[Auto Lens Swapper][issue] Could not find a surrounding machine to drop an old lens into! Lens was not removed.");
                    mIssue   = eIssues.Output;
                    mLastLPT = lpt;
                    return(false);
                }
            }
        }

        lpt.SwapLens(mTargetLens);
        AddLenses(-1);
        mrCurrentPower -= mrPowerPerSwap;
        ++mnTrackLPTs;
        ++mnTrackSwaps;
        MarkDirtyDelayed();
        return(true);
    }
    public ALS_MachineEntity(ModCreateSegmentEntityParameters parameters)
        : base(parameters)
    {
        mbNeedsLowFrequencyUpdate = true;
        mbNeedsUnityUpdate        = true;
        mUpdates = 0;

        mStatus       = eStatuses.Stopped;
        mIssue        = eIssues.Power;
        mbHaltedEarly = false;
        mbOnlySwap    = false;
        mbTrashOld    = false;

        mnSegmentID      = 0;
        mnSegmentEIndex1 = 0;
        mnSegmentEIndex2 = 0;

        mnTrackLPTs  = 0;
        mnTrackSwaps = 0;

        mrCurrentPower = 0;

        //maAttachedHoppers = new List<StorageMachineInterface>();
    }
    private bool checkReady()
    {
        if (mUpdates % 20 == 0 && mDebug)
        {
            string txt = "[Auto Lens Swapper][DEBUG] checkReady called.";
            txt += "\nmIssue: " + mIssue.ToString();
            Debug.LogWarning(txt);
        }

        if (mrCurrentPower < mrPowerPerSwap)
        {
            mIssue = eIssues.Power;
            if (mUpdates % 20 == 0 && mDebug)
            {
                Debug.LogWarning("[Auto Lens Swapper][DEBUG] checkReady Issue: Power:" + mrCurrentPower + " - " + mrMaxPower);
            }
            return(false);
        }
        else if (mTargetLens == null)
        {
            mIssue = eIssues.SetLens;
            if (mUpdates % 20 == 0 && mDebug)
            {
                Debug.LogWarning("[Auto Lens Swapper][DEBUG] checkReady Issue: setlens, null");
            }
            return(false);
        }
        else if (!isValidLensID(mTargetLens.mnItemID))
        {
            mIssue = eIssues.SetLens;
            if (mUpdates % 20 == 0 && mDebug)
            {
                Debug.LogWarning("[Auto Lens Swapper][DEBUG] checkReady Issue: setlens invalid" + isValidLensID(mTargetLens.mnItemID));
            }
            return(false);
        }
        else if (mStoredLenses == null)
        {
            mIssue = eIssues.Input;
            if (mUpdates % 20 == 0 && mDebug)
            {
                Debug.LogWarning("[Auto Lens Swapper][DEBUG] checkReady Issue: stored lenses null" + mStoredLenses.GetDisplayString());
            }
            return(false);
        }
        else if (mStoredLenses.GetAmount() <= 0)
        {
            if (mUpdates % 20 == 0 && mDebug)
            {
                Debug.LogWarning("[Auto Lens Swapper][DEBUG] checkReady Issue: stored lenses 0");
            }
            if (!TakeLensSurrounding())
            {
                mIssue = eIssues.Input;
                if (mUpdates % 20 == 0 && mDebug)
                {
                    Debug.LogWarning("[Auto Lens Swapper][DEBUG] checkReady Issue: Couldn't pull any lenses!");
                }
                return(false);
            }
        }
        else if (mIssue == eIssues.Output)
        {
            if (mUpdates % 20 == 0 && mDebug)
            {
                Debug.LogWarning("[Auto Lens Swapper][DEBUG] checkReady Issue: Couldn't drop-off lenses!");
            }
            if (mLastLPT == null)
            {
                Debug.LogWarning("[Auto Lens Swapper][info] eIssue was output, but then mLastLPT was null! Assuming lpt was deleted and moving on.");
            }
            else if (!runSwapLens(mLastLPT))
            {
                return(false);
            }
            mIssue = eIssues.Ready;
            RequestImmediateNetworkUpdate();
        }
        else if (mIssue != eIssues.Ready)
        {
            mIssue = eIssues.Ready;
            RequestImmediateNetworkUpdate();
        }
        else
        {
            mIssue = eIssues.Ready;
        }
        return(true);
    }