Guest User

Untitled

a guest
Jan 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.04 KB | None | 0 0
  1. public void trade(ItemStack item, int cost)
  2.     {
  3.         int totalErium = 0;
  4.         for (ItemStack stack: theplayer.inventory.mainInventory)
  5.             if (stack != null && stack.itemID == mod_ArcticCraft.eriumStone.shiftedIndex)
  6.                 totalErium += stack.stackSize;
  7.  
  8.         if (totalErium < cost)
  9.         {
  10.             theplayer.addChatMessage("You don't have enough Erium to make this trade.");
  11.             return;
  12.         }
  13.  
  14.         // removes the stuff from the inventory.
  15.         for (int i = 0; i < theplayer.inventory.mainInventory.length; i++)
  16.         {
  17.             ItemStack stack = theplayer.inventory.mainInventory[i];
  18.             if (stack != null && stack.itemID == mod_ArcticCraft.eriumStone.shiftedIndex)
  19.             {
  20.                 if (stack.stackSize >= cost)
  21.                 {
  22.                     stack.stackSize -= cost;
  23.                     if (stack.stackSize == 0)
  24.                         theplayer.inventory.mainInventory[i] = null;
  25.                     break; // or return, and and the method.
  26.                 }
  27.                
  28.                 else if (stack.stackSize < cost)
  29.                 {
  30.                     cost -= stack.stackSize;
  31.                     theplayer.inventory.mainInventory[i] = null;
  32.                 }
  33.             }
  34.         }
  35.  
  36.         theplayer.inventory.addItemStackToInventory(item);
  37.     }
Add Comment
Please, Sign In to add comment