private void BlockPickRequestHandle(BlockPickRequestPacket pk) { if (!this.IsCreative) { return; } Block block = this.World.GetBlock(pk.Position); Item item = block.Item; //TODO : block entity nbt PlayerBlockPickRequestEventArgs args = new PlayerBlockPickRequestEventArgs(this, item); PlayerEvents.OnPlayerBlockPickRequest(args); if (args.IsCancel) { return; } List <int> air = new List <int>(); for (int i = 0; i < pk.HotbarSlot; ++i) { Item slot = this.Inventory.GetItem(i); if (slot == item) { this.Inventory.MainHandSlot = i; this.Inventory.SendMainHand(this); return; } if (slot.ID == BlockFactory.AIR) { air.Add(i); } } if (air.Count == 0 || this.Inventory.MainHandItem.ID == BlockFactory.AIR) { this.Inventory.MainHandItem = item; this.Inventory.SendMainHand(this); return; } this.Inventory.MainHandSlot = air[0]; this.Inventory.MainHandItem = item; this.Inventory.SendMainHand(this); }
public static void OnPlayerBlockPickRequest(PlayerBlockPickRequestEventArgs args) { PlayerBlockPickRequest?.Invoke(args); }