Ejemplo n.º 1
0
        private void CollectFromWorldProperties(CollectibleVariantGroup variantGroup, CollectibleVariantGroup[] variantgroups, OrderedDictionary <string, BlockVariant[]> blockvariantsMul, List <ResolvedBlockVariant> blockvariantsFinal, AssetLocation location)
        {
            StandardWorldProperty property = GetWorldPropertyByCode(variantGroup.LoadFromProperties);

            if (property == null)
            {
                api.Server.LogError(
                    "Error in item or block {0}, worldproperty {1} does not exist (or is empty). Ignoring.",
                    location, variantGroup.LoadFromProperties
                    );
                return;
            }

            string typename = variantGroup.Code == null ? property.Code.Path : variantGroup.Code;

            if (variantGroup.Combine == EnumCombination.Add)
            {
                foreach (WorldPropertyVariant variant in property.Variants)
                {
                    ResolvedBlockVariant resolved = new ResolvedBlockVariant();
                    resolved.Codes.Add(typename, variant.Code.Path);
                    blockvariantsFinal.Add(resolved);
                }
            }

            if (variantGroup.Combine == EnumCombination.Multiply)
            {
                blockvariantsMul.Add(typename, worldPropertiesVariants[property.Code]);
            }
        }
Ejemplo n.º 2
0
        List <ResolvedBlockVariant> GatherVariants(CollectibleVariantGroup[] variantgroups, AssetLocation location)
        {
            List <ResolvedBlockVariant> blockvariantsFinal = new List <ResolvedBlockVariant>();

            if (variantgroups == null || variantgroups.Length == 0)
            {
                return(blockvariantsFinal);
            }

            OrderedDictionary <string, BlockVariant[]> blockvariantsMul = new OrderedDictionary <string, BlockVariant[]>();

            // 1. Collect all types
            for (int i = 0; i < variantgroups.Length; i++)
            {
                if (variantgroups[i].LoadFromProperties != null)
                {
                    CollectFromWorldProperties(variantgroups[i], variantgroups, blockvariantsMul, blockvariantsFinal, location);
                }

                if (variantgroups[i].States != null)
                {
                    CollectFromStateList(variantgroups[i], variantgroups, blockvariantsMul, blockvariantsFinal, location);
                }
            }

            // 2. Multiply multiplicative groups
            BlockVariant[,] variants = MultiplyProperties(blockvariantsMul.Values.ToArray());


            // 3. Add up multiplicative groups
            for (int i = 0; i < variants.GetLength(0); i++)
            {
                ResolvedBlockVariant resolved = new ResolvedBlockVariant();
                for (int j = 0; j < variants.GetLength(1); j++)
                {
                    BlockVariant variant = variants[i, j];

                    if (variant.Codes != null)
                    {
                        for (int k = 0; k < variant.Codes.Count; k++)
                        {
                            resolved.Codes.Add(variant.Types[k], variant.Codes[k]);
                        }
                    }
                    else
                    {
                        resolved.Codes.Add(blockvariantsMul.GetKeyAtIndex(j), variant.Code);
                    }
                }

                blockvariantsFinal.Add(resolved);
            }

            return(blockvariantsFinal);
        }
Ejemplo n.º 3
0
        private void CollectFromStateList(CollectibleVariantGroup variantGroup, CollectibleVariantGroup[] variantgroups, OrderedDictionary <string, BlockVariant[]> blockvariantsMul, List <ResolvedBlockVariant> blockvariantsFinal, AssetLocation filename)
        {
            if (variantGroup.Code == null)
            {
                api.Server.LogError(
                    "Error in itemtype {0}, a variantgroup using a state list must have a code. Ignoring.",
                    filename
                    );
                return;
            }

            string[] states = variantGroup.States;
            string   type   = variantGroup.Code;

            // Additive state list
            if (variantGroup.Combine == EnumCombination.Add)
            {
                for (int j = 0; j < states.Length; j++)
                {
                    ResolvedBlockVariant resolved = new ResolvedBlockVariant();
                    resolved.Codes.Add(type, states[j]);
                    blockvariantsFinal.Add(resolved);
                }
            }

            // Multiplicative state list
            if (variantGroup.Combine == EnumCombination.Multiply)
            {
                List <BlockVariant> stateList = new List <BlockVariant>();

                for (int j = 0; j < states.Length; j++)
                {
                    stateList.Add(new BlockVariant()
                    {
                        Code = states[j]
                    });
                }


                for (int i = 0; i < variantgroups.Length; i++)
                {
                    CollectibleVariantGroup cvg = variantgroups[i];
                    if (cvg.Combine == EnumCombination.SelectiveMultiply && cvg.OnVariant == variantGroup.Code)
                    {
                        for (int k = 0; k < stateList.Count; k++)
                        {
                            if (cvg.Code != stateList[k].Code)
                            {
                                continue;
                            }

                            BlockVariant old = stateList[k];

                            stateList.RemoveAt(k);

                            for (int j = 0; j < cvg.States.Length; j++)
                            {
                                List <string> codes = old.Codes == null ? new List <string>()
                                {
                                    old.Code
                                } : old.Codes;
                                List <string> types = old.Types == null ? new List <string>()
                                {
                                    variantGroup.Code
                                } : old.Types;

                                codes.Add(cvg.States[j]);
                                types.Add(cvg.Code);

                                stateList.Insert(k, new BlockVariant()
                                {
                                    Code  = old.Code + "-" + cvg.States[j],
                                    Codes = codes,
                                    Types = types
                                });
                            }
                        }
                    }
                }

                if (blockvariantsMul.ContainsKey(type))
                {
                    stateList.AddRange(blockvariantsMul[type]);
                    blockvariantsMul[type] = stateList.ToArray();
                }
                else
                {
                    blockvariantsMul.Add(type, stateList.ToArray());
                }
            }
        }