Beispiel #1
0
        /// <summary>
        /// Creates a deep copy of the texture
        /// </summary>
        /// <returns></returns>
        public CompositeShape Clone()
        {
            CompositeShape[] alternatesClone = null;

            if (Alternates != null)
            {
                alternatesClone = new CompositeShape[Alternates.Length];
                for (int i = 0; i < alternatesClone.Length; i++)
                {
                    alternatesClone[i] = Alternates[i].CloneWithoutAlternates();
                }
            }

            CompositeShape[] overlaysClone = null;

            if (this.Overlays != null)
            {
                overlaysClone = new CompositeShape[Overlays.Length];
                for (int i = 0; i < overlaysClone.Length; i++)
                {
                    overlaysClone[i] = Overlays[i].CloneWithoutAlternates();
                }
            }

            CompositeShape ct = new CompositeShape()
            {
                Base                = Base?.Clone(),
                Alternates          = alternatesClone,
                Overlays            = overlaysClone,
                Format              = Format,
                VoxelizeTexture     = VoxelizeTexture,
                InsertBakedTextures = InsertBakedTextures,
                rotateX             = rotateX,
                rotateY             = rotateY,
                rotateZ             = rotateZ,
                offsetX             = offsetX,
                offsetY             = offsetY,
                offsetZ             = offsetZ,
                Scale               = Scale,
                QuantityElements    = QuantityElements,
                SelectiveElements   = (string[])SelectiveElements?.Clone()
            };

            return(ct);
        }
Beispiel #2
0
        /// <summary>
        /// Replaces one part from the blocks code and replaces it with components by splitting it up at every occurence of a dash ('-')
        /// </summary>
        /// <param name="components"></param>
        /// <returns></returns>
        public AssetLocation CodeWithPart(string part, int atPosition = 0)
        {
            if (Code == null) return null;

            AssetLocation newCode = Code.Clone();
            string[] parts = newCode.Path.Split('-');
            parts[atPosition] = part;
            newCode.Path = String.Join("-", parts);

            return newCode;
        }
Beispiel #3
0
        /// <summary>
        /// Clones the held sounds.
        /// </summary>
        /// <returns></returns>
        public HeldSounds Clone()
        {
            HeldSounds sounds = new HeldSounds()
            {
                Idle    = Idle == null ? null : Idle.Clone(),
                Equip   = Equip == null ? null : Equip.Clone(),
                Unequip = Unequip == null ? null : Unequip.Clone(),
                Attack  = Attack == null ? null : Attack.Clone()
            };

            return(sounds);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a deep copy of this object
        /// </summary>
        /// <returns></returns>
        public JsonItemStack Clone()
        {
            JsonItemStack stack = new JsonItemStack()
            {
                Code = Code.Clone(),
                ResolvedItemstack = ResolvedItemstack?.Clone(),
                StackSize         = StackSize,
                Type = Type,
            };

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

            return(stack);
        }
Beispiel #5
0
        /// <summary>
        /// Creates a deep copy of this object
        /// </summary>
        /// <returns></returns>
        public BlockDropItemStack Clone()
        {
            BlockDropItemStack stack = new BlockDropItemStack()
            {
                Code              = Code.Clone(),
                Quantity          = Quantity,
                Type              = Type,
                LastDrop          = LastDrop,
                Tool              = Tool,
                ResolvedItemstack = ResolvedItemstack,
                DropModbyStat     = DropModbyStat
            };

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

            return(stack);
        }
Beispiel #6
0
        /// <summary>
        /// Clones the block sounds.
        /// </summary>
        /// <returns></returns>
        public BlockSounds Clone()
        {
            BlockSounds sounds = new BlockSounds()
            {
                Walk              = Walk == null ? null : Walk.Clone(),
                Inside            = Inside == null ? null : Inside.Clone(),
                Break             = Break == null ? null : Break.Clone(),
                Place             = Place == null ? null : Place.Clone(),
                Hit               = Hit == null ? null : Hit.Clone(),
                Ambient           = Ambient == null ? null : Ambient.Clone(),
                AmbientBlockCount = AmbientBlockCount
            };

            foreach (var val in ByTool)
            {
                sounds.ByTool[val.Key] = val.Value.Clone();
            }

            return(sounds);
        }
Beispiel #7
0
        /// <summary>
        /// Expands the Composite Texture to a texture atlas friendly version and populates the Baked field
        /// </summary>
        public void LoadAlternates(IAssetManager assetManager, ILogger logger)
        {
            if (Base.Path.EndsWith("*"))
            {
                List <IAsset> assets = assetManager.GetMany("shapes/" + Base.Path.Substring(0, Base.Path.Length - 1), Base.Domain);

                if (assets.Count == 0)
                {
                    Base = new AssetLocation("block/basic/cube");
                    logger.Warning("Could not find any variants for shape {0}, will use standard cube shape.", Base.Path);
                }

                if (assets.Count == 1)
                {
                    Base = assets[0].Location.CopyWithPath(assets[0].Location.Path.Substring("shapes/".Length));
                    Base.RemoveEnding();
                }

                if (assets.Count > 1)
                {
                    int origLength = (Alternates == null ? 0 : Alternates.Length);
                    CompositeShape[] alternates = new CompositeShape[origLength + assets.Count];
                    if (Alternates != null)
                    {
                        Array.Copy(Alternates, alternates, Alternates.Length);
                    }

                    int i = 0;
                    foreach (IAsset asset in assets)
                    {
                        AssetLocation newLocation = asset.Location.CopyWithPath(asset.Location.Path.Substring("shapes/".Length));
                        newLocation.RemoveEnding();

                        if (i == 0)
                        {
                            Base = newLocation.Clone();
                        }

                        alternates[origLength + i] = new CompositeShape()
                        {
                            Base = newLocation, rotateX = rotateX, rotateY = rotateY, rotateZ = rotateZ
                        };

                        i++;
                    }

                    Alternates = alternates;
                }
            }

            if (Alternates != null)
            {
                BakedAlternates               = new CompositeShape[Alternates.Length + 1];
                BakedAlternates[0]            = this.Clone();
                BakedAlternates[0].Alternates = null;

                for (int i = 0; i < Alternates.Length; i++)
                {
                    BakedAlternates[i + 1] = Alternates[i].Clone();

                    if (BakedAlternates[i + 1].Base == null)
                    {
                        BakedAlternates[i + 1].Base = Base.Clone();
                    }

                    if (BakedAlternates[i + 1].QuantityElements == null)
                    {
                        BakedAlternates[i + 1].QuantityElements = QuantityElements;
                    }

                    if (BakedAlternates[i + 1].SelectiveElements == null)
                    {
                        BakedAlternates[i + 1].SelectiveElements = SelectiveElements;
                    }
                }
            }
        }