Advertisement
Guest User

matterJar

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