Example #1
0
        // We need the tool item textures also in the block atlas
        public override void OnCollectTextures(ICoreAPI api, ITextureLocationDictionary textureDict)
        {
            base.OnCollectTextures(api, textureDict);

            for (int i = 0; i < api.World.Items.Count; i++)
            {
                Item item = api.World.Items[i];
                if (item.Tool == null && item.Attributes?["rackable"].AsBool() != true)
                {
                    continue;
                }

                ToolTextures tt = new ToolTextures();


                if (item.Shape != null)
                {
                    IAsset asset = api.Assets.TryGet(item.Shape.Base.Clone().WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json"));
                    if (asset != null)
                    {
                        Shape shape = asset.ToObject <Shape>();
                        foreach (var val in shape.Textures)
                        {
                            CompositeTexture ctex = new CompositeTexture(val.Value.Clone());
                            ctex.Bake(api.Assets);

                            textureDict.AddTextureLocation(new AssetLocationAndSource(ctex.Baked.BakedName, "Shape code " + item.Shape.Base));
                            tt.TextureSubIdsByCode[val.Key] = textureDict[new AssetLocationAndSource(ctex.Baked.BakedName)];
                        }
                    }
                }

                foreach (var val in item.Textures)
                {
                    val.Value.Bake(api.Assets);
                    textureDict.AddTextureLocation(new AssetLocationAndSource(val.Value.Baked.BakedName, "Item code " + item.Code));
                    tt.TextureSubIdsByCode[val.Key] = textureDict[new AssetLocationAndSource(val.Value.Baked.BakedName)];
                }



                ToolTextureSubIds(api)[item] = tt;
            }
        }