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); } } } }
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); }
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); }
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); } } }
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 } } }
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); } }
public void Write(MetadataSlot slot) { if (slot != null) { Write(slot.Value.Id); Write(slot.Value.Count); Write(slot.Value.Metadata); } }
public void SetSlot(byte slot, ItemStack itemStack) { Slots[slot] = new MetadataSlot(itemStack); NbtCompound compound = BlockEntity.GetCompound(); compound["Items"] = GetSlots(); OnInventoryChange(slot, itemStack); }
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); }
/// <summary> /// Handles the player action. /// </summary> /// <param name="message">The message.</param> private void HandlePlayerAction(McpePlayerAction message) { Log.DebugFormat("Player action: {0}", message.actionId); Log.DebugFormat("Entity ID: {0}", message.entityId); Log.DebugFormat("Action ID: {0}", message.actionId); Log.DebugFormat("x: {0}", message.x); Log.DebugFormat("y: {0}", message.y); Log.DebugFormat("z: {0}", message.z); Log.DebugFormat("face: {0}", message.face); if (message.entityId != EntityId) { return; } switch (message.actionId) { case 5: // Shoot arrow { if (_itemUseTimer == null) { return; } MetadataSlot itemSlot = Inventory.ItemInHand; Item itemInHand = ItemFactory.GetItem(itemSlot.Value.Id); if (itemInHand == null) { return; // Cheat(?) } _itemUseTimer.Stop(); itemInHand.Release(Level, this, new BlockCoordinates(message.x, message.y, message.z), _itemUseTimer.ElapsedMilliseconds); _itemUseTimer = null; MetadataDictionary metadata = new MetadataDictionary(); metadata[0] = new MetadataByte(0); Level.RelayBroadcast(this, new McpeSetEntityData { entityId = EntityId, metadata = metadata, }); break; } case 7: // Respawn HandleRespawn(null); break; default: return; } }
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); }
public static MetadataSlots GetCreativeMetadataSlots() { var slotData = new MetadataSlots(); for (int i = 0; i < CreativeInventoryItems.Count; i++) { slotData[i] = new MetadataSlot(CreativeInventoryItems[i]); } return(slotData); }
private static void WriteInventoryToFile(string fileName, MetadataEntry[] slots) { Log.Info($"Writing inventory to filename: {fileName}"); FileStream file = File.OpenWrite(fileName); IndentedTextWriter writer = new IndentedTextWriter(new StreamWriter(file)); writer.WriteLine("// GENERATED CODE. DON'T EDIT BY HAND"); writer.Indent++; writer.Indent++; writer.WriteLine("public static List<ItemStack> CreativeInventoryItems = new List<ItemStack>()"); writer.WriteLine("{"); writer.Indent++; foreach (var entry in slots) { MetadataSlot slot = (MetadataSlot)entry; NbtCompound extraData = slot.Value.ExtraData; if (extraData == null) { writer.WriteLine($"new ItemStack({slot.Value.Id}, {slot.Value.Count}, {slot.Value.Metadata}),"); } else { Log.Debug($"Nbt: " + extraData.ToString()); NbtList ench = (NbtList)extraData["ench"]; NbtCompound enchComp = (NbtCompound)ench[0]; var id = enchComp["id"].ShortValue; var lvl = enchComp["lvl"].ShortValue; writer.WriteLine($"new ItemStack({slot.Value.Id}, {slot.Value.Count}, {slot.Value.Metadata}){{ExtraData = new NbtCompound {{new NbtList(\"ench\") {{new NbtCompound {{new NbtShort(\"id\", {id}), new NbtShort(\"lvl\", {lvl}) }} }} }} }},"); } } new ItemStack(0, 0, 0) { ExtraData = new NbtCompound { new NbtList("ench") { new NbtCompound { new NbtShort("id", 0), new NbtShort("lvl", 0) } } } }; //var compound = new NbtCompound(string.Empty) { new NbtList("ench", new NbtCompound()) {new NbtShort("id", 0),new NbtShort("lvl", 0),}, }; writer.Indent--; writer.WriteLine("};"); writer.Indent--; writer.Indent--; writer.Flush(); file.Close(); }
public void Interact(Level world, Player player, short itemId, BlockCoordinates blockCoordinates, short metadata) { // Make sure we are holding the item we claim to be using MetadataSlot itemSlot = player.Inventory.ItemInHand; Item itemInHand = ItemFactory.GetItem(itemSlot.Value.Id, metadata); if (itemInHand == null || itemInHand.Id != itemId) { return; // Cheat(?) } itemInHand.UseItem(world, player, blockCoordinates); }
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); Write((short)0); }
public MetadataSlot ReadMetadataSlot() { short id = ReadShort(); if (id == 0) { return(new MetadataSlot(new ItemStack())); } MetadataSlot metadataSlot = new MetadataSlot(new ItemStack(id, ReadByte(), ReadShort())); ReadShort(); // Nbt len return(metadataSlot); }
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); }
/// <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 }); }
public void IncreasteSlot(byte slot, int itemId, short metadata) { MetadataSlot slotData = (MetadataSlot)Slots[slot]; if (slotData.Value.Id == 0) { slotData.Value = new ItemStack((short)itemId, 1, metadata); } else { slotData.Value.Count++; } OnInventoryChange(slot, slotData.Value); }
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); }
/// <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 }); }
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); } }
public void Interact(Level world, Player player, short itemId, BlockCoordinates blockCoordinates, short metadata, BlockFace face, Vector3 faceCoords) { // Make sure we are holding the item we claim to be using MetadataSlot itemSlot = player.Inventory.ItemInHand; Item itemInHand = ItemFactory.GetItem(itemSlot.Value.Id, metadata); if (itemInHand == null || itemInHand.Id != itemId) { return; // Cheat(?) } Block target = GetBlock(blockCoordinates); if (target.Interact(world, player, blockCoordinates, face)) { return; // Handled in block interaction } itemInHand.UseItem(world, player, blockCoordinates, face, faceCoords); }
private NbtList GetSlots() { NbtList slots = new NbtList("Items"); for (byte i = 0; i < Size; i++) { MetadataSlot slot = (MetadataSlot)Slots[i]; slots.Add(new NbtCompound { new NbtByte("Count", slot.Value.Count), new NbtByte("Slot", i), new NbtShort("id", slot.Value.Id), new NbtByte("Damage", (byte)slot.Value.Metadata), }); } return(slots); }
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); }
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); } } } }
public bool DecreasteSlot(byte slot) { bool isEmpty = false; MetadataSlot slotData = (MetadataSlot)Slots[slot]; if (slotData.Value.Id == 0 || slotData.Value.Count <= 1) { slotData.Value = new ItemStack(0, 0, 0); isEmpty = true; } else { slotData.Value.Count--; } OnInventoryChange(slot, slotData.Value); return(isEmpty); }
public MetadataSlot ReadMetadataSlot() { short id = ReadShort(); if (id <= 0) { return(new MetadataSlot(new ItemStack())); } var stack = new ItemStack(id, ReadByte(), ReadShort()); var slot = new MetadataSlot(stack); int nbtLen = ReadShort(); // NbtLen if (nbtLen > 0) { stack.ExtraData = ReadNbt().NbtFile.RootTag; } return(slot); }
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); } } }
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()); } } }