public void RemoveItems(short id, byte count) { if (count <= 0) { return; } 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 ItemAir(); } SendSetSlot(i); if (--count <= 0) { return; } } } }
public void Clear() { for (int i = 0; i < Slots.Count; ++i) { if (Slots[i] == null || Slots[i].Id != 0) { Slots[i] = new ItemAir(); } } if (Helmet.Id != 0) { Helmet = new ItemAir(); } if (Chest.Id != 0) { Chest = new ItemAir(); } if (Leggings.Id != 0) { Leggings = new ItemAir(); } if (Boots.Id != 0) { Boots = new ItemAir(); } Player.SendPlayerInventory(); }
protected virtual void ProcessDestroyAction(DestroyAction action, List <StackResponseContainerInfo> stackResponses) { byte count = action.Count; StackRequestSlotInfo source = action.Source; Item sourceItem = GetContainerItem(source.ContainerId, source.Slot); sourceItem.Count -= count; if (sourceItem.Count <= 0) { sourceItem = new ItemAir(); SetContainerItem(source.ContainerId, source.Slot, sourceItem); } stackResponses.Add(new StackResponseContainerInfo { ContainerId = source.ContainerId, Slots = new List <StackResponseSlotInfo> { new StackResponseSlotInfo() { Count = sourceItem.Count, Slot = source.Slot, HotbarSlot = source.Slot, StackNetworkId = sourceItem.UniqueId } } }); }
public virtual void DamageItemInHand(ItemDamageReason reason, Entity target, Block block) { if (Player.GameMode != GameMode.Survival) { return; } var itemInHand = GetItemInHand(); var unbreakingLevel = itemInHand.GetEnchantingLevel(EnchantingType.Unbreaking); if (unbreakingLevel > 0) { if (new Random().Next(1 + unbreakingLevel) != 0) { return; } } if (itemInHand.DamageItem(Player, reason, target, block)) { Slots[InHandSlot] = new ItemAir(); var sound = McpeLevelSoundEventOld.CreateObject(); sound.soundId = 5; sound.blockId = -1; sound.entityType = 1; sound.position = Player.KnownPosition; Player.Level.RelayBroadcast(sound); } SendSetSlot(InHandSlot); }
public virtual Item DamageArmorItem(Item item) { if (Player.GameMode != GameMode.Survival) { return(item); } var unbreakingLevel = item.GetEnchantingLevel(EnchantingType.Unbreaking); if (unbreakingLevel > 0) { if (new Random().Next(1 + unbreakingLevel) != 0) { return(item); } } item.Metadata++; if (item.Metadata >= item.Durability) { item = new ItemAir(); var sound = McpeLevelSoundEventOld.CreateObject(); sound.soundId = 5; sound.blockId = -1; sound.entityType = 1; sound.position = Player.KnownPosition; Player.Level.RelayBroadcast(sound); } return(item); }
public void Empty() { for (int i = 0; i < Slots.Length; i++) { Slots[i] = new ItemAir() { Count = 0 }; } }
public virtual void SetInventorySlot(int slot, Item item) { if (item == null || item.Count <= 0) { item = new ItemAir(); } UpdateInventorySlot(slot, item); SendSetSlot(slot); }
public virtual void SetInventorySlot(int slot, Item item, bool forceReplace = false) { if (item == null || item.Count <= 0) { item = new ItemAir(); } UpdateInventorySlot(slot, item, forceReplace); SendSetSlot(slot); }
public static Item ToItem(this string input) { Item item = new ItemAir(); input = input.Trim(' ', ';', '{', '}', '(', ')'); string[] ItemString = input.Split(','); if (ItemString.Length == 1) { return(ItemFactory.GetItem(Convert.ToInt16(ItemString[0]))); } item = ItemFactory.GetItem(Convert.ToInt16(ItemString[0]), Convert.ToInt16(ItemString[1])); return(item); }
public ItemStacks GetSlots() { ItemStacks slotData = new ItemStacks(); for (int i = 0; i < Slots.Count; i++) { if (Slots[i].Count == 0) { Slots[i] = new ItemAir(); } slotData.Add(Slots[i]); } return(slotData); }
public void DecreaseSlot(byte slot) { var slotData = Slots[slot]; if (slotData is ItemAir) return; slotData.Count--; if (slotData.Count <= 0) { slotData = new ItemAir(); } SetSlot(null, slot, slotData); OnInventoryChange(null, slot, slotData); }
public virtual void RemoveItems(short id, byte count) { for (byte i = 0; i < Slots.Length; i++) { var slot = Slots[i]; if (slot.Id == id) { slot.Count--; if (slot.Count == 0) { Slots[i] = new ItemAir(); } SendSetSlot(i); return; } } }
public PlayerInventory(Player player) { Player = player; Slots = Enumerable.Repeat((Item) new ItemAir(), InventorySize).ToList(); ItemHotbar = new int[HotbarSize]; for (byte i = 0; i < ItemHotbar.Length; i++) { ItemHotbar[i] = i; } InHandSlot = 0; Boots = new ItemAir(); Leggings = new ItemAir(); Chest = new ItemAir(); Helmet = new ItemAir(); }
public void SetSlot(int slot, Item item) { if (item == null) { item = new ItemAir(); } if (slot == 0) { Slot0 = item; _horse.SaddleHorse(item is ItemSaddle); } else if (slot == 1) { Slot1 = item; _horse.Chest = item; _horse.BroadcastArmor(); } }
protected virtual void ProcessDropAction(DropAction action, List <StackResponseContainerInfo> stackResponses) { byte count = action.Count; Item dropItem; StackRequestSlotInfo source = action.Source; Item sourceItem = GetContainerItem(source.ContainerId, source.Slot); if (sourceItem.Count == count || sourceItem.Count - count <= 0) { dropItem = sourceItem; sourceItem = new ItemAir(); sourceItem.UniqueId = 0; SetContainerItem(source.ContainerId, source.Slot, sourceItem); } else { dropItem = (Item)sourceItem.Clone(); sourceItem.Count -= count; dropItem.Count = count; dropItem.UniqueId = Environment.TickCount & Int32.MaxValue; } _player.DropItem(dropItem); stackResponses.Add(new StackResponseContainerInfo { ContainerId = source.ContainerId, Slots = new List <StackResponseSlotInfo> { new StackResponseSlotInfo() { Count = sourceItem.Count, Slot = source.Slot, HotbarSlot = source.Slot, StackNetworkId = sourceItem.UniqueId } } }); }
public void SetSlot(int index, Item value, bool isServerTransaction) { if (index < 0 || index >= Slots.Length) { throw new IndexOutOfRangeException(); } if (value.Count == 0) { value = new ItemAir() { Count = 0 }; } //var oldValue = Slots[index]; Set(index, value, !isServerTransaction); //Slots[index] = value; /*if ((index == 36 + _selectedSlot && !IsPeInventory) || (index == _selectedSlot && IsPeInventory)) * { * MainHand = value; * }*/ }
public void RemoveItems(short id, byte count) { if (count <= 0) { return; } for (byte i = 0; i < Slots.Count; i++) { if (count <= 0) { break; } var slot = Slots[i]; if (slot.Id == id) { if (Slots[i].Count >= count) { Slots[i].Count -= count; count = 0; } else { count -= Slots[i].Count; Slots[i].Count = 0; } if (slot.Count == 0) { Slots[i] = new ItemAir(); } SendSetSlot(i); } } }
public void SetSlot(int index, Item value, bool isServerTransaction) { if (index < 0 || index >= Slots.Length) { throw new IndexOutOfRangeException(); } if (value.Count == 0) { value = new ItemAir() { Count = 0 }; } var oldValue = Slots[index]; Slots[index] = value; /*if ((index == 36 + _selectedSlot && !IsPeInventory) || (index == _selectedSlot && IsPeInventory)) * { * MainHand = value; * }*/ SlotChanged?.Invoke(this, new SlotChangedEventArgs(InventoryId, index, value, oldValue, isServerTransaction)); }
protected virtual void ProcessTakeAction(TakeAction action, List <StackResponseContainerInfo> stackResponses) { byte count = action.Count; Item sourceItem; Item destItem; StackRequestSlotInfo source = action.Source; StackRequestSlotInfo destination = action.Destination; sourceItem = GetContainerItem(source.ContainerId, source.Slot); Log.Debug($"Take {sourceItem}"); if (sourceItem.Count == count || sourceItem.Count - count <= 0) { destItem = sourceItem; sourceItem = new ItemAir(); sourceItem.UniqueId = 0; SetContainerItem(source.ContainerId, source.Slot, sourceItem); } else { destItem = (Item)sourceItem.Clone(); sourceItem.Count -= count; destItem.Count = count; destItem.UniqueId = Environment.TickCount & Int32.MaxValue; } SetContainerItem(destination.ContainerId, destination.Slot, destItem); if (source.ContainerId == 21 || source.ContainerId == 22) { if (!(GetContainerItem(21, 14) is ItemAir) && !(GetContainerItem(22, 15) is ItemAir)) { Enchantment.SendEnchantments(_player, GetContainerItem(21, 14)); } else { Enchantment.SendEmptyEnchantments(_player); } } stackResponses.Add(new StackResponseContainerInfo { ContainerId = source.ContainerId, Slots = new List <StackResponseSlotInfo> { new StackResponseSlotInfo() { Count = sourceItem.Count, Slot = source.Slot, HotbarSlot = source.Slot, StackNetworkId = sourceItem.UniqueId } } }); stackResponses.Add(new StackResponseContainerInfo { ContainerId = destination.ContainerId, Slots = new List <StackResponseSlotInfo> { new StackResponseSlotInfo() { Count = destItem.Count, Slot = destination.Slot, HotbarSlot = destination.Slot, StackNetworkId = destItem.UniqueId } } }); }
public GuiPlayerInventoryDialog(Player player, Inventory inventory) { Player = player; Inventory = inventory; // Subscribe to events _guiHotBarInventoryItems = new InventoryContainerItem[inventory?.SlotCount ?? 0]; if (_guiHotBarInventoryItems.Length != 46) { throw new ArgumentOutOfRangeException(nameof(inventory), inventory?.SlotCount ?? 0, "Expected player inventory containing 46 slots."); } ContentContainer.Background = GuiTextures.InventoryPlayerBackground; ContentContainer.BackgroundOverlay = null; ContentContainer.Width = ContentContainer.MinWidth = ContentContainer.MaxWidth = 176; ContentContainer.Height = ContentContainer.MinHeight = ContentContainer.MaxHeight = 166; SetFixedSize(176, 166); ContentContainer.AutoSizeMode = AutoSizeMode.None; var modelRenderer = player.ModelRenderer; var mob = new PlayerMob(player.Name, player.Level, player.Network, player.ModelRenderer.Texture) { ModelRenderer = modelRenderer, }; ContentContainer.AddChild(_playerEntityModelView = new GuiEntityModelView(mob) { Margin = new Thickness(7, 25), Width = 49, Height = 70, Anchor = Alignment.TopLeft, AutoSizeMode = AutoSizeMode.None, Background = null, BackgroundOverlay = null }); Color color = Color.Blue; foreach (var slot in AddSlots(8, 84, 9, 27, 9, 0x00)) { // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f); slot.Item = Inventory[slot.InventoryIndex]; } color = Color.Aqua; foreach (var slot in AddSlots(8, 142, 9, 9, 0, 0)) { // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f); slot.Item = Inventory[slot.InventoryIndex]; } foreach (var slot in AddSlots(8, 8, 1, 4, 0, 120)) { var inventoryIndex = slot.InventoryIndex; Item item = new ItemAir(); switch (slot.InventoryIndex) { case 0: item = Inventory.Helmet; inventoryIndex = Inventory.HelmetSlot; break; case 1: item = Inventory.Chestplate; inventoryIndex = Inventory.ChestSlot; break; case 2: item = Inventory.Leggings; inventoryIndex = Inventory.LeggingsSlot; break; case 3: item = Inventory.Boots; inventoryIndex = Inventory.BootsSlot; break; } // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f); slot.Item = item; slot.InventoryIndex = inventoryIndex; } foreach (var slot in AddSlots(98, 18, 2, 4, 41, 0)) { slot.Item = Inventory[slot.InventoryIndex]; // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f); } CraftingOutput = AddSlot(154, 28, 45, 0); // CraftingOutput.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f); /*var shieldSlot = new InventoryContainerItem() * { * HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f), * Anchor = Alignment.TopLeft, * Margin = new Thickness(61, 76), * AutoSizeMode = AutoSizeMode.None, * Item = Inventory[40], * InventoryIndex = 40 * }; * * ContentContainer.AddChild(shieldSlot);*/ }
private void ExecutePickBlocks(BedrockTraceHandler caller) { var client = caller.Client; int count = 500; int yStart = 100; int x = 0; int z = 0; string fileName = Path.GetTempPath() + "pick_items_" + Guid.NewGuid() + ".json"; var writer = File.AppendText(fileName); var jsonSerializerSettings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.None, Formatting = Formatting.None, }; jsonSerializerSettings.Converters.Add(new NbtIntConverter()); jsonSerializerSettings.Converters.Add(new NbtStringConverter()); //BlockPalette palette = client.BlockPalette; BlockPalette palette = BlockFactory.BlockPalette; // only if we have updated it _resetEventPlayerHotbar.Reset(); for (int id = 0; id < count; id++) { try { { var request = new McpeCommandRequest(); request.command = $"/tp TheGrey {x} {150} {z}"; request.unknownUuid = new UUID(Guid.NewGuid().ToString()); client.SendPacket(request); } var block = BlockFactory.GetBlockById(id); if (block.GetType() == typeof(Block)) { continue; } if (block is Cocoa) { continue; // crashes on meta=15 } int y = yStart; for (int meta = 0; meta <= 15; meta++) { var blockstate = palette.FirstOrDefault(b => b.Id == id && b.Data == meta); if (blockstate == null) { continue; } blockstate.ItemInstance = null; // reset to nothing string name = blockstate.Name.Replace("minecraft:", ""); if (name == "double_plant" || name == "air" || name.StartsWith("element")) { break; } var pick = McpeBlockPickRequest.CreateObject(); pick.x = x; pick.y = y; pick.z = z; client.SendPacket(pick); //Thread.Sleep(100); if (!_resetEventPlayerHotbar.WaitOne(300)) { Log.Error($"No picked item for {id}, {meta}, {name}"); _lastSelectedItem = new ItemAir(); continue; //break; } // Investigate last selected item. This should be the one we picked Item item; lock (_lastSelectedItem) { item = _lastSelectedItem; _lastSelectedItem = new ItemAir(); } Log.Warn($"For {id}, {meta} we picked {item}"); blockstate.ItemInstance = new ItemPickInstance() { Id = item.Id, Metadata = item.Metadata, WantNbt = item.ExtraData != null }; string result = JsonConvert.SerializeObject(blockstate, jsonSerializerSettings); writer.WriteLine($"{item}; {result}"); writer.Flush(); if (blockstate.States.Count == 0) { break; } y += 2; } } finally { x += 2; } } writer.Close(); WritePaletteToJson(palette); Log.Warn("Finished!"); }
public GuiPlayerInventoryDialog(Player player, Inventory inventory) : base(inventory, GuiTextures.InventoryPlayerBackground, 176, 166) { Player = player; // Subscribe to events if (player != null) { var modelRenderer = player.ModelRenderer; var mob = new PlayerMob(player.Name, player.Level, player.Network, player.ModelRenderer.Texture) { ModelRenderer = modelRenderer, }; ContentContainer.AddChild( _playerEntityModelView = new GuiEntityModelView(mob) { Margin = new Thickness(7, 25), Width = 49, Height = 70, Anchor = Alignment.TopLeft, AutoSizeMode = AutoSizeMode.None, Background = null, BackgroundOverlay = null }); } Color color = Color.Blue; foreach (var slot in AddSlots(8, 84, 9, 27, 9, 0x00)) { // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f); slot.Item = Inventory[slot.InventoryIndex]; } color = Color.Aqua; foreach (var slot in AddSlots(8, 142, 9, 9, 0, 0)) { // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(color, 0.5f); slot.Item = Inventory[slot.InventoryIndex]; } foreach (var slot in AddSlots(8, 8, 1, 4, 0, 120)) { var inventoryIndex = slot.InventoryIndex; Item item = new ItemAir(); switch (slot.InventoryIndex) { case 0: item = inventory.Helmet; inventoryIndex = inventory.HelmetSlot; break; case 1: item = inventory.Chestplate; inventoryIndex = inventory.ChestSlot; break; case 2: item = inventory.Leggings; inventoryIndex = inventory.LeggingsSlot; break; case 3: item = inventory.Boots; inventoryIndex = inventory.BootsSlot; break; } // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Red, 0.5f); slot.Item = item; slot.InventoryIndex = inventoryIndex; } foreach (var slot in AddSlots(98, 18, 2, 4, 41, 0)) { slot.Item = Inventory[slot.InventoryIndex]; // slot.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f); } CraftingOutput = AddSlot(154, 28, 45, 0); // CraftingOutput.HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Purple, 0.5f); /*var shieldSlot = new InventoryContainerItem() * { * HighlightedBackground = new Microsoft.Xna.Framework.Color(Color.Orange, 0.5f), * Anchor = Alignment.TopLeft, * Margin = new Thickness(61, 76), * AutoSizeMode = AutoSizeMode.None, * Item = Inventory[40], * InventoryIndex = 40 * }; * * ContentContainer.AddChild(shieldSlot);*/ }
protected virtual void ProcessPlaceAction(PlaceAction action, List <StackResponseContainerInfo> stackResponses) { byte count = action.Count; Item sourceItem; Item destItem; StackRequestSlotInfo source = action.Source; StackRequestSlotInfo destination = action.Destination; sourceItem = GetContainerItem(source.ContainerId, source.Slot); if (sourceItem.Count == count || sourceItem.Count - count <= 0) { destItem = sourceItem; sourceItem = new ItemAir(); sourceItem.UniqueId = 0; SetContainerItem(source.ContainerId, source.Slot, sourceItem); } else { destItem = (Item)sourceItem.Clone(); sourceItem.Count -= count; destItem.Count = count; destItem.UniqueId = Environment.TickCount; } Item existingItem = GetContainerItem(destination.ContainerId, destination.Slot); if (existingItem.UniqueId > 0) // is empty/air is what this means { existingItem.Count += count; destItem = existingItem; } else { SetContainerItem(destination.ContainerId, destination.Slot, destItem); } if (destination.ContainerId == 21 || destination.ContainerId == 22) { if (!(GetContainerItem(21, 14) is ItemAir) && !(GetContainerItem(22, 15) is ItemAir)) { Enchantment.SendEnchantments(_player, GetContainerItem(21, 14)); } else { Enchantment.SendEmptyEnchantments(_player); } } stackResponses.Add(new StackResponseContainerInfo { ContainerId = source.ContainerId, Slots = new List <StackResponseSlotInfo> { new StackResponseSlotInfo() { Count = sourceItem.Count, Slot = source.Slot, HotbarSlot = source.Slot, StackNetworkId = sourceItem.UniqueId } } }); stackResponses.Add(new StackResponseContainerInfo { ContainerId = destination.ContainerId, Slots = new List <StackResponseSlotInfo> { new StackResponseSlotInfo() { Count = destItem.Count, Slot = destination.Slot, HotbarSlot = destination.Slot, StackNetworkId = destItem.UniqueId } } }); }