public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            base.FromTreeAttributes(tree, worldForResolving);
            color = tree.GetInt("color");
            if (color == 0)
            {
                color = ColorUtil.BlackArgb;
            }

            for (int i = 0; i < 8; i++)
            {
                textByCardinalDirection[i] = tree.GetString("text" + i, "");
            }


            signRenderer?.SetNewText(textByCardinalDirection, color);
        }
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);

            if (api is ICoreClientAPI)
            {
                CairoFont font = new CairoFont(20, GuiStyle.StandardFontName, new double[] { 0, 0, 0, 0.8 });

                signRenderer = new BlockEntitySignPostRenderer(Pos, (ICoreClientAPI)api, font);

                if (textByCardinalDirection.Length > 0)
                {
                    signRenderer.SetNewText(textByCardinalDirection, color);
                }

                Shape shape = api.Assets.TryGet(AssetLocation.Create("shapes/block/wood/signpost/sign.json")).ToObject <Shape>();
                if (shape != null)
                {
                    (api as ICoreClientAPI).Tesselator.TesselateShape(Block, shape, out signMesh);
                }
            }
        }
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            if (packetid == (int)EnumSignPacketId.OpenDialog)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    string dialogClassName = reader.ReadString();
                    string dialogTitle     = reader.ReadString();

                    for (int i = 0; i < 8; i++)
                    {
                        textByCardinalDirection[i] = reader.ReadString();
                        if (textByCardinalDirection[i] == null)
                        {
                            textByCardinalDirection[i] = "";
                        }
                    }

                    IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;

                    CairoFont font = new CairoFont(20, GuiStyle.StandardFontName, new double[] { 0, 0, 0, 0.8 });

                    if (dlg != null && dlg.IsOpened())
                    {
                        return;
                    }

                    dlg = new GuiDialogSignPost(dialogTitle, Pos, textByCardinalDirection, Api as ICoreClientAPI, font);
                    dlg.OnTextChanged = DidChangeTextClientSide;
                    dlg.OnCloseCancel = () =>
                    {
                        signRenderer.SetNewText(textByCardinalDirection, color);
                        (Api as ICoreClientAPI).Network.SendBlockEntityPacket(Pos.X, Pos.Y, Pos.Z, (int)EnumSignPacketId.CancelEdit, null);
                    };
                    dlg.OnClosed += () => { dlg.Dispose(); dlg = null; };
                    dlg.TryOpen();
                }
            }


            if (packetid == (int)EnumSignPacketId.NowText)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);
                    for (int i = 0; i < 8; i++)
                    {
                        textByCardinalDirection[i] = reader.ReadString();
                        if (textByCardinalDirection[i] == null)
                        {
                            textByCardinalDirection[i] = "";
                        }
                    }

                    if (signRenderer != null)
                    {
                        signRenderer.SetNewText(textByCardinalDirection, color);
                    }
                }
            }
        }