Ejemplo n.º 1
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            if (packetid == (int)EnumBlockStovePacket.OpenGUI)
            {
                using (MemoryStream memoryStream = new MemoryStream(data))
                {
                    BinaryReader stream = new BinaryReader((Stream)memoryStream);
                    stream.ReadString();
                    string        DialogTitle   = stream.ReadString();
                    TreeAttribute treeAttribute = new TreeAttribute();
                    treeAttribute.FromBytes(stream);
                    Inventory.FromTreeAttributes(treeAttribute);
                    Inventory.ResolveBlocksOrItems();
                    IClientWorldAccessor world = (IClientWorldAccessor)api.World;
                    SyncedTreeAttribute  tree  = new SyncedTreeAttribute();
                    SetDialogValues(tree);
                    clientDialog = new GuiDialogBlockEntityQuern(DialogTitle, Inventory, pos, tree, api as ICoreClientAPI);
                    clientDialog.TryOpen();
                    clientDialog.OnClosed += (Vintagestory.API.Common.Action)(() => clientDialog = null);
                }
            }

            if (packetid == (int)EnumBlockContainerPacketId.CloseInventory)
            {
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Reads all the itemstacks properties from a series of bytes, including its stack attributes
 /// </summary>
 /// <param name="stream"></param>
 public void FromBytes(BinaryReader stream)
 {
     Class     = (EnumItemClass)stream.ReadInt32();
     Id        = stream.ReadInt32();
     stacksize = stream.ReadInt32();
     stackAttributes.FromBytes(stream);
 }
Ejemplo n.º 3
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            if (packetid == (int)EnumBlockStovePacket.OpenGUI)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

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

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);
                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;

                    //clientWorld.OpenDialog(dialogClassName, dialogTitle, Inventory);
                }
            }

            if (packetid == (int)EnumBlockContainerPacketId.CloseInventory)
            {
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
            }
        }
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            if (packetid == (int)EnumBlockStovePacket.OpenGUI)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

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

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);
                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;

                    SyncedTreeAttribute dtree = new SyncedTreeAttribute();
                    SetDialogValues(dtree);

                    clientDialog = new GuiDialogBlockEntityQuern(dialogTitle, Inventory, pos, dtree, api as ICoreClientAPI);
                    clientDialog.TryOpen();
                }
            }

            if (packetid == (int)Vintagestory.API.Client.EnumBlockContainerPacketId.CloseInventory)
            {
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
            }
        }
        public override void FromBytes(BinaryReader reader, bool forClient)
        {
            base.FromBytes(reader, forClient);

            initialPos   = new BlockPos();
            initialPos.X = reader.ReadInt32();
            initialPos.Y = reader.ReadInt32();
            initialPos.Z = reader.ReadInt32();
            blockCode    = new AssetLocation(reader.ReadString());

            bool beIsNull = reader.ReadBoolean();

            if (!beIsNull)
            {
                blockEntityAttributes = new TreeAttribute();
                blockEntityAttributes.FromBytes(reader);
                blockEntityClass = reader.ReadString();
            }

            if (WatchedAttributes.HasAttribute("fallSound"))
            {
                fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound"));
            }

            canFallSideways = WatchedAttributes.GetBool("canFallSideways");
            dustIntensity   = WatchedAttributes.GetFloat("dustIntensity");

            DoRemoveBlock = reader.ReadBoolean();
        }
Ejemplo n.º 6
0
        internal InventoryGeneric LoadLastDeathContent(IPlayer player, int offset = 0)
        {
            ICoreAPI api = player.Entity?.Api;

            if (api == null)
            {
                throw new NullReferenceException("player.Entity.api is null");
            }
            if (Config.Current.MaxDeathContentSavedPerPlayer.Val <= offset)
            {
                throw new IndexOutOfRangeException("offset is too large or save data disabled");
            }

            string datapath = api.GetOrCreateDataPath($"ModData/{api.GetWorldId()}/{ConstantsCore.ModId}/{player.PlayerUID}");
            string file     = Directory.GetFiles(datapath).OrderByDescending(f => new FileInfo(f).Name).ToArray().ElementAt(offset);

            TreeAttribute tree = new TreeAttribute();

            tree.FromBytes(File.ReadAllBytes(file));

            InventoryGeneric inv = new InventoryGeneric(tree.GetInt("qslots"), "playercorpse-" + player.PlayerUID, api);

            inv.FromTreeAttributes(tree);
            return(inv);
        }
Ejemplo n.º 7
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;

            if (packetid == (int)EnumBlockContainerPacketId.OpenInventory)
            {
                if (invDialog != null)
                {
                    if (invDialog?.IsOpened() == true)
                    {
                        invDialog.TryClose();
                    }
                    invDialog?.Dispose();
                    invDialog = null;
                    return;
                }

                string        dialogClassName;
                string        dialogTitle;
                int           cols;
                TreeAttribute tree = new TreeAttribute();

                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);
                    dialogClassName = reader.ReadString();
                    dialogTitle     = reader.ReadString();
                    cols            = reader.ReadByte();
                    tree.FromBytes(reader);
                }

                Inventory.FromTreeAttributes(tree);
                Inventory.ResolveBlocksOrItems();

                invDialog = new GuiDialogBlockEntityInventory(dialogTitle, Inventory, Pos, cols, Api as ICoreClientAPI);

                Block         block      = Api.World.BlockAccessor.GetBlock(Pos);
                string        os         = block.Attributes?["openSound"]?.AsString();
                string        cs         = block.Attributes?["closeSound"]?.AsString();
                AssetLocation opensound  = os == null ? null : AssetLocation.Create(os, block.Code.Domain);
                AssetLocation closesound = cs == null ? null : AssetLocation.Create(cs, block.Code.Domain);

                invDialog.OpenSound  = opensound ?? this.OpenSound;
                invDialog.CloseSound = closesound ?? this.CloseSound;

                invDialog.TryOpen();
            }

            if (packetid == (int)EnumBlockEntityPacketId.Close)
            {
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
                if (invDialog?.IsOpened() == true)
                {
                    invDialog?.TryClose();
                }
                invDialog?.Dispose();
                invDialog = null;
            }
        }
 public override void OnReceivedServerPacket(int packetid, byte[] data, ref EnumHandling handled)
 {
     if (packetid == 1235)
     {
         TreeAttribute tree = new TreeAttribute();
         SerializerUtil.FromBytes(data, (r) => tree.FromBytes(r));
         mouthInv.FromTreeAttributes(tree);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Imports the tree data from a string.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public virtual TreeAttribute DecodeBlockEntityData(string data)
        {
            byte[] bedata = Ascii85.Decode(data);

            TreeAttribute tree = new TreeAttribute();

            using (MemoryStream ms = new MemoryStream(bedata))
            {
                BinaryReader reader = new BinaryReader(ms);
                tree.FromBytes(reader);
            }

            return(tree);
        }
Ejemplo n.º 10
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            var world = (IClientWorldAccessor)Api.World;

            // this packet seems to be treated specially... I attempted removing the unnecessary data and using a custom packet id but it caused bugs. TODO: revisit this later.
            if (packetid == 5000)
            {
                if (invDialog != null)
                {
                    if (invDialog?.IsOpened() == true)
                    {
                        invDialog?.TryClose();
                    }
                    invDialog?.Dispose();
                    invDialog = null;
                    return;
                }
                var treeAttribute = new TreeAttribute();
                using (var memoryStream = new MemoryStream(data))
                {
                    var stream = new BinaryReader(memoryStream);
                    stream.ReadString();
                    stream.ReadString();
                    stream.ReadByte();
                    treeAttribute.FromBytes(stream);
                }
                Inventory.FromTreeAttributes(treeAttribute);
                Inventory.ResolveBlocksOrItems();
                invDialog = new Dialog(Api as ICoreClientAPI, (Api as ICoreClientAPI)?.World.Player, this);
                invDialog.TryOpen();
            }

            if (packetid != 1001)
            {
                return;
            }
            world.Player.InventoryManager.CloseInventory(Inventory);
            if (invDialog?.IsOpened() == true)
            {
                invDialog?.TryClose();
            }

            invDialog?.Dispose();
            invDialog = null;
        }
Ejemplo n.º 11
0
        public override void FromBytes(BinaryReader reader, bool forClient)
        {
            base.FromBytes(reader, forClient);

            initialPos   = new BlockPos();
            initialPos.X = reader.ReadInt32();
            initialPos.Y = reader.ReadInt32();
            initialPos.Z = reader.ReadInt32();
            blockCode    = new AssetLocation(reader.ReadString());

            bool beIsNull = reader.ReadBoolean();

            if (!beIsNull)
            {
                blockEntityAttributes = new TreeAttribute();
                blockEntityAttributes.FromBytes(reader);
                blockEntityClass = reader.ReadString();
            }
        }
Ejemplo n.º 12
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            base.OnReceivedServerPacket(packetid, data);

            if (packetid == 1001)
            {
                talkUtil.Talk(EnumTalkType.Hurt);
            }
            if (packetid == 1002)
            {
                talkUtil.Talk(EnumTalkType.Death);
            }
            if (packetid == 1234)
            {
                TreeAttribute tree = new TreeAttribute();
                tree.FromBytes(data);
                Inventory.FromTreeAttributes(tree);
            }
        }
Ejemplo n.º 13
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            if (packetid == (int)EnumBlockStovePacket.OpenGUI)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

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

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);
                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;

                    SyncedTreeAttribute dtree = new SyncedTreeAttribute();
                    SetDialogValues(dtree);

                    if (clientDialog != null)
                    {
                        clientDialog.TryClose();
                        clientDialog = null;
                    }
                    else
                    {
                        clientDialog           = new GuiDialogBlockEntityFirepit(dialogTitle, Inventory, Pos, dtree, Api as ICoreClientAPI);
                        clientDialog.OnClosed += () => { clientDialog?.Dispose(); clientDialog = null; };
                        clientDialog.TryOpen();
                    }
                }
            }

            if (packetid == (int)EnumBlockEntityPacketId.Close)
            {
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
            }
        }
Ejemplo n.º 14
0
        public InventoryGeneric LoadLastDeathContent(IPlayer player, int offset = 0)
        {
            ICoreAPI api = player.Entity.Api;

            if (Config.Current.MaxDeathContentSavedPerPlayer.Value <= offset)
            {
                throw new IndexOutOfRangeException("offset is too large or save data disabled");
            }

            string localPath = "ModData" + api.GetWorldId() + "/" + Mod.Info.ModID + "/" + player.PlayerUID;
            string path      = api.GetOrCreateDataPath(localPath);
            string file      = Directory.GetFiles(path).OrderByDescending(f => new FileInfo(f).Name).ToArray().ElementAt(offset);

            TreeAttribute tree = new TreeAttribute();

            tree.FromBytes(File.ReadAllBytes(file));

            InventoryGeneric inv = new InventoryGeneric(tree.GetInt("qslots"), "playercorpse-" + player.PlayerUID, api);

            inv.FromTreeAttributes(tree);
            return(inv);
        }
Ejemplo n.º 15
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;

            if (packetid == (int)EnumBlockContainerPacketId.OpenInventory)
            {
                if (invDialog != null)
                {
                    invDialog.TryClose();
                    invDialog = null;
                    return;
                }

                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    string dialogClassName = reader.ReadString();
                    string dialogTitle     = reader.ReadString();
                    int    cols            = reader.ReadByte();

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);
                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    invDialog = new GuiDialogBlockEntityInventory(dialogTitle, Inventory, pos, cols, api as ICoreClientAPI);
                    invDialog.TryOpen();
                }
            }

            if (packetid == (int)EnumBlockContainerPacketId.CloseInventory)
            {
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);

                invDialog?.TryClose();
                invDialog = null;
            }
        }
Ejemplo n.º 16
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            switch (packetid)
            {
            case (int)Packet.OpenGUI:
                using (MemoryStream ms = new MemoryStream(data))
                {
                    if (invDialog != null)
                    {
                        if (invDialog?.IsOpened() == true)
                        {
                            invDialog.TryClose();
                        }
                        invDialog?.Dispose();
                        invDialog = null;
                        return;
                    }

                    BinaryReader reader = new BinaryReader(ms);

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

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);

                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    invDialog = new GuiDialogTinkerTable(dialogTitle, Inventory, Pos, Api as ICoreClientAPI);

                    invDialog.TryOpen();
                }
                break;

            case (int)Packet.CloseGUI:
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
                if (invDialog?.IsOpened() == true)
                {
                    invDialog?.TryClose();
                }
                invDialog?.Dispose();
                invDialog = null;
                break;

            case (int)Packet.UpdateInv:
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);

                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();
                    invDialog?.SetupDialog();
                }
                break;
            }
        }