public override void DoSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, IItemSlot inputSlot, IItemSlot outputSlot)
        {
            ItemStack[] stacks = GetCookingStacks(cookingSlotsProvider);

            CookingRecipe recipe = GetMatchingCookingRecipe(world, stacks);

            Block     block       = world.GetBlock(CodeWithPath(FirstCodePart() + "-cooked"));
            ItemStack outputStack = new ItemStack(block);

            if (recipe != null)
            {
                int quantityServings = recipe.GetQuantityServings(stacks);
                for (int i = 0; i < stacks.Length; i++)
                {
                    stacks[i].StackSize /= quantityServings;
                }
                // Not active. Let's sacrifice mergability for letting players select how meals should look and named like
                //stacks = stacks.OrderBy(stack => stack.Collectible.Code.ToShortString()).ToArray(); // Required so that different arrangments of ingredients still create mergable meal bowls

                ((BlockCookedContainer)block).SetContents(recipe.Code, quantityServings, outputStack, stacks);

                outputStack.Collectible.SetTemperature(world, outputStack, GetIngredientsTemperature(world, stacks));
                outputSlot.Itemstack = outputStack;
                inputSlot.Itemstack  = null;

                for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++)
                {
                    cookingSlotsProvider.Slots[i].Itemstack = null;
                }
                return;
            }
        }
Example #2
0
        public string GetOutputText(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot)
        {
            if (inputSlot.Itemstack == null)
            {
                return(null);
            }
            if (!(inputSlot.Itemstack.Collectible is BlockCookingContainer))
            {
                return(null);
            }

            ItemStack[] stacks = GetCookingStacks(cookingSlotsProvider);

            CookingRecipe recipe = GetMatchingCookingRecipe(world, stacks);

            if (recipe != null)
            {
                double quantity = recipe.GetQuantityServings(stacks);
                if (quantity != 1)
                {
                    return(Lang.Get("mealcreation-makeplural", (int)quantity, recipe.GetOutputName(world, stacks).ToLowerInvariant()));
                }
                else
                {
                    return(Lang.Get("mealcreation-makesingular", (int)quantity, recipe.GetOutputName(world, stacks).ToLowerInvariant()));
                }
            }

            return(null);
        }
        public override string GetBlockInfo(IPlayer forPlayer)
        {
            ItemStack[]   contentStacks = GetContentStacks();
            CookingRecipe recipe        = api.World.CookingRecipes.FirstOrDefault(rec => rec.Code == RecipeCode);

            if (recipe == null)
            {
                return(null);
            }

            int    servings   = QuantityServings;
            int    temp       = GetTemperature();
            string temppretty = Lang.Get("{0}°C", temp);

            if (temp < 20)
            {
                temppretty = "Cold";
            }

            BlockMeal mealblock  = api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;
            string    nutriFacts = mealblock.GetContentNutritionFacts(api.World, contentStacks, forPlayer.Entity);

            if (servings == 1)
            {
                return(Lang.Get("{0} serving of {1}\nTemperature: {2}{3}{4}", servings, recipe.GetOutputName(forPlayer.Entity.World, contentStacks), temppretty, nutriFacts != null ? "\n" : "", nutriFacts));
            }
            else
            {
                return(Lang.Get("{0} servings of {1}\nTemperature: {2}{3}{4}", servings, recipe.GetOutputName(forPlayer.Entity.World, contentStacks), temppretty, nutriFacts != null ? "\n" : "", nutriFacts));
            }
        }
Example #4
0
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);

            CookingRecipe recipe   = GetMealRecipe(world, inSlot.Itemstack);
            float         servings = inSlot.Itemstack.Attributes.GetFloat("quantityServings");

            ItemStack[] stacks = GetContents(world, inSlot.Itemstack);

            DummySlot firstContentItemSlot = new DummySlot(stacks != null && stacks.Length > 0 ? stacks[0] : null, inSlot.Inventory);

            if (recipe != null)
            {
                if (servings == 1)
                {
                    dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks)));
                }
                else
                {
                    dsc.AppendLine(Lang.Get("{0} servings of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks)));
                }
            }

            BlockMeal mealblock  = api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;
            string    nutriFacts = mealblock.GetContentNutritionFacts(api.World, inSlot, stacks, null);

            if (nutriFacts != null)
            {
                dsc.AppendLine(nutriFacts);
            }

            firstContentItemSlot.Itemstack?.Collectible.AppendPerishableInfoText(firstContentItemSlot, dsc, world);
        }
Example #5
0
        public MeshRef GetOrCreateMealInContainerMeshRef(Block containerBlock, CookingRecipe forRecipe, ItemStack[] contentStacks, Vec3f foodTranslate = null)
        {
            Dictionary <int, MeshRef> meshrefs;

            object obj;

            if (capi.ObjectCache.TryGetValue("cookedMeshRefs", out obj))
            {
                meshrefs = obj as Dictionary <int, MeshRef>;
            }
            else
            {
                capi.ObjectCache["cookedMeshRefs"] = meshrefs = new Dictionary <int, MeshRef>();
            }

            if (contentStacks == null)
            {
                return(null);
            }

            int mealhashcode = GetMealHashCode(containerBlock, contentStacks, foodTranslate);

            MeshRef mealMeshRef;

            if (!meshrefs.TryGetValue(mealhashcode, out mealMeshRef))
            {
                MeshData mesh = GenMealInContainerMesh(containerBlock, forRecipe, contentStacks, foodTranslate);

                meshrefs[mealhashcode] = mealMeshRef = capi.Render.UploadMesh(mesh);
            }

            return(mealMeshRef);
        }
        public override void GetHeldItemInfo(ItemStack stack, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            base.GetHeldItemInfo(stack, dsc, world, withDebugInfo);

            CookingRecipe recipe = GetMealRecipe(world, stack);

            int servings = stack.Attributes.GetInt("servings");

            if (recipe != null)
            {
                if (servings == 1)
                {
                    dsc.AppendLine(Lang.Get("{0} serving of {1}", servings, recipe.GetOutputName(world, GetContents(world, stack))));
                }
                else
                {
                    dsc.AppendLine(Lang.Get("{0} servings of {1}", servings, recipe.GetOutputName(world, GetContents(world, stack))));
                }
            }

            BlockMeal mealblock  = api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;
            string    nutriFacts = mealblock.GetContentNutritionFacts(api.World, GetContents(world, stack), null);

            if (nutriFacts != null)
            {
                dsc.AppendLine(nutriFacts);
            }
        }
Example #7
0
        public MeshRef GetOrCreateMealMeshRef(CompositeShape containerShape, CookingRecipe forRecipe, ItemStack[] contentStacks, Vec3f foodTranslate = null)
        {
            Dictionary <int, MeshRef> meshrefs = null;

            object obj;

            if (capi.ObjectCache.TryGetValue("cookedMeshRefs", out obj))
            {
                meshrefs = obj as Dictionary <int, MeshRef>;
            }
            else
            {
                capi.ObjectCache["cookedMeshRefs"] = meshrefs = new Dictionary <int, MeshRef>();
            }

            if (contentStacks == null)
            {
                return(null);
            }

            int mealhashcode = GetMealHashCode(containerShape, capi.World, contentStacks);

            MeshRef mealMeshRef = null;

            if (!meshrefs.TryGetValue(mealhashcode, out mealMeshRef))
            {
                meshrefs[mealhashcode] = mealMeshRef = capi.Render.UploadMesh(CreateMealMesh(containerShape, forRecipe, contentStacks, foodTranslate));
            }

            return(mealMeshRef);
        }
Example #8
0
        public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
        {
            BlockEntityCrock becrock = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCrock;

            if (becrock == null)
            {
                return(null);
            }

            BlockMeal mealblock = world.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;

            CookingRecipe recipe = world.CookingRecipes.FirstOrDefault((rec) => becrock.RecipeCode == rec.Code);

            ItemStack[] stacks = becrock.inventory.Where(slot => !slot.Empty).Select(slot => slot.Itemstack).ToArray();

            if (stacks == null || stacks.Length == 0)
            {
                return("Empty");
            }

            StringBuilder dsc = new StringBuilder();

            if (recipe != null)
            {
                DummySlot firstContentItemSlot = new DummySlot(stacks != null && stacks.Length > 0 ? stacks[0] : null, becrock.inventory);

                if (recipe != null)
                {
                    dsc.AppendLine(recipe.GetOutputName(world, stacks).UcFirst());
                }

                string facts = mealblock.GetContentNutritionFacts(world, new DummySlot(OnPickBlock(world, pos)), null);

                if (facts != null)
                {
                    dsc.Append(facts);
                }

                firstContentItemSlot.Itemstack?.Collectible.AppendPerishableInfoText(firstContentItemSlot, dsc, world);
            }
            else
            {
                dsc.AppendLine("Contents:");
                foreach (var stack in stacks)
                {
                    if (stack == null)
                    {
                        continue;
                    }

                    dsc.AppendLine(stack.StackSize + "x  " + stack.GetName());
                }

                becrock.inventory[0].Itemstack.Collectible.AppendPerishableInfoText(becrock.inventory[0], dsc, api.World);
            }


            return(dsc.ToString());
        }
Example #9
0
        public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc)
        {
            CookingRecipe recipe = FromRecipe;

            if (recipe == null)
            {
                if (inventory.Count > 0 && !inventory[0].Empty)
                {
                    dsc.AppendLine(inventory[0].StackSize + "x " + inventory[0].Itemstack.GetName());
                }

                return;
            }


            dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(QuantityServings, 1), recipe.GetOutputName(forPlayer.Entity.World, GetNonEmptyContentStacks()).UcFirst()));

            if (ownBlock == null)
            {
                return;
            }


            int    temp       = GetTemperature();
            string temppretty = Lang.Get("{0}°C", temp);

            if (temp < 20)
            {
                temppretty = Lang.Get("Cold");
            }

            dsc.AppendLine(Lang.Get("Temperature: {0}", temppretty));

            string nutriFacts = ownBlock.GetContentNutritionFacts(Api.World, inventory[0], GetNonEmptyContentStacks(false), forPlayer.Entity);

            if (nutriFacts != null)
            {
                dsc.Append(nutriFacts);
            }


            foreach (var slot in inventory)
            {
                if (slot.Empty)
                {
                    continue;
                }

                TransitionableProperties[] propsm = slot.Itemstack.Collectible.GetTransitionableProperties(Api.World, slot.Itemstack, null);
                if (propsm != null && propsm.Length > 0)
                {
                    slot.Itemstack.Collectible.AppendPerishableInfoText(slot, dsc, Api.World);
                    break;
                }
            }
        }
Example #10
0
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            float temp = GetTemperature(world, inSlot.Itemstack);

            if (temp > 20)
            {
                dsc.AppendLine(Lang.Get("Temperature: {0}°C", (int)temp));
            }

            CookingRecipe recipe = GetCookingRecipe(world, inSlot.Itemstack);

            ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack);
            ItemSlot    slot   = BlockCrock.GetDummySlotForFirstPerishableStack(world, stacks, null, inSlot.Inventory);

            slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world);

            float servings = GetQuantityServings(world, inSlot.Itemstack);

            if (recipe != null)
            {
                if (Math.Round(servings, 1) < 0.05)
                {
                    dsc.AppendLine(Lang.Get("{1}% serving of {0}", recipe.GetOutputName(world, stacks).UcFirst(), Math.Round(servings * 100, 0)));
                }
                else
                {
                    dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks).UcFirst()));
                }
            }
            else
            {
                if (inSlot.Itemstack.Attributes.HasAttribute("quantityServings"))
                {
                    dsc.AppendLine(Lang.Get("{0} servings left", Math.Round(servings, 1)));
                }
                else if (displayContentsInfo)
                {
                    dsc.AppendLine(Lang.Get("Contents:"));
                    if (stacks != null && stacks.Length > 0)
                    {
                        dsc.AppendLine(stacks[0].StackSize + "x " + stacks[0].GetName());
                    }
                }
            }

            if (!MealMeshCache.ContentsRotten(stacks))
            {
                string facts = GetContentNutritionFacts(world, inSlot, null, recipe == null);

                if (facts != null)
                {
                    dsc.Append(facts);
                }
            }
        }
Example #11
0
        public MeshData GenMealMesh(CookingRecipe forRecipe, ItemStack[] contentStacks, Vec3f foodTranslate = null)
        {
            MealTextureSource source = new MealTextureSource(capi, mealtextureSourceBlock);

            if (forRecipe != null)
            {
                MeshData foodMesh = GenFoodMixMesh(contentStacks, forRecipe, foodTranslate);
                if (foodMesh != null)
                {
                    return(foodMesh);
                }
            }

            if (contentStacks != null && contentStacks.Length > 0)
            {
                bool rotten = ContentsRotten(contentStacks);
                if (rotten)
                {
                    Shape contentShape = capi.Assets.TryGet("shapes/block/food/meal/rot.json").ToObject <Shape>();

                    MeshData contentMesh;
                    capi.Tesselator.TesselateShape("rotcontents", contentShape, out contentMesh, source);

                    if (foodTranslate != null)
                    {
                        contentMesh.Translate(foodTranslate);
                    }

                    return(contentMesh);
                }
                else
                {
                    JsonObject obj = contentStacks[0]?.ItemAttributes?["inContainerTexture"];
                    if (obj != null && obj.Exists)
                    {
                        source.ForStack = contentStacks[0];

                        CompositeShape cshape = contentStacks[0]?.ItemAttributes?["inBowlShape"].AsObject <CompositeShape>(new CompositeShape()
                        {
                            Base = new AssetLocation("shapes/block/food/meal/pickled.json")
                        });

                        Shape    contentShape = capi.Assets.TryGet(cshape.Base.WithPathAppendixOnce(".json").WithPathPrefixOnce("shapes/")).ToObject <Shape>();
                        MeshData contentMesh;
                        capi.Tesselator.TesselateShape("picklednmealcontents", contentShape, out contentMesh, source);

                        return(contentMesh);
                    }
                }
            }

            return(null);
        }
Example #12
0
        public override void DoSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot, ItemSlot outputSlot)
        {
            ItemStack[]   stacks = GetCookingStacks(cookingSlotsProvider);
            CookingRecipe recipe = GetMatchingCookingRecipe(world, stacks);

            Block     block       = world.GetBlock(CodeWithVariant("type", "cooked"));
            ItemStack outputStack = new ItemStack(block);

            if (recipe != null)
            {
                int quantityServings = recipe.GetQuantityServings(stacks);

                for (int i = 0; i < stacks.Length; i++)
                {
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(stacks[i]);
                    ItemStack cookedStack          = ingred.GetMatchingStack(stacks[i])?.CookedStack?.ResolvedItemstack.Clone();
                    if (cookedStack != null)
                    {
                        stacks[i] = cookedStack;
                    }
                }

                // Carry over and set perishable properties
                TransitionableProperties cookedPerishProps = recipe.PerishableProps.Clone();
                cookedPerishProps.TransitionedStack.Resolve(world, "cooking container perished stack");

                CarryOverFreshness(api, cookingSlotsProvider.Slots, stacks, cookedPerishProps);

                for (int i = 0; i < stacks.Length; i++)
                {
                    stacks[i].StackSize /= quantityServings; // whats this good for? Probably doesn't do anything meaningful
                }



                // Disabled. Let's sacrifice mergability for letting players select how meals should look and be named like
                //stacks = stacks.OrderBy(stack => stack.Collectible.Code.ToShortString()).ToArray(); // Required so that different arrangments of ingredients still create mergable meal bowls

                ((BlockCookedContainer)block).SetContents(recipe.Code, quantityServings, outputStack, stacks);

                outputStack.Collectible.SetTemperature(world, outputStack, GetIngredientsTemperature(world, stacks));
                outputSlot.Itemstack = outputStack;
                inputSlot.Itemstack  = null;

                for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++)
                {
                    cookingSlotsProvider.Slots[i].Itemstack = null;
                }
                return;
            }
        }
        public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc)
        {
            ItemStack[]   contentStacks = GetNonEmptyContentStacks();
            CookingRecipe recipe        = Api.GetCookingRecipes().FirstOrDefault(rec => rec.Code == RecipeCode);

            if (recipe == null)
            {
                return;
            }

            float  servings   = QuantityServings;
            int    temp       = GetTemperature();
            string temppretty = Lang.Get("{0}°C", temp);

            if (temp < 20)
            {
                temppretty = Lang.Get("Cold");
            }

            BlockMeal mealblock  = Api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;
            string    nutriFacts = mealblock.GetContentNutritionFacts(Api.World, inventory[0], contentStacks, forPlayer.Entity);


            if (servings == 1)
            {
                dsc.Append(Lang.Get("cookedcontainer-servingstemp-singular", Math.Round(servings, 1), recipe.GetOutputName(forPlayer.Entity.World, contentStacks), temppretty, nutriFacts != null ? "\n" : "", nutriFacts));
            }
            else
            {
                dsc.Append(Lang.Get("cookedcontainer-servingstemp-plural", Math.Round(servings, 1), recipe.GetOutputName(forPlayer.Entity.World, contentStacks), temppretty, nutriFacts != null ? "\n" : "", nutriFacts));
            }


            foreach (var slot in inventory)
            {
                if (slot.Empty)
                {
                    continue;
                }

                TransitionableProperties[] propsm = slot.Itemstack.Collectible.GetTransitionableProperties(Api.World, slot.Itemstack, null);
                if (propsm != null && propsm.Length > 0)
                {
                    slot.Itemstack.Collectible.AppendPerishableInfoText(slot, dsc, Api.World);
                    break;
                }
            }
        }
Example #14
0
        public MeshData GenMealInContainerMesh(Block containerBlock, CookingRecipe forRecipe, ItemStack[] contentStacks, Vec3f foodTranslate = null)
        {
            CompositeShape cShape = containerBlock.Shape;
            Shape          shape  = capi.Assets.TryGet("shapes/" + cShape.Base.Path + ".json").ToObject <Shape>();
            MeshData       wholeMesh;

            capi.Tesselator.TesselateShape("meal", shape, out wholeMesh, capi.Tesselator.GetTexSource(containerBlock), new Vec3f(cShape.rotateX, cShape.rotateY, cShape.rotateZ));

            MeshData mealMesh = GenMealMesh(forRecipe, contentStacks, foodTranslate);

            if (mealMesh != null)
            {
                wholeMesh.AddMeshData(mealMesh);
            }

            return(wholeMesh);
        }
Example #15
0
        public MeshData CreateMealMesh(CompositeShape cShape, CookingRecipe forRecipe, ItemStack[] contentStacks, Vec3f foodTranslate = null)
        {
            MealTextureSource source = new MealTextureSource(capi, textureSourceBlock);
            Shape             shape  = capi.Assets.TryGet("shapes/" + cShape.Base.Path + ".json").ToObject <Shape>();

            MeshData containerMesh;

            capi.Tesselator.TesselateShape("meal", shape, out containerMesh, source, new Vec3f(cShape.rotateX, cShape.rotateY, cShape.rotateZ));

            if (forRecipe != null)
            {
                MeshData foodMesh = GenFoodMixMesh(contentStacks, forRecipe, foodTranslate);
                containerMesh.AddMeshData(foodMesh);
            }

            return(containerMesh);
        }
Example #16
0
        public override void GetHeldItemInfo(ItemStack stack, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            base.GetHeldItemInfo(stack, dsc, world, withDebugInfo);

            CookingRecipe recipe = GetCookingRecipe(world, stack);

            if (recipe != null)
            {
                dsc.AppendLine(recipe.GetOutputName(world, GetContents(world, stack)).UcFirst());
            }

            string facts = GetContentNutritionFacts(world, stack, null);

            if (facts != null)
            {
                dsc.Append(facts);
            }
        }
Example #17
0
        public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
        {
            if (meshCache == null)
            {
                meshCache = capi.ModLoader.GetModSystem <MealMeshCache>();
            }

            CookingRecipe recipe = GetCookingRecipe(capi.World, itemstack);

            ItemStack[] contents = GetNonEmptyContents(capi.World, itemstack);

            MeshRef meshref = meshCache.GetOrCreateMealInContainerMeshRef(this, recipe, contents, new Vec3f(0, yoff / 16f, 0));

            if (meshref != null)
            {
                renderinfo.ModelRef = meshref;
            }
        }
Example #18
0
        public MeshData CreateMealMesh(CompositeShape cShape, CookingRecipe forRecipe, ItemStack[] contentStacks, Vec3f foodTranslate = null)
        {
            MealTextureSource source = new MealTextureSource(capi, textureSourceBlock);
            Shape             shape  = capi.Assets.TryGet("shapes/" + cShape.Base.Path + ".json").ToObject <Shape>();

            MeshData containerMesh;

            capi.Tesselator.TesselateShape("meal", shape, out containerMesh, source, new Vec3f(cShape.rotateX, cShape.rotateY, cShape.rotateZ));

            if (forRecipe != null)
            {
                MeshData foodMesh = GenFoodMixMesh(contentStacks, forRecipe, foodTranslate);
                containerMesh.AddMeshData(foodMesh);
            }

            if (contentStacks != null && contentStacks.Length > 0)
            {
                bool rotten = ContentsRotten(contentStacks);
                if (rotten)
                {
                    Shape contentShape = capi.Assets.TryGet("shapes/block/meal/rot.json").ToObject <Shape>();

                    MeshData contentMesh;
                    capi.Tesselator.TesselateShape("rotcontents", contentShape, out contentMesh, source);
                    containerMesh.AddMeshData(contentMesh);
                }
                else
                {
                    JsonObject obj = contentStacks[0]?.ItemAttributes?["inContainerTexture"];
                    if (obj != null && obj.Exists)
                    {
                        source.ForStack = contentStacks[0];

                        Shape    contentShape = capi.Assets.TryGet("shapes/block/meal/pickled.json").ToObject <Shape>();
                        MeshData contentMesh;
                        capi.Tesselator.TesselateShape("picklednmealcontents", contentShape, out contentMesh, source);

                        containerMesh.AddMeshData(contentMesh);
                    }
                }
            }

            return(containerMesh);
        }
        public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
        {
            if (meshCache == null)
            {
                meshCache = capi.ModLoader.GetModSystem <MealMeshCache>();
            }

            CookingRecipe recipe = GetCookingRecipe(capi.World, itemstack);

            ItemStack[] contents = GetContents(capi.World, itemstack);

            float yoff = 2.5f; // itemstack.Attributes.GetInt("servings");

            MeshRef meshref = meshCache.GetOrCreateMealMeshRef(this.Shape, recipe, contents, new Vec3f(0, yoff / 16f, 0));

            if (meshref != null)
            {
                renderinfo.ModelRef = meshref;
            }
        }
        public override string GetBlockInfo(IPlayer forPlayer)
        {
            ItemStack[]   contentStacks = GetNonEmptyContentStacks();
            CookingRecipe recipe        = api.World.CookingRecipes.FirstOrDefault(rec => rec.Code == RecipeCode);

            if (recipe == null)
            {
                return(null);
            }

            float  servings   = QuantityServings;
            int    temp       = GetTemperature();
            string temppretty = Lang.Get("{0}°C", temp);

            if (temp < 20)
            {
                temppretty = "Cold";
            }

            BlockMeal mealblock  = api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;
            string    nutriFacts = mealblock.GetContentNutritionFacts(api.World, inventory[0], contentStacks, forPlayer.Entity);

            StringBuilder dsc = new StringBuilder();

            if (servings == 1)
            {
                dsc.Append(Lang.Get("{0} serving of {1}\nTemperature: {2}{3}{4}", Math.Round(servings, 1), recipe.GetOutputName(forPlayer.Entity.World, contentStacks), temppretty, nutriFacts != null ? "\n" : "", nutriFacts));
            }
            else
            {
                dsc.Append(Lang.Get("{0} servings of {1}\nTemperature: {2}{3}{4}", Math.Round(servings, 1), recipe.GetOutputName(forPlayer.Entity.World, contentStacks), temppretty, nutriFacts != null ? "\n" : "", nutriFacts));
            }


            inventory[0].Itemstack.Collectible.AppendPerishableInfoText(inventory[0], dsc, api.World);

            //dsc.AppendLine(base.GetBlockInfo(forPlayer));


            return(dsc.ToString());
        }
        public string GetContainedInfo(ItemSlot inSlot)
        {
            var world = api.World;

            CookingRecipe recipe   = GetMealRecipe(world, inSlot.Itemstack);
            float         servings = inSlot.Itemstack.Attributes.GetFloat("quantityServings");

            ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack);

            if (stacks.Length == 0)
            {
                return(Lang.Get("Empty {0}", ContainerNameShort));
            }

            if (recipe != null)
            {
                if (servings == 1)
                {
                    return(Lang.Get("{0} serving of {1} in {2}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks), ContainerNameShort));
                }
                else
                {
                    return(Lang.Get("{0:0.#} servings of {1} in {2}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks), ContainerNameShort));
                }
            }

            StringBuilder sb = new StringBuilder();

            foreach (var stack in stacks)
            {
                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(stack.GetName());
            }
            sb.Append(Lang.Get(" in {0}", ContainerNameShort));

            return(sb.ToString());
        }
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            //base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);
            float temp = GetTemperature(world, inSlot.Itemstack);

            if (temp > 20)
            {
                dsc.AppendLine(Lang.Get("Temperature: {0}°C", (int)temp));
            }

            CookingRecipe recipe   = GetMealRecipe(world, inSlot.Itemstack);
            float         servings = inSlot.Itemstack.Attributes.GetFloat("quantityServings");

            ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack);


            if (recipe != null)
            {
                if (servings == 1)
                {
                    dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks)));
                }
                else
                {
                    dsc.AppendLine(Lang.Get("{0} servings of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks)));
                }
            }

            BlockMeal mealblock  = api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;
            string    nutriFacts = mealblock.GetContentNutritionFacts(api.World, inSlot, stacks, null);

            if (nutriFacts != null)
            {
                dsc.AppendLine(nutriFacts);
            }

            ItemSlot slot = BlockCrock.GetDummySlotForFirstPerishableStack(api.World, stacks, null, inSlot.Inventory);

            slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world);
        }
Example #23
0
        public override string GetBlockInfo(IPlayer forPlayer)
        {
            CookingRecipe recipe = FromRecipe;

            if (recipe == null)
            {
                return("Unknown recipe :O");
            }

            StringBuilder dsc = new StringBuilder();

            dsc.AppendLine(recipe.GetOutputName(forPlayer.Entity.World, GetContentStacks()).UcFirst());

            if (ownBlock == null)
            {
                return(dsc.ToString());
            }


            int    temp       = GetTemperature();
            string temppretty = Lang.Get("{0}°C", temp);

            if (temp < 20)
            {
                temppretty = "Cold";
            }

            dsc.AppendLine(Lang.Get("Temperature: {0}", temppretty));

            string nutriFacts = ownBlock.GetContentNutritionFacts(api.World, ownBlock.OnPickBlock(api.World, pos), forPlayer.Entity);

            if (nutriFacts != null)
            {
                dsc.Append(nutriFacts);
            }


            return(dsc.ToString());
        }
Example #24
0
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);

            CookingRecipe recipe = GetCookingRecipe(world, inSlot.Itemstack);

            ItemStack[] stacks = GetContents(world, inSlot.Itemstack);
            DummySlot   firstContentItemSlot = new DummySlot(stacks != null && stacks.Length > 0 ? stacks[0] : null);

            float servings = GetQuantityServings(world, inSlot.Itemstack);

            if (recipe != null)
            {
                if (Math.Round(servings, 1) < 0.05)
                {
                    dsc.AppendLine(Lang.Get("<5% serving of {1}", recipe.GetOutputName(world, stacks).UcFirst()));
                }
                else
                {
                    dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks).UcFirst()));
                }
            }
            else
            {
                if (stacks != null && stacks.Length > 0)
                {
                    dsc.AppendLine(stacks[0].StackSize + "x " + stacks[0].GetName());
                }
            }

            string facts = GetContentNutritionFacts(world, inSlot, null, true);

            if (facts != null)
            {
                dsc.Append(facts);
            }

            firstContentItemSlot.Itemstack?.Collectible.AppendPerishableInfoText(firstContentItemSlot, dsc, world);
        }
Example #25
0
        public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
        {
            BlockEntityCrock becrock = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCrock;

            if (becrock == null)
            {
                return(null);
            }

            BlockMeal mealblock = world.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;

            CookingRecipe recipe = world.CookingRecipes.FirstOrDefault((rec) => becrock.RecipeCode == rec.Code);

            ItemStack[] stacks = becrock.inventory.Where(slot => !slot.Empty).Select(slot => slot.Itemstack).ToArray();

            if (stacks == null || stacks.Length == 0)
            {
                return("Empty");
            }

            StringBuilder dsc = new StringBuilder();

            if (recipe != null)
            {
                ItemSlot slot = GetDummySlotForFirstPerishableStack(api.World, stacks, forPlayer.Entity, becrock.inventory);

                if (recipe != null)
                {
                    if (becrock.QuantityServings == 1)
                    {
                        dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(becrock.QuantityServings, 1), recipe.GetOutputName(world, stacks)));
                    }
                    else
                    {
                        dsc.AppendLine(Lang.Get("{0} servings of {1}", Math.Round(becrock.QuantityServings, 1), recipe.GetOutputName(world, stacks)));
                    }
                }

                string facts = mealblock.GetContentNutritionFacts(world, new DummySlot(OnPickBlock(world, pos)), null);

                if (facts != null)
                {
                    dsc.Append(facts);
                }

                slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world);
            }
            else
            {
                dsc.AppendLine("Contents:");
                foreach (var stack in stacks)
                {
                    if (stack == null)
                    {
                        continue;
                    }

                    dsc.AppendLine(stack.StackSize + "x  " + stack.GetName());
                }

                becrock.inventory[0].Itemstack?.Collectible.AppendPerishableInfoText(becrock.inventory[0], dsc, api.World);
            }

            if (becrock.Sealed)
            {
                dsc.AppendLine("<font color=\"lightgreen\">" + Lang.Get("Sealed.") + "</font>");
            }


            return(dsc.ToString());
        }
Example #26
0
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);

            BlockMeal mealblock = world.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal;

            CookingRecipe recipe = GetCookingRecipe(world, inSlot.Itemstack);

            ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack);

            if (stacks == null || stacks.Length == 0)
            {
                dsc.AppendLine("Empty");
                return;
            }

            DummyInventory dummyInv = new DummyInventory(api);

            ItemSlot slot = GetDummySlotForFirstPerishableStack(api.World, stacks, null, dummyInv);

            dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) =>
            {
                float val = mul * GetContainingTransitionModifierContained(world, inSlot, transType);

                val *= inSlot.Inventory.GetTransitionSpeedMul(transType, inSlot.Itemstack);

                return(val);
            };


            if (recipe != null)
            {
                double servings = inSlot.Itemstack.Attributes.GetDecimal("quantityServings");

                if (recipe != null)
                {
                    if (servings == 1)
                    {
                        dsc.AppendLine(Lang.Get("{0} serving of {1}", servings, recipe.GetOutputName(world, stacks)));
                    }
                    else
                    {
                        dsc.AppendLine(Lang.Get("{0} servings of {1}", servings, recipe.GetOutputName(world, stacks)));
                    }
                }

                string facts = mealblock.GetContentNutritionFacts(world, inSlot, null);
                if (facts != null)
                {
                    dsc.Append(facts);
                }
            }
            else
            {
                dsc.AppendLine("Contents:");
                foreach (var stack in stacks)
                {
                    if (stack == null)
                    {
                        continue;
                    }

                    dsc.AppendLine(stack.StackSize + "x  " + stack.GetName());
                }
            }


            slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world);

            if (inSlot.Itemstack.Attributes.GetBool("sealed"))
            {
                dsc.AppendLine("<font color=\"lightgreen\">" + Lang.Get("Sealed.") + "</font>");
            }
        }
Example #27
0
        public MeshData GenFoodMixMesh(ItemStack[] contentStacks, CookingRecipe recipe, Vec3f foodTranslate)
        {
            MeshData          mergedmesh = null;
            MealTextureSource texSource  = new MealTextureSource(capi, mealtextureSourceBlock);

            var shapePath = recipe.Shape.Base.Clone().WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json");

            bool rotten = ContentsRotten(contentStacks);

            if (rotten)
            {
                shapePath = new AssetLocation("shapes/block/food/meal/rot.json");
            }

            Shape shape = capi.Assets.TryGet(shapePath).ToObject <Shape>();
            Dictionary <CookingRecipeIngredient, int> usedIngredQuantities = new Dictionary <CookingRecipeIngredient, int>();

            if (rotten)
            {
                capi.Tesselator.TesselateShape(
                    "mealpart", shape, out mergedmesh, texSource,
                    new Vec3f(recipe.Shape.rotateX, recipe.Shape.rotateY, recipe.Shape.rotateZ)
                    );
            }
            else
            {
                HashSet <string> drawnMeshes = new HashSet <string>();

                for (int i = 0; i < contentStacks.Length; i++)
                {
                    texSource.ForStack = contentStacks[i];
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(
                        contentStacks[i],
                        usedIngredQuantities.Where(val => val.Key.MaxQuantity <= val.Value).Select(val => val.Key).ToArray()
                        );

                    if (ingred == null)
                    {
                        ingred = recipe.GetIngrendientFor(contentStacks[i]);
                    }
                    else
                    {
                        int cnt = 0;
                        usedIngredQuantities.TryGetValue(ingred, out cnt);
                        cnt++;
                        usedIngredQuantities[ingred] = cnt;
                    }

                    if (ingred == null)
                    {
                        continue;
                    }


                    MeshData meshpart;
                    string[] selectiveElements = null;

                    CookingRecipeStack recipestack = ingred.GetMatchingStack(contentStacks[i]);

                    if (recipestack.ShapeElement != null)
                    {
                        selectiveElements = new string[] { recipestack.ShapeElement }
                    }
                    ;
                    texSource.customTextureMapping = recipestack.TextureMapping;

                    if (drawnMeshes.Contains(recipestack.ShapeElement + recipestack.TextureMapping))
                    {
                        continue;
                    }
                    drawnMeshes.Add(recipestack.ShapeElement + recipestack.TextureMapping);

                    capi.Tesselator.TesselateShape(
                        "mealpart", shape, out meshpart, texSource,
                        new Vec3f(recipe.Shape.rotateX, recipe.Shape.rotateY, recipe.Shape.rotateZ), 0, 0, 0, null, selectiveElements
                        );

                    if (mergedmesh == null)
                    {
                        mergedmesh = meshpart;
                    }
                    else
                    {
                        mergedmesh.AddMeshData(meshpart);
                    }
                }
            }


            if (foodTranslate != null && mergedmesh != null)
            {
                mergedmesh.Translate(foodTranslate);
            }

            return(mergedmesh);
        }
Example #28
0
        /// <summary>
        /// Gets the name for ingredients in regards to food.
        /// </summary>
        /// <param name="worldForResolve">The world to resolve in.</param>
        /// <param name="recipeCode">The recipe code.</param>
        /// <param name="stacks">The stacks of items to add.</param>
        /// <returns>The name of the food type.</returns>
        public string GetNameForIngredients(IWorldAccessor worldForResolve, string recipeCode, ItemStack[] stacks)
        {
            OrderedDictionary <ItemStack, int> quantitiesByStack = new OrderedDictionary <ItemStack, int>();

            quantitiesByStack = mergeStacks(worldForResolve, stacks);

            CookingRecipe recipe = worldForResolve.Api.GetCookingRecipes().FirstOrDefault(rec => rec.Code == recipeCode);

            if (recipeCode == null || recipe == null || quantitiesByStack.Count == 0)
            {
                return("unknown");
            }

            int           max                 = 1;
            string        MealFormat          = "meal";
            string        topping             = string.Empty;
            ItemStack     PrimaryIngredient   = null;
            ItemStack     SecondaryIngredient = null;
            List <string> OtherIngredients    = new List <string>();
            List <string> MashedNames         = new List <string>();
            List <string> GarnishedNames      = new List <string>();
            List <string> grainNames          = new List <string>();
            string        mainIngredients;
            string        everythingelse = "";



            switch (recipeCode)
            {
            case "soup":
            {
                max = 0;
                foreach (var val in quantitiesByStack)
                {
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key);
                    if (val.Key.Collectible.Code.Path.Contains("waterportion"))
                    {
                        continue;
                    }
                    if (ingred?.Code == "topping")
                    {
                        topping = "honeyportion";
                        continue;
                    }


                    if (max < val.Value)
                    {
                        max = val.Value;
                        if (PrimaryIngredient != null)
                        {
                            SecondaryIngredient = PrimaryIngredient;
                        }
                        PrimaryIngredient = val.Key;
                    }
                    else
                    {
                        OtherIngredients.Add(ingredientName(val.Key, true));
                    }
                }

                if (max == 2)
                {
                    max = 3;
                }
                else if (max == 3)
                {
                    max = 4;
                }
                else
                {
                    max = 2;
                }

                break;
            }

            case "porridge":
            {
                max = 0;
                foreach (var val in quantitiesByStack)
                {
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key);
                    if (getFoodCat(val.Key) == EnumFoodCategory.Grain)
                    {
                        max++;
                        if (PrimaryIngredient == null)
                        {
                            PrimaryIngredient = val.Key;
                        }
                        else if (SecondaryIngredient == null && val.Key != PrimaryIngredient)
                        {
                            SecondaryIngredient = val.Key;
                        }

                        continue;
                    }

                    if (ingred?.Code == "topping")
                    {
                        topping = "honeyportion";
                        continue;
                    }

                    MashedNames.Add(ingredientName(val.Key, true));
                }
                break;
            }

            case "meatystew":
            {
                max = 0;
                foreach (var val in quantitiesByStack)
                {
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key);

                    EnumFoodCategory foodCat = getFoodCat(val.Key);

                    if (foodCat == EnumFoodCategory.Protein)
                    {
                        if (PrimaryIngredient == val.Key || SecondaryIngredient == val.Key)
                        {
                            continue;
                        }

                        if (PrimaryIngredient == null)
                        {
                            PrimaryIngredient = val.Key;
                        }
                        else if (SecondaryIngredient == null)
                        {
                            SecondaryIngredient = val.Key;
                        }
                        else
                        {
                            OtherIngredients.Add(ingredientName(val.Key, true));
                        }

                        max += val.Value;

                        continue;
                    }


                    if (ingred?.Code == "topping")
                    {
                        topping = "honeyportion";
                        continue;
                    }

                    OtherIngredients.Add(ingredientName(val.Key, true));
                }

                recipeCode = "stew";
                break;
            }

            case "vegetablestew":
            {
                max = 0;

                foreach (var val in quantitiesByStack)
                {
                    if (getFoodCat(val.Key) == EnumFoodCategory.Vegetable)
                    {
                        if (PrimaryIngredient == val.Key || SecondaryIngredient == val.Key)
                        {
                            continue;
                        }

                        if (PrimaryIngredient == null)
                        {
                            PrimaryIngredient = val.Key;
                        }
                        else if (SecondaryIngredient == null)
                        {
                            SecondaryIngredient = val.Key;
                        }
                        else
                        {
                            GarnishedNames.Add(ingredientName(val.Key, true));
                        }

                        max += val.Value;

                        continue;
                    }
                    GarnishedNames.Add(ingredientName(val.Key, true));
                }

                // Slightly ugly hack for soybean stew
                if (PrimaryIngredient == null)
                {
                    foreach (var val in quantitiesByStack)
                    {
                        //CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key); - whats this for?
                        PrimaryIngredient = val.Key;
                        max += val.Value;
                    }
                }

                recipeCode = "stew";
                break;
            }



            case "scrambledeggs":
            {
                max = 0;

                foreach (var val in quantitiesByStack)
                {
                    if (val.Key.Collectible.FirstCodePart() == "egg")
                    {
                        PrimaryIngredient = val.Key;
                        max += val.Value;
                        continue;
                    }

                    GarnishedNames.Add(ingredientName(val.Key, true));
                }


                recipeCode = "scrambledeggs";
                break;
            }


            case "jam":
            {
                ItemStack[] fruits = new ItemStack[2];
                int         i      = 0;
                foreach (var val in quantitiesByStack)
                {
                    if (val.Key.Collectible.NutritionProps?.FoodCategory == EnumFoodCategory.Fruit)
                    {
                        fruits[i++] = val.Key;
                        if (i == 2)
                        {
                            break;
                        }
                    }
                }

                if (fruits[1] != null)
                {
                    return(Lang.Get("mealname-mixedjam", fruits[0].GetName(), fruits[1].GetName()));
                }
                else
                {
                    string jamName          = fruits[0].Collectible.LastCodePart() + "-jam";
                    string jamNameLocalised = Lang.Get(jamName);
                    if (jamName != jamNameLocalised)
                    {
                        return(jamNameLocalised);
                    }
                    return(Lang.Get("mealname-singlejam", fruits[0].GetName()));
                }
            }
            }



            switch (max)
            {
            case 3:
                MealFormat += "-hearty-" + recipeCode;
                break;

            case 4:
                MealFormat += "-hefty-" + recipeCode;
                break;

            default:
                MealFormat += "-normal-" + recipeCode;
                break;
            }

            if (topping == "honeyportion")
            {
                MealFormat += "-honey";
            }
            //mealformat is done.  Time to do the main inredients.



            if (SecondaryIngredient != null && recipeCode != "scrambledeggs")
            {
                mainIngredients = Lang.Get("multi-main-ingredients-format", getMainIngredientName(PrimaryIngredient, recipeCode), getMainIngredientName(SecondaryIngredient, recipeCode, true));
            }
            else
            {
                mainIngredients = PrimaryIngredient == null ? "" : getMainIngredientName(PrimaryIngredient, recipeCode);
            }


            switch (recipeCode)
            {
            case "porridge":
                if (MashedNames.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-porridge-mashed", MashedNames);
                }
                else
                {
                    everythingelse = "";
                }
                break;

            case "stew":
                if (OtherIngredients.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-meatystew-boiled", OtherIngredients);
                }
                else if (GarnishedNames.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-vegetablestew-garnish", GarnishedNames);
                }
                else
                {
                    everythingelse = "";
                }
                break;

            case "scrambledeggs":
                if (GarnishedNames.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-vegetablestew-garnish", GarnishedNames);
                }
                return(Lang.Get(MealFormat, everythingelse).Trim().UcFirst());

            case "soup":
                if (OtherIngredients.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-generic", OtherIngredients);
                }
                break;
            }
            //everything else is done.

            return(Lang.Get(MealFormat, mainIngredients, everythingelse).Trim().UcFirst());
        }
Example #29
0
        public MeshData GenFoodMixMesh(ItemStack[] contentStacks, CookingRecipe recipe, Vec3f foodTranslate)
        {
            MeshData          mergedmesh = null;
            MealTextureSource texSource  = new MealTextureSource(capi, textureSourceBlock);

            Shape shape = capi.Assets.TryGet("shapes/" + recipe.Shape.Base.Path + ".json").ToObject <Shape>();
            Dictionary <CookingRecipeIngredient, int> usedIngredQuantities = new Dictionary <CookingRecipeIngredient, int>();

            for (int i = 0; i < contentStacks.Length; i++)
            {
                texSource.ForStack = contentStacks[i];
                CookingRecipeIngredient ingred = recipe.GetIngrendientFor(
                    contentStacks[i],
                    usedIngredQuantities.Where(val => val.Key.MaxQuantity <= val.Value).Select(val => val.Key).ToArray()
                    );

                if (ingred == null)
                {
                    ingred = recipe.GetIngrendientFor(contentStacks[i]);
                }
                else
                {
                    int cnt = 0;
                    usedIngredQuantities.TryGetValue(ingred, out cnt);
                    cnt++;
                    usedIngredQuantities[ingred] = cnt;
                }

                if (ingred == null)
                {
                    continue;
                }


                MeshData meshpart;
                string[] selectiveElements = null;

                CookingRecipeStack recipestack = ingred.GetMatchingStack(contentStacks[i]);

                if (recipestack.ShapeElement != null)
                {
                    selectiveElements = new string[] { recipestack.ShapeElement }
                }
                ;
                texSource.customTextureMapping = recipestack.TextureMapping;

                capi.Tesselator.TesselateShape(
                    "mealpart", shape, out meshpart, texSource,
                    new Vec3f(recipe.Shape.rotateX, recipe.Shape.rotateY, recipe.Shape.rotateZ), 0, 0, null, selectiveElements
                    );

                if (mergedmesh == null)
                {
                    mergedmesh = meshpart;
                }
                else
                {
                    mergedmesh.AddMeshData(meshpart);
                }
            }

            if (foodTranslate != null)
            {
                mergedmesh.Translate(foodTranslate);
            }

            return(mergedmesh);
        }
Example #30
0
        public override string GetBlockInfo(IPlayer forPlayer)
        {
            CookingRecipe recipe = FromRecipe;
            StringBuilder dsc    = new StringBuilder();

            if (recipe == null)
            {
                if (inventory.Count > 0 && !inventory[0].Empty)
                {
                    dsc.AppendLine(inventory[0].StackSize + "x " + inventory[0].Itemstack.GetName());
                }

                return(dsc.ToString());
            }


            dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(QuantityServings, 1), recipe.GetOutputName(forPlayer.Entity.World, GetNonEmptyContentStacks()).UcFirst()));

            if (ownBlock == null)
            {
                return(dsc.ToString());
            }


            int    temp       = GetTemperature();
            string temppretty = Lang.Get("{0}°C", temp);

            if (temp < 20)
            {
                temppretty = "Cold";
            }

            dsc.AppendLine(Lang.Get("Temperature: {0}", temppretty));

            string nutriFacts = ownBlock.GetContentNutritionFacts(api.World, inventory[0], GetNonEmptyContentStacks(false), forPlayer.Entity);

            if (nutriFacts != null)
            {
                dsc.Append(nutriFacts);
            }

            TransitionState state = inventory[0].Itemstack.Collectible.UpdateAndGetTransitionState(api.World, inventory[0], EnumTransitionType.Perish);

            if (state != null)
            {
                if (state.TransitionLevel > 0)
                {
                    dsc.AppendLine(Lang.Get("<font color=\"orange\">Perishable.</font> {0}% spoiled", (int)Math.Round(state.TransitionLevel * 100)));
                }
                else
                {
                    double hoursPerday = api.World.Calendar.HoursPerDay;
                    if (state.FreshHoursLeft > hoursPerday)
                    {
                        dsc.AppendLine(Lang.Get("<font color=\"orange\">Perishable.</font> Fresh for {0} days", Math.Round(state.FreshHoursLeft / hoursPerday, 1)));
                    }
                    else
                    {
                        dsc.AppendLine(Lang.Get("<font color=\"orange\">Perishable.</font> Fresh for {0} hours", Math.Round(state.FreshHoursLeft, 1)));
                    }
                }
            }


            return(dsc.ToString());
        }