Fatcatgaming3603

Untitled

Apr 14th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. package com.androbean.zcp.items;
  2.  
  3. import mod.akrivus.kagic.entity.EntityGem;
  4. import mod.akrivus.kagic.init.ModCreativeTabs;
  5. import mod.akrivus.kagic.util.PoofDamage;
  6. import net.minecraft.enchantment.Enchantment;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.item.IItemPropertyGetter;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.nbt.NBTTagCompound;
  13. import net.minecraft.util.ActionResult;
  14. import net.minecraft.util.EnumActionResult;
  15. import net.minecraft.util.EnumHand;
  16. import net.minecraft.util.ResourceLocation;
  17. import net.minecraft.util.math.MathHelper;
  18. import net.minecraft.world.World;
  19. import net.minecraftforge.fml.relauncher.Side;
  20. import net.minecraftforge.fml.relauncher.SideOnly;
  21.  
  22. public class ItemGemRejuvenator extends Item {
  23. public ItemGemRejuvenator() {
  24. super();
  25. this.setCreativeTab(ModCreativeTabs.CREATIVE_TAB_OTHER);
  26. this.setUnlocalizedName("gem_rejuvenator");
  27. this.setMaxStackSize(1);
  28. this.addPropertyOverride(new ResourceLocation("primed"), new IItemPropertyGetter() {
  29. @Override
  30. @SideOnly(Side.CLIENT)
  31. public float apply(ItemStack stack, World world, EntityLivingBase entity) {
  32. if (stack.hasTagCompound()) {
  33. return stack.getTagCompound().getBoolean("Primed") ? 1.0F : 0.0F;
  34. }
  35. return 0.0F;
  36. }
  37. });
  38. }
  39.  
  40. @Override
  41. public int getMaxItemUseDuration(ItemStack stack) {
  42. return 40;
  43. }
  44.  
  45. @Override
  46. public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entity, int timeLeft) {
  47. if (!world.isRemote && entity instanceof EntityPlayer) {
  48. EntityPlayer player = (EntityPlayer) entity;
  49. player.getCooldownTracker().setCooldown(this, 0);
  50. }
  51. }
  52.  
  53. @Override
  54. public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entity) {
  55. NBTTagCompound compound = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
  56. compound.setBoolean("Primed", true);
  57. stack.setTagCompound(compound);
  58. return stack;
  59. }
  60.  
  61. @Override
  62. public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
  63. ItemStack stack = player.getHeldItem(hand);
  64. player.setActiveHand(hand);
  65. if (!stack.hasTagCompound() || !stack.getTagCompound().getBoolean("Primed")) {
  66. player.getCooldownTracker().setCooldown(this, 60);
  67. }
  68. return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
  69. }
  70.  
  71. @Override
  72. public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
  73. if (stack.hasTagCompound()) {
  74. if (target instanceof EntityGem) {
  75. if (stack.getTagCompound().getBoolean("Primed")) {
  76. ((EntityGem) target).setOwnerId("0");
  77. target.attackEntityFrom(new PoofDamage(), target.getMaxHealth());
  78. this.Rejuvenate((EntityGem) target);
  79. stack.getTagCompound().setBoolean("Primed", false);
  80. }
  81. }
  82. return true;
  83. }
  84. return false;
  85. }
  86.  
  87. public void Rejuvenate(EntityGem gem){
  88. gem.setGemId(MathHelper.getRandomUUID());
  89. gem.setUniformColor(gem.nativeColor);
  90. gem.setServitude(EntityGem.SERVE_NONE);
  91. gem.fallbackServitude = -1;
  92. gem.setAttackAI();
  93. }
  94.  
  95. @Override
  96. public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
  97. return false;
  98. }
  99.  
  100. @Override
  101. @SideOnly(Side.CLIENT)
  102. public boolean isFull3D() {
  103. return true;
  104. }
  105. }
Add Comment
Please, Sign In to add comment