Guest User

ItemRegenerationStone.java

a guest
Aug 8th, 2015
193
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package noahc3.abilitystones.items;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.entity.Entity;
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.item.Item;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.nbt.NBTTagCompound;
  11. import net.minecraft.potion.Potion;
  12. import net.minecraft.potion.PotionEffect;
  13. import net.minecraft.util.EnumChatFormatting;
  14. import net.minecraft.world.World;
  15. import net.minecraftforge.fml.relauncher.Side;
  16. import net.minecraftforge.fml.relauncher.SideOnly;
  17.  
  18. public class ItemRegenerationStone extends Item
  19. {
  20. public static void debugState(System system, ItemStack stack) //remove when done debugging
  21. {
  22. System.out.println(stack.getTagCompound().getInteger("Enabled"));
  23. }
  24.  
  25.  
  26. @Override
  27. public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn)
  28. {
  29. if(stack.getTagCompound().getInteger("Enabled") == 1 && stack.getTagCompound().getInteger("Cooldown") == 0)
  30. {
  31. stack.clearCustomName();
  32. stack.getTagCompound().setInteger("Enabled", 0);
  33. stack.getTagCompound().setInteger("Cooldown", 20);
  34. debugState(null, stack); //remove when done debugging
  35. return stack;
  36. }
  37. else if(stack.getTagCompound().getInteger("Enabled") == 0 && stack.getTagCompound().getInteger("Cooldown") == 0)
  38. {
  39. stack.setStackDisplayName(EnumChatFormatting.AQUA + "Regeneration Stone");
  40. stack.getTagCompound().setInteger("Enabled", 1);
  41. stack.getTagCompound().setInteger("Cooldown", 20);
  42. debugState(null, stack); //remove when done debugging
  43. return stack;
  44. }
  45. return stack;
  46.  
  47. }
  48.  
  49. @Override
  50. @SideOnly(Side.CLIENT)
  51. public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced)
  52. {
  53.  
  54. }
  55.  
  56. @SideOnly(Side.CLIENT)
  57. public boolean hasEffect(ItemStack stack)
  58. {
  59. if (!(stack.getTagCompound() == null))
  60. {
  61. if (stack.getTagCompound().getInteger("Enabled") == 1)
  62. {
  63. return true;
  64. }
  65. else if (stack.getTagCompound().getInteger("Enabled") == 0)
  66. {
  67. return false;
  68. }
  69. }
  70.  
  71. return false;
  72. }
  73.  
  74. @Override
  75. public void onUpdate(ItemStack stack, World world, Entity entity, int metadata, boolean bool)
  76. {
  77. if (stack.getTagCompound() == null)
  78. {
  79. stack.setTagCompound(new NBTTagCompound());
  80. stack.getTagCompound().setInteger("Enabled", 0);
  81. stack.getTagCompound().setInteger("Cooldown", 0);
  82. stack.getTagCompound().setInteger("Timer", 23999);
  83. }
  84.  
  85. if (stack.getTagCompound().getInteger("Enabled") == 1)
  86. {
  87.  
  88. ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.regeneration.id, 1, 2));
  89.  
  90. if (stack.getTagCompound().getInteger("Timer") > 0)
  91. {
  92. stack.getTagCompound().setInteger("Timer", stack.getTagCompound().getInteger("Timer") + -1);
  93. }
  94.  
  95.  
  96. }
  97. else if (stack.getTagCompound().getInteger("Enabled") == 0)
  98. {
  99.  
  100. }
  101.  
  102. if (stack.getTagCompound().getInteger("Cooldown") > 0)
  103. {
  104. stack.getTagCompound().setInteger("Cooldown", stack.getTagCompound().getInteger("Cooldown") + -1);
  105. }
  106. }
  107. }
RAW Paste Data