TechMage66

SoulsHandler

Feb 9th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.techmage.magetech.handler;
  2.  
  3. import com.techmage.magetech.init.MageTechItems;
  4. import com.techmage.magetech.item.ItemShardSouls;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.item.ItemStack;
  7.  
  8. public class SoulsHandler
  9. {
  10.     public static ItemStack findShardWithSouls(EntityPlayer player, int amount)
  11.     {
  12.         for (int index = 0; index < player.inventory.getSizeInventory(); index ++)
  13.         {
  14.             ItemStack stack = player.inventory.getStackInSlot(index);
  15.  
  16.             if (stack != null && stack.getItem() == MageTechItems.shardSouls)
  17.             {
  18.                 if (((ItemShardSouls) stack.getItem()).getStoredSouls(stack) >= amount)
  19.                     return stack;
  20.             }
  21.         }
  22.  
  23.         return null;
  24.     }
  25.  
  26.     public static boolean hasEnoughSouls(EntityPlayer player, int amount)
  27.     {
  28.         return findShardWithSouls(player, amount) != null;
  29.     }
  30.  
  31.     public static void useSouls(EntityPlayer player, int amount)
  32.     {
  33.         if (hasEnoughSouls(player, amount))
  34.             ((ItemShardSouls) findShardWithSouls(player, amount).getItem()).useSouls(findShardWithSouls(player, amount), amount);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment