public static bool IsAccessListCompatible(this Pawn p, BodyPartRecord bpr, MTWDef mTWDef, bool debug = false)
        {
            if (mTWDef.HasApplyList && p.PartOrAnyAncestorHasHediff(bpr, mTWDef.applyThoughtHediffList))
            {
                if (debug)
                {
                    Log.Warning(p.LabelShort + " " + bpr.Label + " is in apply list");
                }
                return(true);
            }


            if (mTWDef.HasIgnoreList && p.PartOrAnyAncestorHasHediff(bpr, mTWDef.ignoreThoughtHediffList))
            {
                if (debug)
                {
                    Log.Warning(p.LabelShort + " " + bpr.Label + " is in ignore list");
                }
                return(false);
            }

            if (debug)
            {
                Log.Warning(p.LabelShort + " " + bpr.Label + " is ACL compatible");
            }
            return(true);
        }
        public static bool ValidateBP(this MTWDef mtwDef, BodyPartRecord BPR)
        {
            if (mtwDef.HasBodyPartDefTarget)
            {
                return(mtwDef.bodyPart == BPR.def);
            }
            else if (mtwDef.HasBodyPartLabelTarget)
            {
                return(mtwDef.bodyPartLabel == BPR.customLabel);
            }

            return(false);
        }
        protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            //Log.Warning(p.LabelShort + " Entering RaceBPHediff " + p.def);

            MTWDef myTWD =
                DefDatabase <MTWDef> .AllDefs
                .Where(
                    m =>
                    m.race == p.def &&
                    def == m.thought &&
                    m.HasTarget &&
                    (m.HasLifeStages ? m.lifeStages.Contains(p.ageTracker.CurLifeStage) : true)
                    ).SingleOrDefault();

            if (myTWD == null)
            {
                return(false);
            }

            //Log.Warning(p.LabelShort + " found TWD");

            IEnumerable <Hediff> HA = p.health.hediffSet.hediffs
                                      .Where(h =>
                                             h.Part != null &&
                                             myTWD.ValidateBP(h.Part) &&
                                             //h.def == myTWD.hediff
                                             (h.def == myTWD.hediff || (myTWD.HasApplyList && myTWD.applyThoughtHediffList.Contains(h.def)))
                                             );

            if (HA.EnumerableNullOrEmpty())
            {
                return(false);
            }

            if (myTWD.ignoreThoughtIfAddedPart)
            {
                HA = HA
                     .Where(h =>
                            !p.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(h.Part)
                            );
            }
            else if (myTWD.HasAccessList)
            {
                HA = HA
                     .Where(h =>
                            p.IsAccessListCompatible(h.Part, myTWD, myTWD.debug)
                            );
            }

            if (HA.EnumerableNullOrEmpty())
            {
                return(false);
            }

            if (myTWD.HasRequiredBpNum)
            {
                return(myTWD.bpNum.Includes(HA.EnumerableCount()));
            }

            return(false);
        }