private void InventoryTransactionHandle(InventoryTransactionPacket pk) { List <InventoryAction> actions = new List <InventoryAction>(); for (int i = 0; i < pk.Actions.Length; ++i) { try { InventoryAction action = pk.Actions[i].GetInventoryAction(this); actions.Add(action); } catch (Exception e) { Logger.Log($"Unhandled inventory action from {this.Name}: {e.Message}"); this.SendAllInventories(); return; } } if (pk.TransactionType == InventoryTransactionPacket.TYPE_NORMAL) { InventoryTransaction transaction = new InventoryTransaction(this, actions); if (this.IsSpectator) { this.SendAllInventories(); return; } if (!transaction.Execute()) { Logger.Log($"Failed to execute inventory transaction from {this.Name} with actions"); } } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_MISMATCH) { this.SendAllInventories(); return; } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_USE_ITEM) { UseItemData data = (UseItemData)pk.TransactionData; Vector3 blockPos = data.BlockPos; BlockFace face = data.Face; if (data.ActionType == InventoryTransactionPacket.USE_ITEM_ACTION_CLICK_BLOCK) { this.SetFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_ACTION, false, true); if (this.CanInteract(blockPos + new Vector3(0.5f, 0.5f, 0.5f), this.IsCreative ? 13 : 7)) { Item item = this.Inventory.MainHandItem; this.World.UseItem(blockPos, item, face, data.ClickPos, this); } //Send MainHand } else if (data.ActionType == InventoryTransactionPacket.USE_ITEM_ACTION_BREAK_BLOCK) { Item item = this.Inventory.MainHandItem; if (this.CanInteract(blockPos + new Vector3(0.5f, 0.5f, 0.5f), this.IsCreative ? 13 : 7)) { this.World.UseBreak(data.BlockPos, item, this); if (this.IsSurvival) { //TODO : food this.Inventory.SendMainHand(); } } else { this.World.SendBlocks(new Player[] { this }, new Vector3[] { data.BlockPos }); } } } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_USE_ITEM_ON_ENTITY) { } else if (pk.TransactionType == InventoryTransactionPacket.TYPE_RELEASE_ITEM) { ReleaseItemData data = (ReleaseItemData)pk.TransactionData; if (data.ActionType == InventoryTransactionPacket.RELEASE_ITEM_ACTION_RELEASE) { } else if (data.ActionType == InventoryTransactionPacket.RELEASE_ITEM_ACTION_CONSUME) { if (this.Inventory.MainHandItem != data.MainHandItem || this.Inventory.MainHandSlot != data.HotbarSlot) { this.Inventory.SendMainHand(this); return; } Item item = this.Inventory.MainHandItem; if (!(item is IConsumeable)) { this.Inventory.SendMainHand(this); return; } IConsumeable consume = (IConsumeable)item; PlayerItemConsumeableEventArgs playerItemConsumeableEvent = new PlayerItemConsumeableEventArgs(this, consume); PlayerEvents.OnPlayerItemConsumeable(playerItemConsumeableEvent); if (playerItemConsumeableEvent.IsCancel) { this.Inventory.SendMainHand(this); return; } consume.OnConsume(this); } } }
public PlayerItemConsumeEventArgs(Player player, Item item, IConsumeable consume) : base(player) { this.Item = item; this.Consume = consume; }
public PlayerItemConsumeableEventArgs(Player player, IConsumeable consumeable) : base(player) { this.Consumeable = consumeable; }