예제 #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);
        }
예제 #2
0
		public void SetSlot(Player player, byte slot, ItemStack itemStack)
		{
			Slots[slot] = new MetadataSlot(itemStack);

			NbtCompound compound = BlockEntity.GetCompound();
			compound["Items"] = GetSlots();

			OnInventoryChange(player, slot, itemStack);
		}
예제 #3
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;
		}
예제 #4
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);
            }
        }
예제 #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));
            }
        }
예제 #6
0
        /// <summary>
        ///     Set a players slot to the specified item.
        /// </summary>
        /// <param name="slot">The slot to set</param>
        /// <param name="itemId">The item id</param>
        /// <param name="amount">Amount of items</param>
        /// <param name="metadata">Metadata for the item</param>
        public void SetInventorySlot(byte slot, short itemId, byte amount = 1, short metadata = 0)
        {
            if (slot > 35) throw new IndexOutOfRangeException("slot");
            Slots[slot] = new MetadataSlot(new ItemStack(itemId, amount, metadata));

            _player.SendPackage(new McpeContainerSetContent
            {
                windowId = 0,
                slotData = Slots,
                hotbarData = ItemHotbar
            });
        }
예제 #7
0
 public bool HasItem(MetadataSlot item)
 {
     for (byte i = 0; i < Slots.Count; i++)
     {
         if (((MetadataSlot)Slots[i]).Value.Id == item.Value.Id && ((MetadataSlot)Slots[i]).Value.Metadata == item.Value.Metadata)
         {
             return true;
         }
     }
     return false;
 }
예제 #8
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;
        }
예제 #9
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;
 }
예제 #10
0
 public MetadataSlot GetMetadataSlot()
 {
     MetadataSlot metadataSlot = new MetadataSlot(new ItemStack((short) Item.Id, (byte) Item.Metadata, Count));
     return metadataSlot;
 }
예제 #11
0
		public void Write(MetadataSlot slot)
		{
			if (slot == null || slot.Value.Id <= 0)
			{
				Write((short) 0);
				return;
			}

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

            return slotData;
        }
예제 #13
0
        /// <summary>
        ///     Handles the container set slot.
        /// </summary>
        /// <param name="message">The message.</param>
        private void HandleContainerSetSlot(McpeContainerSetSlot message)
        {
            if (HealthManager.IsDead) return;

            // on all set container content, check if we have active inventory
            // and update that inventory.
            // Inventory manager makes sure other players with the same inventory open will
            // also get the update.

            var itemStack = new ItemStack(message.itemId, message.itemCount, message.itemDamage);
            var metadataSlot = new MetadataSlot(itemStack);

            Inventory inventory = Level.InventoryManager.GetInventory(message.windowId);
            if (inventory != null)
            {
                inventory.SetSlot((byte) message.slot, itemStack);
                return;
            }

            switch (message.windowId)
            {
                case 0:
                    Inventory.Slots[(byte) message.slot] = metadataSlot;
                    break;
                case 0x78:
                    Inventory.Armor[(byte) message.slot] = metadataSlot;
                    break;
            }

            Level.RelayBroadcast(this, new McpePlayerArmorEquipment()
            {
                entityId = EntityId,
                helmet = (byte) (((MetadataSlot) Inventory.Armor[0]).Value.Id - 256),
                chestplate = (byte) (((MetadataSlot) Inventory.Armor[1]).Value.Id - 256),
                leggings = (byte) (((MetadataSlot) Inventory.Armor[2]).Value.Id - 256),
                boots = (byte) (((MetadataSlot) Inventory.Armor[3]).Value.Id - 256)
            });

            Level.RelayBroadcast(this, new McpePlayerEquipment()
            {
                entityId = EntityId,
                item = Inventory.ItemInHand.Value.Id,
                meta = Inventory.ItemInHand.Value.Metadata,
                slot = 0
            });
        }
예제 #14
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);
				}

			}
		}
예제 #15
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);
			//}

		}
예제 #16
0
		public void Write(MetadataSlot slot)
		{
			if (slot == null || slot.Value.Id <= 0)
			{
				Write((short)0);
				return;
			}

			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);
			}
		}
예제 #17
0
        public void Kit(Player player, int kitId)
        {
            var armor = player.Inventory.Armor;
            var slots = player.Inventory.Slots;

            switch (kitId)
            {
                case 0:
                    // Kit leather tier
                    armor[0] = new MetadataSlot(new ItemStack(298)); // Helmet
                    armor[1] = new MetadataSlot(new ItemStack(299)); // Chest
                    armor[2] = new MetadataSlot(new ItemStack(300)); // Leggings
                    armor[3] = new MetadataSlot(new ItemStack(301)); // Boots
                    break;
                case 1:
                    // Kit gold tier
                    armor[0] = new MetadataSlot(new ItemStack(314)); // Helmet
                    armor[1] = new MetadataSlot(new ItemStack(315)); // Chest
                    armor[2] = new MetadataSlot(new ItemStack(316)); // Leggings
                    armor[3] = new MetadataSlot(new ItemStack(317)); // Boots
                    break;
                case 2:
                    // Kit chain tier
                    armor[0] = new MetadataSlot(new ItemStack(302)); // Helmet
                    armor[1] = new MetadataSlot(new ItemStack(303)); // Chest
                    armor[2] = new MetadataSlot(new ItemStack(304)); // Leggings
                    armor[3] = new MetadataSlot(new ItemStack(305)); // Boots
                    break;
                case 3:
                    // Kit iron tier
                    armor[0] = new MetadataSlot(new ItemStack(306)); // Helmet
                    armor[1] = new MetadataSlot(new ItemStack(307)); // Chest
                    armor[2] = new MetadataSlot(new ItemStack(308)); // Leggings
                    armor[3] = new MetadataSlot(new ItemStack(309)); // Boots
                    break;
                case 4:
                    // Kit diamond tier
                    armor[0] = new MetadataSlot(new ItemStack(310)); // Helmet
                    armor[1] = new MetadataSlot(new ItemStack(311)); // Chest
                    armor[2] = new MetadataSlot(new ItemStack(312)); // Leggings
                    armor[3] = new MetadataSlot(new ItemStack(313)); // Boots
                    break;
            }

            byte c = 0;
            slots[c++] = new MetadataSlot(new ItemStack(268, 1)); // Wooden Sword
            slots[c++] = new MetadataSlot(new ItemStack(283, 1)); // Golden Sword
            slots[c++] = new MetadataSlot(new ItemStack(272, 1)); // Stone Sword
            slots[c++] = new MetadataSlot(new ItemStack(267, 1)); // Iron Sword
            slots[c++] = new MetadataSlot(new ItemStack(276, 1)); // Diamond Sword

            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

            player.SendPackage(new McpeContainerSetContent
            {
                windowId = 0,
                slotData = player.Inventory.Slots,
                hotbarData = player.Inventory.ItemHotbar
            });

            player.SendPackage(new McpeContainerSetContent
            {
                windowId = 0x78, // Armor windows ID
                slotData = player.Inventory.Armor,
                hotbarData = null
            });

            SendEquipmentForPlayer(player);
            SendArmorForPlayer(player);

            player.Level.BroadcastTextMessage(string.Format("Player {0} changed kit.", player.Username), type: MessageType.Raw);
        }