public static ItemStack FromStream(BinaryReader stream) { var slot = new ItemStack(); slot.Id = stream.ReadInt16(); slot.Count = stream.ReadByte(); slot.Metadata = stream.ReadInt16(); return slot; }
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); }
public PlayerMob(string name, Level level) : base(63, level) { Width = 0.6; Length = 0.6; Height = 1.80; IsSpawned = false; Name = name; Skin = new Skin {Slim = false, Texture = Encoding.Default.GetBytes(new string('Z', 8192))}; ItemInHand = new ItemStack(); }
/// <summary> /// Handles the container set slot. /// </summary> /// <param name="message">The message.</param> protected virtual 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); Inventory inventory = Level.InventoryManager.GetInventory(message.windowId); if (inventory != null) { // block inventories of various kinds (chests, furnace, etc) inventory.SetSlot((byte) message.slot, itemStack); return; } switch (message.windowId) { case 0: if (GameMode != GameMode.Creative && Inventory.Slots[(byte) message.slot].Id != itemStack.Id) { Log.Warn("Inventory set from client not matching inventory on server"); SendPlayerInventory(); } else if(GameMode == GameMode.Creative) { Inventory.Slots[(byte) message.slot] = itemStack; } break; case 0x78: switch ((byte) message.slot) { case 0: Inventory.Helmet = ItemFactory.GetItem(message.itemId, message.itemDamage); break; case 1: Inventory.Chest = ItemFactory.GetItem(message.itemId, message.itemDamage); break; case 2: Inventory.Leggings = ItemFactory.GetItem(message.itemId, message.itemDamage); break; case 3: Inventory.Boots = ItemFactory.GetItem(message.itemId, message.itemDamage); break; } break; } var armorEquipment = McpePlayerArmorEquipment.CreateObject(); armorEquipment.entityId = EntityId; armorEquipment.helmet = (byte) (Inventory.Helmet.Id - 256); armorEquipment.chestplate = (byte) (Inventory.Chest.Id - 256); armorEquipment.leggings = (byte) (Inventory.Leggings.Id - 256); armorEquipment.boots = (byte) (Inventory.Boots.Id - 256); Level.RelayBroadcast(this, armorEquipment); var playerEquipment = McpePlayerEquipment.CreateObject(); playerEquipment.entityId = EntityId; playerEquipment.item = (short) Inventory.ItemInHand.Id; playerEquipment.meta = Inventory.ItemInHand.Metadata; playerEquipment.slot = 0; Level.RelayBroadcast(this, playerEquipment); }
public override void FromStream(BinaryReader stream) { Value = ItemStack.FromStream(stream); }
private short GetFuelEfficiency(ItemStack itemStack) { Item item = ItemFactory.GetItem(itemStack.Id, itemStack.Metadata); return (short) (item.FuelEfficiency*20); }
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; }
private void OnInventoryChange(Player player, Inventory inventory, byte slot, ItemStack itemStack) { if (player == this) { //TODO: This needs to be synced to work properly under heavy load (SG). //Level.SetBlockEntity(inventory.BlockEntity, false); } else { var containerSetSlot = McpeContainerSetSlot.CreateObject(); containerSetSlot.windowId = inventory.WindowsId; containerSetSlot.slot = slot; containerSetSlot.item = new MetadataSlot(itemStack); SendPackage(containerSetSlot); } }
private bool FirstEmptySlot(short itemId, byte amount, short metadata, bool update, int si, Item item) { var b = Slots[si]; if (b.Id == itemId && b.Metadata == metadata && b.Count + amount <= item.MaxStackSize) { Slots[si].Count += amount; //if (update) Player.SendPlayerInventory(); if (update) SendSetSlot(si); Log.Info("Set on slot " + si); return true; } else if (b.Id == 0 || b.Id == -1) { Slots[si] = new ItemStack(itemId, amount, metadata); //if (update) Player.SendPlayerInventory(); if (update) SendSetSlot(si); Log.Info("Set on slot " + si); return true; } return false; }
protected virtual void OnInventoryChange(Player player, byte slot, ItemStack itemStack) { Action<Player, Inventory, byte, ItemStack> handler = InventoryChange; if (handler != null) handler(player, this, slot, itemStack); }
public void Write(ItemStack stack, bool signItem = true) { if (stack == null || stack.Id <= 0) { Write((short)0); return; } Write(stack.Id); Write(stack.Count); Write(stack.Metadata); NbtCompound extraData = stack.ExtraData; if (signItem) { extraData = ItemSigner.DefualtItemSigner?.SignNbt(extraData); } if (extraData != null) { byte[] bytes = GetNbtData(extraData); Write((short)bytes.Length); Write(bytes); } else { Write((short)0); } }
public bool HasItem(ItemStack item) { for (byte i = 0; i < Slots.Count; i++) { if ((Slots[i]).Id == item.Id && (Slots[i]).Metadata == item.Metadata) { return true; } } return false; }
public ItemStacks GetSlots() { ItemStacks slotData = new ItemStacks(); for (int i = 0; i < Slots.Count; i++) { if (Slots[i].Count == 0) Slots[i] = new ItemStack(); slotData.Add(Slots[i]); } return slotData; }
public virtual bool VerifyItemStack(Player player, ItemStack itemStack) { return true; }
private void OnInventoryChange(Inventory inventory, byte slot, ItemStack itemStack) { Level.SetBlockEntity(inventory.BlockEntity, false); SendPackage(new McpeContainerSetSlot() { windowId = inventory.Id, slot = slot, itemCount = itemStack.Count, itemId = itemStack.Id, itemDamage = itemStack.Metadata, }); }
public void SetInventorySlot(byte slot, short itemId, byte amount = 1, short metadata = 0) { if (slot > 35) throw new IndexOutOfRangeException("slot"); Slots[slot] = new ItemStack(itemId, amount, metadata); Player.SendPackage(new McpeContainerSetContent { windowId = 0, slotData = GetSlots(), hotbarData = GetHotbar() }); }
public MetadataSlot(ItemStack value) { Value = value; }
protected bool Equals(ItemStack other) { return Equals(Item, other.Item) && Count == other.Count; }
public void RemoveItems(short id, byte count) { for (byte i = 0; i < Slots.Count; i++) { var slot = Slots[i]; if (slot.Id == id) { slot.Count--; if(slot.Count == 0) { Slots[i] = new ItemStack(); } SendSetSlot(i); return; } } }
/// <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 virtual bool VerifyItemStack(ItemStack itemStack) { if (ItemSigner.DefualtItemSigner == null) return true; return ItemSigner.DefualtItemSigner.VerifyItemStack(this, itemStack); }
public void IncreaseSlot(Player player, byte slot, int itemId, short metadata) { var slotData = Slots[slot]; if (slotData.Id == 0) { slotData = new ItemStack((short) itemId, 1, metadata); } else { slotData.Count++; } OnInventoryChange(player, slot, slotData); }
public void SetInventorySlot(int slot, short itemId, byte amount = 1, short metadata = 0) { Slots[slot] = new ItemStack(itemId, amount, metadata); var containerSetContent = McpeContainerSetContent.CreateObject(); containerSetContent.windowId = 0; containerSetContent.slotData = GetSlots(); containerSetContent.hotbarData = GetHotbar(); Player.SendPackage(containerSetContent); }
public bool DecreaseSlot(Player player, byte slot) { bool isEmpty = false; var slotData = Slots[slot]; if (slotData.Id == 0 || slotData.Count <= 1) { slotData = new ItemStack(0, 0, 0); isEmpty = true; } else { slotData.Count--; } OnInventoryChange(player, slot, slotData); return isEmpty; }
private Item GetResult(ItemStack ingredient) { Item item = ItemFactory.GetItem(ingredient.Id, ingredient.Metadata); return item.GetSmelt(); }