Пример #1
0
        public MeshData GenMesh(ICoreClientAPI capi, ItemStack contentStack, BlockPos forBlockPos = null)
        {
            Shape    shape = capi.Assets.TryGet("shapes/block/wood/bucket/empty.json").ToObject <Shape>();
            MeshData bucketmesh;

            capi.Tesselator.TesselateShape(this, shape, out bucketmesh);

            if (contentStack != null)
            {
                WaterTightContainableProps props = GetStackProps(contentStack);

                ContainerTextureSource contentSource = new ContainerTextureSource(capi, contentStack, props.Texture);
                shape = capi.Assets.TryGet("shapes/block/wood/bucket/contents.json").ToObject <Shape>();
                MeshData contentMesh;
                capi.Tesselator.TesselateShape("bucket", shape, out contentMesh, contentSource, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ));

                contentMesh.Translate(0, GameMath.Min(7 / 16f, contentStack.StackSize / props.ItemsPerLitre * 0.7f / 16f), 0);

                if (props.TintIndex > 0)
                {
                    int col = capi.ApplyColorTintOnRgba(props.TintIndex, ColorUtil.WhiteArgb, 196, 128, false);
                    if (forBlockPos != null)
                    {
                        col = capi.ApplyColorTintOnRgba(props.TintIndex, ColorUtil.WhiteArgb, forBlockPos.X, forBlockPos.Y, forBlockPos.Z, false);
                    }

                    byte[] rgba = ColorUtil.ToBGRABytes(col);

                    for (int i = 0; i < contentMesh.Rgba.Length; i++)
                    {
                        contentMesh.Rgba[i] = (byte)((contentMesh.Rgba[i] * rgba[i % 4]) / 255);
                    }
                }

                for (int i = 0; i < contentMesh.Flags.Length; i++)
                {
                    contentMesh.Flags[i] = contentMesh.Flags[i] & ~(1 << 12); // Remove water waving flag
                }

                bucketmesh.AddMeshData(contentMesh);

                // Water flags
                if (forBlockPos != null)
                {
                    bucketmesh.CustomInts       = new CustomMeshDataPartInt(bucketmesh.FlagsCount);
                    bucketmesh.CustomInts.Count = bucketmesh.FlagsCount;

                    bucketmesh.CustomFloats       = new CustomMeshDataPartFloat(bucketmesh.FlagsCount * 2);
                    bucketmesh.CustomFloats.Count = bucketmesh.FlagsCount * 2;
                }
            }


            return(bucketmesh);
        }
Пример #2
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            if (this != brownSeg3 && this != capi.World.GetBlock(new AssetLocation("bamboo-placed-green-segment3")))
            {
                return(base.GetRandomColor(capi, pos, facing));
            }

            if (Textures == null || Textures.Count == 0)
            {
                return(0);
            }
            CompositeTexture tex;

            if (!Textures.TryGetValue(facing.Code, out tex))
            {
                tex = Textures.First().Value;
            }
            if (tex?.Baked == null)
            {
                return(0);
            }

            int color = capi.BlockTextureAtlas.GetRandomPixel(tex.Baked.TextureSubId);

            return(capi.ApplyColorTintOnRgba(1, color, pos.X, pos.Y, pos.Z));
        }
Пример #3
0
 public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
 {
     if (facing == BlockFacing.UP)
     {
         return(capi.ApplyColorTintOnRgba(1, capi.BlockTextureAtlas.GetRandomPixel(Textures["specialSecondTexture"].Baked.TextureSubId), pos.X, pos.Y, pos.Z));
     }
     return(base.GetRandomColor(capi, pos, facing));
 }
Пример #4
0
        public MeshData GenMesh(ICoreClientAPI capi, ItemStack contentStack, BlockPos forBlockPos = null)
        {
            Shape    shape = capi.Assets.TryGet("shapes/block/wood/bucket/empty.json").ToObject <Shape>();
            MeshData bucketmesh;

            capi.Tesselator.TesselateShape(this, shape, out bucketmesh);

            if (contentStack != null)
            {
                WaterTightContainableProps props = GetStackProps(contentStack);
                Block contentBlock = capi.World.GetBlock(props.BlockTextureSource);
                if (contentBlock == null)
                {
                    return(bucketmesh);
                }

                BucketTextureSource contentSource = new BucketTextureSource(capi, contentStack, contentBlock);
                shape = capi.Assets.TryGet("shapes/block/wood/bucket/contents.json").ToObject <Shape>();
                MeshData contentMesh;
                capi.Tesselator.TesselateShape("bucket", shape, out contentMesh, contentSource, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ));


                contentMesh.Translate(0, GameMath.Min(7 / 16f, contentStack.StackSize / props.ItemsPerLitre * 0.7f / 16f), 0);

                if (contentBlock.TintIndex > 0)
                {
                    int col = capi.ApplyColorTintOnRgba(contentBlock.TintIndex, ColorUtil.WhiteArgb, 196, 128, false);
                    if (forBlockPos != null)
                    {
                        col = capi.ApplyColorTintOnRgba(contentBlock.TintIndex, ColorUtil.WhiteArgb, forBlockPos.X, forBlockPos.Y, forBlockPos.Z, false);
                    }

                    byte[] rgba = ColorUtil.ToBGRABytes(col);

                    for (int i = 0; i < contentMesh.Rgba.Length; i++)
                    {
                        contentMesh.Rgba[i] = (byte)((contentMesh.Rgba[i] * rgba[i % 4]) / 255);
                    }
                }

                bucketmesh.AddMeshData(contentMesh);
            }

            return(bucketmesh);
        }
Пример #5
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            BakedCompositeTexture tex = Textures?.First().Value?.Baked;
            int color = capi.BlockTextureAtlas.GetRandomPixel(tex.TextureSubId);

            color = capi.ApplyColorTintOnRgba(1, color, pos.X, pos.Y, pos.Z);

            return(color);
        }
Пример #6
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            Dictionary <string, CompositeTexture> textures = this.Textures;
            BakedCompositeTexture compositeTexture         = textures != null?textures.First <KeyValuePair <string, CompositeTexture> >().Value?.Baked : (BakedCompositeTexture)null;

            int randomColor = capi.BlockTextureAtlas.GetRandomColor(compositeTexture.TextureSubId);

            return(this.FirstCodePart() == "palmfrond" ? capi.ApplyColorTintOnRgba(1, randomColor, pos.X, pos.Y, pos.Z, true) : randomColor);
        }
Пример #7
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            int color = base.GetRandomColor(capi, pos, facing);

            if (EntityClass == "Sapling")
            {
                color = capi.ApplyColorTintOnRgba(1, color, pos.X, pos.Y, pos.Z);
            }

            return(color);
        }
        public override int GetColor(ICoreClientAPI capi, BlockPos pos)
        {
            string grasscover = LastCodePart();

            if (grasscover == "none")
            {
                return(base.GetColor(capi, pos));
            }

            CompositeTexture tex;

            if (Textures == null || !Textures.TryGetValue("specialSecondTexture", out tex))
            {
                tex = Textures?.First().Value;
            }

            int?textureSubId = tex?.Baked.TextureSubId;

            if (textureSubId == null)
            {
                return(ColorUtil.WhiteArgb);
            }

            int grassColor = ColorUtil.ReverseColorBytes(capi.BlockTextureAtlas.GetPixelAt((int)textureSubId, 0.5f, 0.5f));

            if (TintIndex > 0)
            {
                grassColor = capi.ApplyColorTintOnRgba(TintIndex, grassColor, pos.X, pos.Y, pos.Z, false);
            }

            if (grasscover == "normal")
            {
                return(grassColor);
            }
            else
            {
                int soilColor = ColorUtil.ReverseColorBytes(capi.BlockTextureAtlas.GetPixelAt((int)Textures["up"].Baked.TextureSubId, 0.5f, 0.5f));

                return(ColorUtil.ColorOverlay(soilColor, grassColor, grasscover == "verysparse" ? 0.5f : 0.75f));
            }
        }
Пример #9
0
 public override int GetColor(ICoreClientAPI capi, BlockPos pos)
 {
     return(capi.ApplyColorTintOnRgba(1, base.GetColor(capi, pos), pos.X, pos.Y, pos.Z, false));
 }
Пример #10
0
        public override int GetColor(ICoreClientAPI capi, BlockPos pos)
        {
            int gray = ColorUtil.ColorFromRgba(127, 127, 127, 255);

            return(this.FirstCodePart() == "palmfrond" ? capi.ApplyColorTintOnRgba(1, gray, pos.X, pos.Y, pos.Z, false) : GetColorWithoutTint(capi, pos));
        }
        public override int GetColor(ICoreClientAPI capi, BlockPos pos)
        {
            int color = base.GetColorWithoutTint(capi, pos);

            return(capi.ApplyColorTintOnRgba(1, color, pos.X, pos.Y, pos.Z, false));
        }
Пример #12
0
 public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
 {
     return(capi.ApplyColorTintOnRgba(1, capi.BlockTextureAtlas.GetRandomPixel(Textures.Last().Value.Baked.TextureSubId), pos.X, pos.Y, pos.Z));
 }
Пример #13
0
        protected MeshData getContentMesh(ItemStack stack, BlockPos forBlockPos, string shapefilename)
        {
            ICoreClientAPI capi = api as ICoreClientAPI;

            WaterTightContainableProps props         = GetStackProps(stack);
            ITexPositionSource         contentSource = null;


            float fillHeight = 0;

            if (props != null)
            {
                contentSource = new ContainerTextureSource(capi, stack, props.Texture);
                fillHeight    = GameMath.Min(10 / 16f, 0.2f * stack.StackSize / props.ItemsPerLitre / 16f);
            }
            else
            {
                JsonObject obj = stack?.ItemAttributes?["inContainerTexture"];
                if (obj != null && obj.Exists)
                {
                    contentSource = new ContainerTextureSource(capi, stack, obj.AsObject <CompositeTexture>());
                    fillHeight    = GameMath.Min(10 / 16f, 0.7f * stack.StackSize / stack.Collectible.MaxStackSize);
                }
                else
                {
                    if (stack?.Block != null && (stack.Block.DrawType == EnumDrawType.Cube || stack.Block.Shape.Base.Path.Contains("basic/cube")))
                    {
                        contentSource = new BlockTopTextureSource(capi, stack.Block);
                        fillHeight    = GameMath.Min(10 / 16f, 0.7f * 1);
                    }
                }
            }

            if (stack != null && contentSource != null)
            {
                Shape    shape = capi.Assets.TryGet("shapes/block/wood/barrel/" + shapefilename).ToObject <Shape>();
                MeshData contentMesh;
                capi.Tesselator.TesselateShape("barrel", shape, out contentMesh, contentSource, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ));

                contentMesh.Translate(0, fillHeight, 0);

                if (props != null && props.TintIndex > 0)
                {
                    int col = capi.ApplyColorTintOnRgba(props.TintIndex, ColorUtil.WhiteArgb, 196, 128, false);
                    if (forBlockPos != null)
                    {
                        col = capi.ApplyColorTintOnRgba(props.TintIndex, ColorUtil.WhiteArgb, forBlockPos.X, forBlockPos.Y, forBlockPos.Z, false);
                    }

                    byte[] rgba = ColorUtil.ToBGRABytes(col);

                    for (int i = 0; i < contentMesh.Rgba.Length; i++)
                    {
                        contentMesh.Rgba[i] = (byte)((contentMesh.Rgba[i] * rgba[i % 4]) / 255);
                    }
                }


                return(contentMesh);
            }

            return(null);
        }