/// <summary> /// Called by a slot game object when it is clicked on. /// </summary> public virtual void onSlotClick(int i, bool leftBtn, bool rightBtn, bool middleBtn) { ContainerHeldItem cm = this.player.playerUI.heldItem; IItemBase heldStack = cm.getHeldItem(); IItemBase slotContents = this.contents.getItem(i); if (leftBtn) { if (heldStack == null && slotContents != null) { // Slot is empty, hand is occupied. Pick up the stack. cm.setHeldStack(slotContents); this.contents.setItem(i, null); } else if (heldStack != null && slotContents == null) { // Slot is occupied, hand is not. Drop off the stack. this.contents.setItem(i, heldStack); cm.setHeldStack(null); } else if (heldStack != null && slotContents != null) { // Both hand and slot have stuff. // Swap. IItemBase temp = slotContents; this.contents.setItem(i, heldStack); cm.setHeldStack(temp); } } }
public override void onTabClose() { base.onTabClose(); // Returns the held item to the players inventory. ContainerHeldItem hi = this.getPlayer().playerUI.heldItem; if (hi.getHeldItem() != null) { this.getPlayer().inventory.addItem((IItem)hi.getHeldItem()); hi.setHeldStack(null); } }