Example #1
0
 /// <summary>
 /// Handle the mouse wheel event when gui is open
 /// </summary>
 /// <param name="currentContainer">current container</param>
 /// <param name="slotIndex">the slot mouse is over</param>
 private void handleMouseWheel(ContainerSlots currentContainer, int slotIndex)
 {
     if (Input.GetAxis("Mouse ScrollWheel") > 0f)
     {
         if (slotIndex >= 0 && slotIndex < currentContainer.Capacity)
         {
             Slot slot = currentContainer.GetSlotAt(slotIndex);
             if (containerCursor.itemStack == null && slot.itemStack != null)
             {
                 containerCursor.itemStack = slot.itemStack.Split(1);
             }
             else if (containerCursor.itemStack != null && slot.itemStack != null && slot.itemStack.mergeable(containerCursor.itemStack))
             {
                 slot.itemStack = containerCursor.itemStack.takeNumberReturnRemain(slot.itemStack, 1);
             }
         }
     }
     else if (Input.GetAxis("Mouse ScrollWheel") < 0f)
     {
         if (slotIndex >= 0 && slotIndex < currentContainer.Capacity)
         {
             Slot slot = currentContainer.GetSlotAt(slotIndex);
             if (containerCursor.itemStack != null && slot.IsEmpty())
             {
                 slot.itemStack = containerCursor.itemStack.Split(1);
             }
             else if (containerCursor.itemStack != null && slot.itemStack != null && slot.itemStack.mergeable(containerCursor.itemStack))
             {
                 containerCursor.itemStack = slot.itemStack.takeNumberReturnRemain(containerCursor.itemStack, 1);
             }
         }
     }
 }
Example #2
0
 /// <summary>
 /// Handle the mouse click event when the gui is open
 /// </summary>
 /// <param name="currentContainer"></param>
 /// <param name="slotIndex"></param>
 private void handleMouseClick(ContainerSlots currentContainer, int slotIndex)
 {
     if (slotIndex >= 0 && slotIndex < currentContainer.Capacity)
     {
         Slot slot = currentContainer.GetSlotAt(slotIndex);
         if (containerCursor.itemStack != null && slot.itemStack != null && slot.itemStack.mergeable(containerCursor.itemStack))
         {
             player.playerAudio.PlayOneShot(containerCursor.itemStack.GetClickSound());
             containerCursor.itemStack = slot.itemStack.mergeWith(containerCursor.itemStack);
         }
         else
         {
             if (containerCursor.itemStack != null || slot.itemStack != null)
             {
                 player.playerAudio.PlayOneShot((containerCursor.itemStack != null? containerCursor.itemStack : slot.itemStack).GetClickSound());
             }
             ItemStack tempStack = containerCursor.itemStack;
             containerCursor.itemStack = slot.itemStack;
             slot.itemStack            = tempStack;
         }
     }
 }