public Thing                        TryProduceThingDef(ThingDef thingDef)
        {
            //Log.Message( string.Format( "{0}.TryProduceThingDef( {1} )", this.ThingID, thingDef == null ? "null" : thingDef.defName ) );
            var recipe = FindRecipeForProduct(thingDef);

            if (recipe == null)
            {
                return((Thing)null);
            }
            var chosen = new List <ThingAmount>();

            if (!CompHopperUser.RemoveResourcesFromHoppers(recipe, chosen))
            {
                return(null);
            }
            var thing = ThingMaker.MakeThing(thingDef);

            thing.stackCount = recipe.products[0].count;
            var ingredients = thing.TryGetComp <CompIngredients>();

            if (ingredients != null)
            {
                foreach (var ingredient in chosen)
                {
                    ingredients.RegisterIngredient(ingredient.thing.def);
                }
            }
            return(thing);
        }
        public Thing                        TryProduceThingDef(ThingDef thingDef)
        {
            //Log.Message( string.Format( "{0}.TryProduceThingDef( {1} )", this.ThingID, thingDef == null ? "null" : thingDef.defName ) );
            var recipe = FindRecipeForProduct(thingDef);

            if (recipe == null)
            {
                return((Thing)null);
            }
            List <ThingAmount> chosen = new List <ThingAmount>();

            if (!CompHopperUser.RemoveResourcesFromHoppers(recipe, chosen))
            {
                return(null);
            }
            var thing = ThingMaker.MakeThing(thingDef);

            thing.stackCount = recipe.products[0].count;
            if (
                (thingDef.thingClass == typeof(Meal)) ||
                (thingDef.thingClass.IsSubclassOf(typeof(Meal)))
                )
            {
                var meal = (Meal)thing;
                foreach (var ingredient in chosen)
                {
                    meal.RegisterIngredient(ingredient.thing.def);
                }
            }
            return(thing);
        }