Esempio n. 1
0
        private LoadedTexture GenerateOverlayTexture()
        {
            var colorTexture = new LoadedTexture(_clientApi, 0, _chunksize, _chunksize);
            var colorArray   = Enumerable.Repeat(_config.TextureColor.RGBA, _chunksize * _chunksize).ToArray();

            if (_config.RenderBorder)
            {
                for (int x = 0; x < _chunksize; x++)
                {
                    for (int y = 0; y < _chunksize; y++)
                    {
                        if (x < _config.BorderThickness || x > _chunksize - 1 - _config.BorderThickness)
                        {
                            colorArray[y * _chunksize + x] = ColorUtil.ColorOver(colorArray[y * _chunksize + x], _config.BorderColor.RGBA);
                        }
                        else if (y < _config.BorderThickness || y > _chunksize - 1 - _config.BorderThickness)
                        {
                            colorArray[y * _chunksize + x] = ColorUtil.ColorOver(colorArray[y * _chunksize + x], _config.BorderColor.RGBA);
                        }
                    }
                }
            }

            _clientApi.Render.LoadOrUpdateTextureFromRgba(colorArray, false, 0, ref colorTexture);
            _clientApi.Render.BindTexture2d(colorTexture.TextureId);

            return(colorTexture);
        }
Esempio n. 2
0
        public TextureAtlasPosition this[string textureCode]
        {
            get
            {
                AssetLocation texturePath;

                if (textureCode == "ropedcloth" || type == null || type == "")
                {
                    texturePath = new AssetLocation("block/cloth/ropedcloth");
                }
                else
                {
                    texturePath = new AssetLocation("block/cloth/tapestry/" + type);
                }

                AssetLocation cachedPath = texturePath.Clone();

                AssetLocation rotLoc = null;

                if (rotten)
                {
                    rotLoc           = new AssetLocation("block/cloth/tapestryoverlay/rotten" + rotVariant);
                    cachedPath.Path += "++" + rotLoc.Path;
                }

                TextureAtlasPosition texpos = capi.BlockTextureAtlas[cachedPath];

                if (texpos == null)
                {
                    IAsset texAsset = capi.Assets.TryGet(texturePath.Clone().WithPathPrefixOnce("textures/").WithPathAppendixOnce(".png"));
                    if (texAsset != null)
                    {
                        BitmapRef bmp = texAsset.ToBitmap(capi);

                        if (rotten)
                        {
                            BakedBitmap bakedBmp = new BakedBitmap()
                            {
                                Width = bmp.Width, Height = bmp.Height
                            };
                            bakedBmp.TexturePixels = bmp.Pixels;

                            int[] texturePixelsOverlay = capi.Assets.TryGet(rotLoc.WithPathPrefixOnce("textures/").WithPathAppendixOnce(".png"))?.ToBitmap(capi)?.Pixels;
                            if (texturePixelsOverlay == null)
                            {
                                throw new Exception("Texture file " + rotLoc + " is missing");
                            }

                            for (int p = 0; p < bakedBmp.TexturePixels.Length; p++)
                            {
                                bakedBmp.TexturePixels[p] = ColorUtil.ColorOver(texturePixelsOverlay[p], bakedBmp.TexturePixels[p]);
                            }

                            capi.BlockTextureAtlas.InsertTextureCached(cachedPath, bakedBmp, out _, out texpos);
                        }
                        else
                        {
                            capi.BlockTextureAtlas.InsertTextureCached(cachedPath, bmp, out _, out texpos);
                        }
                    }
                    else
                    {
                        capi.World.Logger.Warning("Tapestry type '{0}' defined texture '{1}', but no such texture found.", type, texturePath);
                    }
                }

                if (texpos == null)
                {
                    return(capi.BlockTextureAtlas.UnknownTexturePosition);
                }

                return(texpos);
            }
        }