Esempio n. 1
0
        public virtual void FromBytes(BinaryReader reader, IClassRegistryAPI instancer)
        {
            Code              = reader.ReadString();
            MinQuantity       = reader.ReadInt32();
            MaxQuantity       = reader.ReadInt32();
            PortionSizeLitres = reader.ReadSingle();

            int q = reader.ReadInt32();

            ValidStacks = new CookingRecipeStack[q];
            for (int i = 0; i < q; i++)
            {
                ValidStacks[i] = new CookingRecipeStack();
                ValidStacks[i].FromBytes(reader, instancer);
            }
        }
Esempio n. 2
0
        public new CookingRecipeStack Clone()
        {
            CookingRecipeStack stack = new CookingRecipeStack()
            {
                Code = Code.Clone(),
                ResolvedItemstack = ResolvedItemstack?.Clone(),
                StackSize         = StackSize,
                Type           = Type,
                TextureMapping = (string[])TextureMapping?.Clone(),
                CookedStack    = CookedStack?.Clone()
            };

            if (Attributes != null)
            {
                stack.Attributes = Attributes.Clone();
            }

            stack.ShapeElement = ShapeElement;

            return(stack);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }