// 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;
            }
        }
        public TextureAtlasPosition this[string textureCode]
        {
            get {
                ToolTextures tt = null;

                if (BlockToolRack.ToolTextureSubIds(api).TryGetValue((Item)tmpItem, out tt))
                {
                    int textureSubId = 0;
                    if (tt.TextureSubIdsByCode.TryGetValue(textureCode, out textureSubId))
                    {
                        return(((ICoreClientAPI)api).BlockTextureAtlas.Positions[textureSubId]);
                    }

                    return(((ICoreClientAPI)api).BlockTextureAtlas.Positions[tt.TextureSubIdsByCode.First().Value]);
                }

                return(null);
            }
        }
Exemple #3
0
        // We need the tool item textures also in the block atlas
        public override void OnCollectTextures(ICoreAPI api, OrderedDictionary <AssetLocationAndSource, bool> textureDict)
        {
            base.OnCollectTextures(api, textureDict);

            for (int i = 0; i < api.World.Items.Length; i++)
            {
                Item item = api.World.Items[i];
                if (item.Tool == null)
                {
                    continue;
                }

                ToolTextures tt = new ToolTextures();

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

                /*if (item.Shape != null)
                 * {
                 *  Shape shape = api.Assets.Get(item.Shape.Base).ToObject<Shape>();
                 *  foreach(var val in shape.Textures)
                 *  {
                 *      val.Value.Bake(api.Assets);
                 *      textureDict[val.Value.Baked.BakedName] = true;
                 *      tt.TextureSubIdsByCode[val.Key] = textureDict.IndexOfKey(val.Value.Baked.BakedName);
                 *  }
                 * }*/


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