Advertisement
HalestormXV

1.7.10 Code

Aug 19th, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.33 KB | None | 0 0
  1. package com.halestormxv.item.gifts;
  2.  
  3. import java.util.List;
  4.  
  5. import com.halestormxv.creativetabs.CelestialCraft_creativeTabs;
  6. import com.halestormxv.entity.celestialBolt;
  7. import com.halestormxv.lib.RefStrings;
  8.  
  9. import cpw.mods.fml.relauncher.Side;
  10. import cpw.mods.fml.relauncher.SideOnly;
  11. import net.minecraft.enchantment.Enchantment;
  12. import net.minecraft.enchantment.EnchantmentHelper;
  13. import net.minecraft.entity.Entity;
  14. import net.minecraft.entity.EntityLivingBase;
  15. import net.minecraft.entity.effect.EntityLightningBolt;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.entity.projectile.EntityArrow;
  18. import net.minecraft.init.Items;
  19. import net.minecraft.item.EnumAction;
  20. import net.minecraft.item.EnumRarity;
  21. import net.minecraft.item.Item;
  22. import net.minecraft.item.ItemStack;
  23. import net.minecraft.nbt.NBTTagCompound;
  24. import net.minecraft.potion.Potion;
  25. import net.minecraft.potion.PotionEffect;
  26. import net.minecraft.util.ChatComponentTranslation;
  27. import net.minecraft.util.DamageSource;
  28. import net.minecraft.util.EnumChatFormatting;
  29. import net.minecraft.world.World;
  30. import net.minecraftforge.common.MinecraftForge;
  31. import net.minecraftforge.event.entity.player.ArrowLooseEvent;
  32.  
  33. public class leoGift extends Item
  34. {
  35.     public  double powerCost;
  36.  
  37.     public leoGift()
  38.     {
  39.         this.setMaxStackSize(1);
  40.         this.setTextureName(RefStrings.MODID + ":leo_gift");
  41.         this.setMaxDamage(-1);
  42.         this.setCreativeTab(CelestialCraft_creativeTabs.tabTools);
  43.     }
  44.  
  45.     public boolean isDamageable()
  46.     {
  47.         return false;
  48.     }
  49.  
  50.     @Override
  51.     @SideOnly(Side.CLIENT)
  52.     public EnumRarity getRarity(ItemStack par1ItemStack){
  53.         return EnumRarity.uncommon;
  54.     }
  55.  
  56.     @Override
  57.     public boolean hasEffect(ItemStack par1ItemStack){
  58.         return true;
  59.     }
  60.  
  61.     @Override
  62.     public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
  63.     {
  64.         par3List.add("");
  65.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "An artifact from Leo, argued to be");
  66.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "one of the most powerful spirits.");
  67.         par3List.add(EnumChatFormatting.LIGHT_PURPLE + "True power is held within.");
  68.         par3List.add("");
  69.         par3List.add(EnumChatFormatting.UNDERLINE + "Calls down Celestial Power on surrounding enemies.");
  70.         if (par1ItemStack.stackTagCompound != null)
  71.         {
  72.             String owner = par1ItemStack.stackTagCompound.getString("Artifact Bound To: ");
  73.             int cooldownRemain = par1ItemStack.stackTagCompound.getInteger("Cooldown: ");
  74.             if (owner.equals(par2EntityPlayer.getDisplayName()))
  75.             {
  76.                 par3List.add((EnumChatFormatting.GREEN + "Bound To: " + owner));
  77.                 par3List.add((EnumChatFormatting.GREEN + "Cooldown: " + cooldownRemain));
  78.             } else {
  79.                 par3List.add(EnumChatFormatting.RED + "This isn't your artifact.");
  80.             }
  81.         }
  82.     }
  83.  
  84.     public double getUsageCost(EntityPlayer user)
  85.     {
  86.         powerCost = (float)(user.experienceLevel) / 4;
  87.         return powerCost;
  88.     }
  89.  
  90.     public int getMaxItemUseDuration(ItemStack itemstack)
  91.     {
  92.         return 72000;
  93.     }
  94.  
  95.     public EnumAction getItemUseAction(ItemStack itemstack)
  96.     {
  97.         return EnumAction.block;
  98.     }
  99.  
  100.     public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer player, int chargedTime)
  101.     {
  102.         int j = this.getMaxItemUseDuration(itemstack) - chargedTime;
  103.  
  104.         ArrowLooseEvent event = new ArrowLooseEvent(player, itemstack, j);
  105.         MinecraftForge.EVENT_BUS.post(event);
  106.         if (event.isCanceled())
  107.         {
  108.             return;
  109.         }
  110.         j = event.charge;
  111.  
  112.         if (itemstack.stackTagCompound.getInteger("Cooldown: ") == 0 )
  113.         {
  114.             powerCost = getUsageCost(player);
  115.             player.addExperienceLevel((int)-powerCost);
  116.             player.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
  117.             if (j > 400){ j = 400;}
  118.             j = Math.round(j / 40);
  119.             List<EntityLivingBase> targetList = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, player.boundingBox.expand(8.0F + j, 8.0F + j, 8.0F + j));
  120.             for (EntityLivingBase targets : targetList)
  121.             {
  122.                 if ( targets != null)
  123.                 {
  124.                     if ( targets != player )
  125.                     {
  126.                         player.worldObj.spawnEntityInWorld(new EntityLightningBolt(world, targets.posX, targets.posY, targets.posZ) );
  127.                         targets.clearActivePotions();
  128.                         world.createExplosion(targets, targets.posX, targets.posY, targets.posZ, 3.2F + (j / 2), true);
  129.                         targets.setHealth(targets.getHealth() - j);
  130.                         world.playSoundAtEntity(targets, RefStrings.MODID + ":leo_gift_execute", 1.4F, 1.0F);
  131.                     }
  132.                 }
  133.             }
  134.             itemstack.stackTagCompound.setInteger("Cooldown: ", 300);
  135.         }else{
  136.             player.addChatComponentMessage(new ChatComponentTranslation ("\u00A74This item is on cooldown."));
  137.         }
  138.  
  139.     }
  140.  
  141.     public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
  142.     {
  143.         if ( player.capabilities.isCreativeMode || (player.experienceLevel > 8) )
  144.         {
  145.             if (!itemstack.hasTagCompound())
  146.             {
  147.                 itemstack.setTagCompound(new NBTTagCompound());
  148.                 itemstack.stackTagCompound.setString("Artifact Bound To: ", player.getDisplayName());
  149.                 itemstack.stackTagCompound.setInteger("Cooldown: ", 0);
  150.             }
  151.             else if (itemstack.hasTagCompound())
  152.             {
  153.                 String owner = itemstack.stackTagCompound.getString("Artifact Bound To: ");
  154.                 if (!owner.equals(player.getDisplayName()))
  155.                 {
  156.                     player.addChatComponentMessage(new ChatComponentTranslation ("\u00A74You are not the owner of this Artifact!"));
  157.                     return itemstack;
  158.                 }
  159.             }
  160.             if (itemstack.stackTagCompound.getInteger("Cooldown: ") == 0 )
  161.             {
  162.                 player.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
  163.                 world.playSoundAtEntity(player, RefStrings.MODID + ":leo_gift_cast", 1.0F, 1.0F);
  164.                
  165.             }else{
  166.                 player.addChatComponentMessage(new ChatComponentTranslation ("\u00A74This item is on cooldown."));
  167.             }
  168.         }else{
  169.             player.addChatComponentMessage(new ChatComponentTranslation ("\u00A74Not have enough Celestial Power to use Artifact."));
  170.         }
  171.         return itemstack;
  172.     }
  173.  
  174.     public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5)
  175.     {
  176.         EntityPlayer player = (EntityPlayer) entity;
  177.         ItemStack equipped = player.getCurrentEquippedItem();
  178.         if (itemStack.hasTagCompound() && itemStack.stackTagCompound.getInteger("Cooldown: ") > 0)
  179.         {
  180.             int cooldownCounter = itemStack.stackTagCompound.getInteger("Cooldown: ") - 1;
  181.             itemStack.stackTagCompound.setInteger("Cooldown: ", cooldownCounter);
  182.         }
  183.     }
  184.  
  185.  
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement