Example #1
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());

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

            byte c = 0;
            Slots[c++] = new MetadataSlot(new ItemStack(54, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(58, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(61, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(325, 1, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(173, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(263, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(268, 10));
            Slots[c++] = new MetadataSlot(new ItemStack(280, 10));

            for (byte i = 0; i < 6; i++)
            {
                ItemHotbar[i] = new MetadataInt(i + 9);
            }
            //ItemHotbar[0] = new MetadataInt(9);
        }
Example #2
0
		public static MetadataSlots GetCreativeMetadataSlots()
		{
			var slotData = new MetadataSlots();
			for (int i = 0; i < CreativeInventoryItems.Count; i++)
			{
				slotData[i] = new MetadataSlot(CreativeInventoryItems[i]);
			}

			return slotData;
		}
Example #3
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, 1));
            //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);
            }
        }
Example #4
0
		public static MetadataSlots FromStream(BinaryReader stream)
		{
			var value = new MetadataSlots();
			while (true)
			{
				byte key = stream.ReadByte();
				if (key == 127) break;

				byte type = (byte) ((key & 0xE0) >> 5);
				byte index = (byte) (key & 0x1F);

				var entry = EntryTypes[type]();
				entry.FromStream(stream);
				entry.Index = index;

				value[index] = entry;
			}
			return value;
		}
Example #5
0
        public Inventory(int 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++)
            {
                Slots[i] = new MetadataSlot(new ItemStack());
            }

            for (byte i = 0; i < slots.Count; i++)
            {
                NbtCompound item = (NbtCompound) slots[i];

                Slots[item["Slot"].ByteValue] = new MetadataSlot(new ItemStack(item["id"].ShortValue, item["Count"].ByteValue, item["Damage"].ByteValue));
            }
        }
Example #6
0
        public static MetadataSlots FromStream(BinaryReader stream)
        {
            var value = new MetadataSlots();

            while (true)
            {
                byte key = stream.ReadByte();
                if (key == 127)
                {
                    break;
                }

                byte type  = (byte)((key & 0xE0) >> 5);
                byte index = (byte)(key & 0x1F);

                var entry = EntryTypes[type]();
                entry.FromStream(stream);
                entry.Index = index;

                value[index] = entry;
            }
            return(value);
        }
Example #7
0
		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);
					if (slot.Value.ExtraData == null)
					{
						Write((short)0);
					}
					else
					{
						var bytes = GetNbtData(slot.Value.ExtraData);
						Write((short)bytes.Length);
						Write(bytes);
					}
				}
			}
		}
Example #8
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;
        }
Example #9
0
        public MetadataSlots GetSlots()
        {
            var slotData = new MetadataSlots();
            for (int i = 0; i < Slots.Count; i++)
            {
                if (Slots[i].Count == 0) Slots[i] = new ItemStack();
                slotData[i] = new MetadataSlot(Slots[i]);
            }

            return slotData;
        }
Example #10
0
 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;
 }
Example #11
0
        public MetadataSlots GetSlots()
        {
            var slotData = new MetadataSlots();
            for (byte i = 0; i < Slots.Count; i++)
            {
                slotData[i] = new MetadataSlot(Slots[i]);
            }

            return slotData;
        }
Example #12
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);
				}

			}
		}
Example #13
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);
			//}

		}