private void CollectFromWorldProperties(RegistryObjectVariantGroup variantGroup, RegistryObjectVariantGroup[] 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]);
            }
        }
예제 #2
0
        private void CollectFromWorldPropertiesCombine(AssetLocation[] propList, RegistryObjectVariantGroup variantGroup, RegistryObjectVariantGroup[] variantgroups, OrderedDictionary <string, VariantEntry[]> blockvariantsMul, List <ResolvedVariant> blockvariantsFinal, AssetLocation location)
        {
            if (propList.Length > 1 && variantGroup.Code == null)
            {
                api.Server.LogError(
                    "Error in item or block {0}, defined a variantgroup with loadFromPropertiesCombine (first element: {1}), but did not explicitly declare a code for this variant group, hence I do not know which code to use. Ignoring.",
                    location, propList[0]
                    );
                return;
            }

            foreach (var val in propList)
            {
                StandardWorldProperty property = GetWorldPropertyByCode(val);

                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)
                    {
                        ResolvedVariant resolved = new ResolvedVariant();
                        resolved.CodeParts.Add(typename, variant.Code.Path);
                        blockvariantsFinal.Add(resolved);
                    }
                }

                if (variantGroup.Combine == EnumCombination.Multiply)
                {
                    VariantEntry[] variants = null;
                    if (blockvariantsMul.TryGetValue(typename, out variants))
                    {
                        blockvariantsMul[typename] = variants.Append(worldPropertiesVariants[property.Code]);
                    }
                    else
                    {
                        blockvariantsMul.Add(typename, worldPropertiesVariants[property.Code]);
                    }
                }
            }
        }
예제 #3
0
        private void CollectFromStateList(RegistryObjectVariantGroup variantGroup, RegistryObjectVariantGroup[] variantgroups, OrderedDictionary <string, VariantEntry[]> variantsMul, List <ResolvedVariant> 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++)
                {
                    ResolvedVariant resolved = new ResolvedVariant();
                    resolved.CodeParts.Add(type, states[j]);
                    blockvariantsFinal.Add(resolved);
                }
            }

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

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


                for (int i = 0; i < variantgroups.Length; i++)
                {
                    RegistryObjectVariantGroup 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;
                            }

                            VariantEntry 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 VariantEntry()
                                {
                                    Code  = old.Code + "-" + cvg.States[j],
                                    Codes = codes,
                                    Types = types
                                });
                            }
                        }
                    }
                }

                if (variantsMul.ContainsKey(type))
                {
                    stateList.AddRange(variantsMul[type]);
                    variantsMul[type] = stateList.ToArray();
                }
                else
                {
                    variantsMul.Add(type, stateList.ToArray());
                }
            }
        }
예제 #4
0
 private void CollectFromWorldProperties(RegistryObjectVariantGroup variantGroup, RegistryObjectVariantGroup[] variantgroups, OrderedDictionary <string, VariantEntry[]> blockvariantsMul, List <ResolvedVariant> blockvariantsFinal, AssetLocation location)
 {
     CollectFromWorldPropertiesCombine(new AssetLocation[] { variantGroup.LoadFromProperties }, variantGroup, variantgroups, blockvariantsMul, blockvariantsFinal, location);
 }