TechMage66

ItemSharedSouls

Feb 9th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. package com.techmage.magetech.item;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.item.ItemStack;
  5. import net.minecraft.nbt.NBTTagCompound;
  6. import net.minecraft.world.World;
  7. import net.minecraftforge.fml.relauncher.Side;
  8. import net.minecraftforge.fml.relauncher.SideOnly;
  9.  
  10. import java.util.List;
  11.  
  12. public class ItemShardSouls extends ItemMageTech
  13. {
  14.     private static final int maxSouls = 5000;
  15.  
  16.     public ItemShardSouls()
  17.     {
  18.         super();
  19.  
  20.         this.setMaxStackSize(1);
  21.     }
  22.  
  23.     @Override
  24.     public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
  25.     {
  26.         if (hasSoulsTag(itemStackIn))
  27.         {
  28.             if (itemStackIn.getTagCompound().getInteger("storedSouls") + 100 <= maxSouls)
  29.                 itemStackIn.getTagCompound().setInteger("storedSouls", itemStackIn.getTagCompound().getInteger("storedSouls") + 100);
  30.  
  31.             else
  32.                 itemStackIn.getTagCompound().setInteger("storedSouls", maxSouls);
  33.         }
  34.  
  35.         else
  36.         {
  37.             itemStackIn.setTagCompound(new NBTTagCompound());
  38.             itemStackIn.getTagCompound().setInteger("storedSouls", 100);
  39.         }
  40.  
  41.         return itemStackIn;
  42.     }
  43.  
  44.     @Override
  45.     @SideOnly(Side.CLIENT)
  46.     public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
  47.     {
  48.         if (hasSoulsTag(stack))
  49.             tooltip.add(stack.getTagCompound().getInteger("storedSouls") + " : " + maxSouls);
  50.  
  51.         else
  52.             tooltip.add("0 : " + maxSouls);
  53.     }
  54.  
  55.     private boolean hasSoulsTag(ItemStack stack)
  56.     {
  57.         return stack.hasTagCompound() && stack.getTagCompound().hasKey("storedSouls");
  58.     }
  59.  
  60.     public int getStoredSouls(ItemStack stack)
  61.     {
  62.         if (hasSoulsTag(stack))
  63.             return stack.getTagCompound().getInteger("storedSouls");
  64.  
  65.         else
  66.             return 0;
  67.     }
  68.  
  69.     public void useSouls(ItemStack stack, int amount)
  70.     {
  71.         if (hasSoulsTag(stack))
  72.             stack.getTagCompound().setInteger("storedSouls", stack.getTagCompound().getInteger("storedSouls") - amount);
  73.     }
  74. }
Add Comment
Please, Sign In to add comment