コード例 #1
0
        public void Write(MetadataSlots metadata)
        {
            if (metadata == null)
            {
                Write((short)0);
                return;
            }

            Write((short)metadata.Count);

            for (byte i = 0; i < metadata.Count; i++)
            {
                if (!metadata.Contains(i))
                {
                    continue;
                }

                MetadataSlot slot = metadata[i] as MetadataSlot;
                if (slot != null)
                {
                    if (slot.Value.Id == 0)
                    {
                        Write((short)0);
                        continue;
                    }

                    Write(slot.Value.Id);
                    Write(slot.Value.Count);
                    Write(slot.Value.Metadata);
                    Write((short)0);                      // NBT Len
                }
            }
        }
コード例 #2
0
        public MetadataSlots ReadMetadataSlots()
        {
            short count = ReadShort();

            MetadataSlots metadata = new MetadataSlots();

            for (int i = 0; i < count; i++)
            {
                short id = ReadShort();
                if (id <= 0)
                {
                    metadata[i] = new MetadataSlot(new ItemStack());
                    continue;
                }

                metadata[i] = new MetadataSlot(new ItemStack(id, ReadByte(), ReadShort()));
                int nbtLen = ReadShort();                 // NbtLen
                if (nbtLen > 0)
                {
                    ReadBytes(nbtLen);                     // Slurp
                }
            }

            return(metadata);
        }
コード例 #3
0
        public void SendCraftingEvent()
        {
            var recipe = _recipeToSend;

            if (recipe != null)
            {
                {
                    McpeContainerSetSlot setSlot = new McpeContainerSetSlot();
                    setSlot.item     = new MetadataSlot(new ItemStack(new ItemBlock(new Block(17), 0), 1));
                    setSlot.windowId = 0;
                    setSlot.slot     = 0;
                    SendPackage(setSlot);
                }
                {
                    McpePlayerEquipment eq = new McpePlayerEquipment();
                    eq.entityId     = _entityId;
                    eq.slot         = 9;
                    eq.selectedSlot = 0;
                    eq.item         = new MetadataSlot(new ItemStack(new ItemBlock(new Block(17), 0), 1));
                    SendPackage(eq);
                }

                Log.Error("Sending crafting event: " + recipe.Id);

                McpeCraftingEvent crafting = new McpeCraftingEvent();
                crafting.windowId   = 0;
                crafting.recipeType = 1;
                crafting.recipeId   = recipe.Id;

                {
                    MetadataSlots slotData = new MetadataSlots();
                    slotData[0]    = new MetadataSlot(new ItemStack(new ItemBlock(new Block(17), 0), 1));
                    crafting.input = slotData;
                }
                {
                    MetadataSlots slotData = new MetadataSlots();
                    slotData[0]     = new MetadataSlot(new ItemStack(new ItemBlock(new Block(5), 0), 4));
                    crafting.result = slotData;
                }

                SendPackage(crafting);

                //{
                //	McpeContainerSetSlot setSlot = new McpeContainerSetSlot();
                //	setSlot.item = new MetadataSlot(new ItemStack(new ItemBlock(new Block(5), 0), 4));
                //	setSlot.windowId = 0;
                //	setSlot.slot = 0;
                //	SendPackage(setSlot);
                //}

                {
                    McpePlayerEquipment eq = new McpePlayerEquipment();
                    eq.entityId     = _entityId;
                    eq.slot         = 10;
                    eq.selectedSlot = 1;
                    eq.item         = new MetadataSlot(new ItemStack(new ItemBlock(new Block(5), 0), 4));
                    SendPackage(eq);
                }
            }
        }
コード例 #4
0
ファイル: Package.cs プロジェクト: Eros/MiNET
        public void Write(MetadataSlots metadata)
        {
            McpeContainerSetContent msg = this as McpeContainerSetContent;
            bool signItems = msg == null || msg.windowId != 0x79;

            if (metadata == null)
            {
                if (this is McpeCraftingEvent)
                {
                    Write((int)0);
                }
                else
                {
                    Write((short)0);
                }
                return;
            }

            if (this is McpeCraftingEvent)
            {
                Write((int)metadata.Count);
            }
            else
            {
                Write((short)metadata.Count);
            }


            for (int i = 0; i < metadata.Count; i++)
            {
                MetadataSlot slot = metadata[i] as MetadataSlot;
                if (slot != null)
                {
                    if (slot.Value.Id == 0)
                    {
                        Write((short)0);
                        continue;
                    }

                    Write(slot.Value.Id);
                    Write(slot.Value.Count);
                    Write(slot.Value.Metadata);
                    var extraData = slot.Value.ExtraData;
                    if (signItems)
                    {
                        extraData = ItemSigner.DefualtItemSigner?.SignNbt(extraData);
                    }
                    if (extraData != null)
                    {
                        var bytes = GetNbtData(extraData);
                        Write((short)bytes.Length);
                        Write(bytes);
                    }
                    else
                    {
                        Write((short)0);
                    }
                }
            }
        }
コード例 #5
0
        public MetadataSlots ReadMetadataSlots()
        {
            short count = ReadShort();

            MetadataSlots metadata = new MetadataSlots();

            for (int i = 0; i < count; i++)
            {
                short id = ReadShort();
                if (id <= 0)
                {
                    metadata[i] = new MetadataSlot(new ItemStack());
                    continue;
                }

                var stack = new ItemStack(id, ReadByte(), ReadShort());
                var slot  = new MetadataSlot(stack);
                metadata[i] = slot;
                int nbtLen = ReadShort();                 // NbtLen
                if (nbtLen > 0)
                {
                    stack.ExtraData = ReadNbt().NbtFile.RootTag;
                    //ReadBytes(nbtLen); // Slurp
                }
            }

            return(metadata);
        }
コード例 #6
0
ファイル: PlayerInventory.cs プロジェクト: ruslan81/MiNET
        public MetadataSlots GetArmor()
        {
            var slotData = new MetadataSlots();

            slotData[0] = new MetadataSlot(new ItemStack((short)Helmet.Id, 1, Helmet.Metadata));
            slotData[1] = new MetadataSlot(new ItemStack((short)Chest.Id, 1, Helmet.Metadata));
            slotData[2] = new MetadataSlot(new ItemStack((short)Leggings.Id, 1, Helmet.Metadata));
            slotData[3] = new MetadataSlot(new ItemStack((short)Boots.Id, 1, Helmet.Metadata));
            return(slotData);
        }
コード例 #7
0
ファイル: InventoryUtils.cs プロジェクト: vvzar/MiNET
        public static MetadataSlots GetCreativeMetadataSlots()
        {
            var slotData = new MetadataSlots();

            for (int i = 0; i < CreativeInventoryItems.Count; i++)
            {
                slotData[i] = new MetadataSlot(CreativeInventoryItems[i]);
            }

            return(slotData);
        }
コード例 #8
0
        public MetadataSlots ReadMetadataSlots()
        {
            short count = ReadShort();

            MetadataSlots metadata = new MetadataSlots();

            for (byte i = 0; i < count; i++)
            {
                metadata[i] = new MetadataSlot(new ItemStack(ReadShort(), ReadByte(), ReadShort()));
            }

            return(metadata);
        }
コード例 #9
0
        public bool Import(byte[] data)
        {
            using (MemoryStream stream = new MemoryStream(data))
            {
                NbtBinaryReader reader = new NbtBinaryReader(stream, false);

                Armor      = MetadataSlots.FromStream(reader);
                Slots      = MetadataSlots.FromStream(reader);
                ItemHotbar = MetadataInts.FromStream(reader);
            }

            return(true);
        }
コード例 #10
0
ファイル: PlayerInventory.cs プロジェクト: ruslan81/MiNET
        public MetadataSlots GetSlots()
        {
            var slotData = new MetadataSlots();

            for (byte i = 0; i < Slots.Count; i++)
            {
                if (Slots[i].Count == 0)
                {
                    Slots[i] = new ItemStack();
                }
                slotData[i] = new MetadataSlot(Slots[i]);
            }

            return(slotData);
        }
コード例 #11
0
        public PlayerInventory(Player player)
        {
            _player    = player;
            Armor      = new MetadataSlots();
            Slots      = new MetadataSlots();
            ItemHotbar = new MetadataInts();
            ItemInHand = new MetadataSlot(new ItemStack());

            Armor[0] = new MetadataSlot(new ItemStack());
            Armor[1] = new MetadataSlot(new ItemStack());
            Armor[2] = new MetadataSlot(new ItemStack());
            Armor[3] = new MetadataSlot(new ItemStack());

            //Armor[0] = new MetadataSlot(new ItemStack(306));
            //Armor[1] = new MetadataSlot(new ItemStack(307));
            //Armor[2] = new MetadataSlot(new ItemStack(308));
            //Armor[3] = new MetadataSlot(new ItemStack(309));

            for (byte i = 0; i < 35; i++)
            {
                Slots[i] = new MetadataSlot(new ItemStack((short)-1, 0));
            }

            byte c = 0;

            //Slots[c++] = new MetadataSlot(new ItemStack(383, 1, 34));
            //Slots[c++] = new MetadataSlot(new ItemStack(355, 64));
            Slots[c++] = new MetadataSlot(new ItemStack(261, 1));             // Bow
            Slots[c++] = new MetadataSlot(new ItemStack(262, 64));            // Arrows
            Slots[c++] = new MetadataSlot(new ItemStack(344, 64));            // Eggs
            Slots[c++] = new MetadataSlot(new ItemStack(332, 64));            // Snowballs
            //Slots[c++] = new MetadataSlot(new ItemStack(46, 64));
            //Slots[c++] = new MetadataSlot(new ItemStack(259, 1));
            Slots[c++] = new MetadataSlot(new ItemStack(268, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(280, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(290, 1));
            //Slots[c++] = new MetadataSlot(new ItemStack(259, 1)); // Flint/Steal
            //Slots[c++] = new MetadataSlot(new ItemStack(325, 64, 8)); // Water
            //Slots[c++] = new MetadataSlot(new ItemStack(325, 64, 10)); // Lava

            for (byte i = 0; i < 6; i++)
            {
                ItemHotbar[i] = new MetadataInt(i + 9);
            }
        }
コード例 #12
0
ファイル: Package.cs プロジェクト: Encritary/MiNET
        public MetadataSlots ReadMetadataSlots()
        {
            int count;

            if (this is McpeCraftingEvent)
            {
                // Misaligned array counters for some packets :-(
                count = ReadInt();
            }
            else
            {
                count = ReadShort();
            }

            MetadataSlots metadata = new MetadataSlots();

            for (int i = 0; i < count; i++)
            {
                short id = ReadShort();
                if (id <= 0)
                {
                    metadata[i] = new MetadataSlot(new ItemStack());
                    continue;
                }

                var stack = new ItemStack(id, ReadByte(), ReadShort());
                var slot  = new MetadataSlot(stack);
                metadata[i] = slot;
                if (stack.Count == 0)
                {
                    continue;
                }

                int nbtLen = ReadShort();                 // NbtLen
                if (nbtLen > 0)
                {
                    var nbt = ReadNbt();
                    stack.ExtraData = nbt.NbtFile.RootTag;
                }
            }

            return(metadata);
        }
コード例 #13
0
ファイル: McpeWriter.cs プロジェクト: Eros/MiNET
        public void Write(MetadataSlots metadata)
        {
            if (metadata == null)
            {
                Write((short)0);
                return;
            }

            Write((short)metadata.Count);

            for (int i = 0; i < metadata.Count; i++)
            {
                //if (!metadata.Contains(i)) continue;

                MetadataSlot slot = metadata[i] as MetadataSlot;
                if (slot != null)
                {
                    if (slot.Value.Id == 0)
                    {
                        Write((short)0);
                        continue;
                    }

                    Write(slot.Value.Id);
                    Write(slot.Value.Count);
                    Write(slot.Value.Metadata);
                    var extraData = slot.Value.ExtraData;
                    extraData = ItemSigner.DefualtItemSigner?.SignNbt(extraData, true);

                    if (extraData != null)
                    {
                        var bytes = GetNbtData(extraData);
                        Write((short)bytes.Length);
                        Write(bytes);
                    }
                    else
                    {
                        Write((short)0);
                    }
                }
            }
        }
コード例 #14
0
        public void Write(MetadataSlots metadata)
        {
            if (metadata == null)
            {
                Write((short)0);
                return;
            }

            Write((short)metadata.Count);

            for (byte i = 0; i < metadata.Count; i++)
            {
                MetadataSlot slot = metadata[i] as MetadataSlot;
                if (slot != null)
                {
                    Write(slot.Value.Id);
                    Write(slot.Value.Count);
                    Write(slot.Value.Metadata);
                }
            }
        }
コード例 #15
0
        public Inventory(byte id, BlockEntity blockEntity, short inventorySize, NbtList slots)
        {
            Id          = id;
            BlockEntity = blockEntity;
            Size        = inventorySize;
            Coordinates = BlockEntity.Coordinates;

            Slots = new MetadataSlots();
            for (byte i = 0; i < Size; i++)
            {
                if (i < slots.Count)
                {
                    NbtCompound item = (NbtCompound)slots[i];
                    Slots[i] = new MetadataSlot(new ItemStack(item["id"].ShortValue, item["Count"].ByteValue));
                }
                else
                {
                    Slots[i] = new MetadataSlot(new ItemStack());
                }
            }
        }
コード例 #16
0
        public void SendCraftingEvent2()
        {
            var recipe = _recipeToSend;

            if (recipe != null)
            {
                Log.Error("Sending crafting event: " + recipe.Id);

                McpeCraftingEvent crafting = new McpeCraftingEvent();
                crafting.windowId   = 0;
                crafting.recipeType = 1;
                crafting.recipeId   = recipe.Id;

                {
                    var slotData = new MetadataSlots();
                    for (int i = 0; i < recipe.Input.Length; i++)
                    {
                        slotData[i] = new MetadataSlot(new ItemStack(recipe.Input[i], 1));

                        McpeContainerSetSlot setSlot = new McpeContainerSetSlot
                        {
                            item     = new MetadataSlot(new ItemStack(recipe.Input[i], 1)),
                            windowId = 0,
                            slot     = (short)(i)
                        };
                        SendPackage(setSlot);
                        Log.Error("Set set slot");
                    }
                    crafting.input = slotData;

                    {
                        McpePlayerEquipment eq = new McpePlayerEquipment
                        {
                            entityId     = _entityId,
                            slot         = 9,
                            selectedSlot = 0,
                            item         = new MetadataSlot(new ItemStack(recipe.Input[0], 1))
                        };
                        SendPackage(eq);
                        Log.Error("Set eq slot");
                    }
                }
                {
                    MetadataSlots slotData = new MetadataSlots();
                    slotData[0]     = new MetadataSlot(recipe.Result);
                    crafting.result = slotData;
                }

                SendPackage(crafting);
            }


            //{
            //	McpeContainerSetSlot setSlot = new McpeContainerSetSlot();
            //	setSlot.item = new MetadataSlot(new ItemStack(new ItemDiamondAxe(0), 1));
            //	setSlot.windowId = 0;
            //	setSlot.slot = 0;
            //	SendPackage(setSlot);
            //}
            //{
            //	McpePlayerEquipment eq = new McpePlayerEquipment();
            //	eq.entityId = _entityId;
            //	eq.slot = 9;
            //	eq.selectedSlot = 0;
            //	eq.item = new MetadataSlot(new ItemStack(new ItemDiamondAxe(0), 1));
            //	SendPackage(eq);
            //}
        }