public void RemoveItem(IInventoryItem item) { ItemStack found = FindItem(item); if (found != null) { int quantity = found.Decrement(); if (itemStacked != null) { itemStacked(this, new InventoryStackEventArgs(item.itemName, found.Quantity)); } if (quantity <= 0) { mItems.Remove(found); if (itemRemoved != null) { itemRemoved(this, new InventoryEventArgs(item)); } } } else if (mItems.Count < SLOTS) { mItems.Add(new ItemStack(item)); //Add the item to the inventory item.OnPickUp(); //OnPickUp() method is called if (itemAdded != null) { itemAdded(this, new InventoryEventArgs(item)); //ItemAdded event raised and all the subscribers for this event are notified } } }
// Uses item in hand public void UseItem() { // If ain't aiming at anything if (!current.active) { return; } ItemStack its = playerEvents.GetSlotStack(); // If is holding no items if (its == null) { return; } Item it = its.GetItem(); // If is a placeable item if (it is IPlaceable) { IPlaceable itPlaceable = it as IPlaceable; // If block placement was successful in client if (this.PlaceBlock(itPlaceable.placeableBlockID)) { PlayerRaycast.lastBlockPlaced = it.id; if (its.Decrement()) { playerEvents.hotbar.SetNull(PlayerEvents.hotbarSlot); playerEvents.DestroyItemEntity(); } playerEvents.DrawHotbarSlot(PlayerEvents.hotbarSlot); playerEvents.invUIPlayer.DrawSlot(1, PlayerEvents.hotbarSlot); } } }