Guest User

Untitled

a guest
Oct 21st, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.62 KB | None | 0 0
  1. package com.halestormxv.item;
  2.  
  3. import java.lang.reflect.*;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import com.halestormxv.Main.handler.ExtendedPlayer;
  8. import com.halestormxv.entity.goldspirits.EntityAquarius;
  9. import com.halestormxv.entity.goldspirits.EntityAries;
  10. import com.halestormxv.entity.goldspirits.EntityCancer;
  11. import com.halestormxv.entity.goldspirits.EntityCapricorn;
  12. import com.halestormxv.entity.goldspirits.EntityGemini;
  13. import com.halestormxv.entity.goldspirits.EntityGemini2;
  14. import com.halestormxv.entity.goldspirits.EntityLeo;
  15. import com.halestormxv.entity.goldspirits.EntityLibra;
  16. import com.halestormxv.entity.goldspirits.EntityPisces;
  17. import com.halestormxv.entity.goldspirits.EntityPisces2;
  18. import com.halestormxv.entity.goldspirits.EntitySagittarius;
  19. import com.halestormxv.entity.goldspirits.EntityScorpio;
  20. import com.halestormxv.entity.goldspirits.EntityTaurus;
  21. import com.halestormxv.entity.goldspirits.EntityVirgo;
  22. import com.halestormxv.lib.RefStrings;
  23.  
  24. import cpw.mods.fml.relauncher.Side;
  25. import cpw.mods.fml.relauncher.SideOnly;
  26. import net.minecraft.block.Block;
  27. import net.minecraft.block.BlockLog;
  28. import net.minecraft.client.Minecraft;
  29. import net.minecraft.client.renderer.texture.IIconRegister;
  30. import net.minecraft.creativetab.CreativeTabs;
  31. import net.minecraft.entity.Entity;
  32. import net.minecraft.entity.passive.EntityTameable;
  33. import net.minecraft.entity.player.EntityPlayer;
  34. import net.minecraft.init.Blocks;
  35. import net.minecraft.item.EnumRarity;
  36. import net.minecraft.item.Item;
  37. import net.minecraft.item.ItemStack;
  38. import net.minecraft.nbt.NBTTagCompound;
  39. import net.minecraft.nbt.NBTTagList;
  40. import net.minecraft.util.ChatComponentTranslation;
  41. import net.minecraft.util.EnumChatFormatting;
  42. import net.minecraft.util.IIcon;
  43. import net.minecraft.util.MathHelper;
  44. import net.minecraft.world.World;
  45.  
  46. public class celKey extends Item
  47. {
  48.     public static final String[] celKeys = new String[] {"Aquarius", "Taurus", "Cancer", "Virgo", "Sagittarius", "Leo", "Aries", "Scorpio", "Gemini", "Capricorn", "Pisces", "Libra"};
  49.     public static final String[] celKeys2 = new String[] {"Aquarius", "Taurus", "Cancer", "Virgo", "Sagittarius", "Leo", "Aries", "Scorpio", "Gemini", "Capricorn", "Pisces", "Libra"};
  50.     public static Class<? extends Entity>[] entityClasses = new Class[]
  51.             {
  52.                     EntityAquarius.class, EntityTaurus.class, EntityCancer.class, EntityVirgo.class,
  53.                     EntitySagittarius.class, EntityLeo.class, EntityAries.class, EntityScorpio.class,
  54.                     EntityGemini.class, EntityCapricorn.class, EntityPisces.class, EntityLibra.class
  55.             };
  56.     public static int SpiritCostBase[] = new int[]{8, 14, 11, 13, 12, 9, 6, 8, 10, 7, 9, 12};
  57.     public static int SpiritCostFormula[] = new int[]{7, 9, 9, 12, 10, 3, 12, 6, 8, 12, 6, 5};
  58.     public static int SpiritSummonCost;
  59.     public int summonedAmount = 0;
  60.  
  61.     @SideOnly(Side.CLIENT)
  62.     private IIcon[] iconID;
  63.  
  64.     public celKey()
  65.     {
  66.         this.setHasSubtypes(true);
  67.         this.setMaxDamage(0);
  68.         this.setMaxStackSize(1);
  69.     }
  70.    
  71.     @Override
  72.     @SideOnly(Side.CLIENT)
  73.     public EnumRarity getRarity(ItemStack par1ItemStack){
  74.         return EnumRarity.epic;
  75.     }
  76.  
  77.     @Override
  78.     public boolean hasEffect(ItemStack par1ItemStack){
  79.         return true;
  80.     }
  81.  
  82.     @SideOnly(Side.CLIENT)
  83.     public IIcon getIconFromDamage(int meta)
  84.     {
  85.         int j = MathHelper.clamp_int(meta, 0, 11);
  86.         return this.iconID[j];
  87.     }
  88.  
  89.     public String getUnlocalizedName(ItemStack itemstack)
  90.     {
  91.         int i = MathHelper.clamp_int(itemstack.getItemDamage(), 0, 11);
  92.         return super.getUnlocalizedName() + "." + celKeys[i];
  93.     }
  94.  
  95.     public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int meta, float p_77648_8_, float p_77648_9_, float p_77648_10_)
  96.     {
  97.         if (player.canPlayerEdit(x, y, z, meta, itemstack) && !world.isRemote)
  98.         {
  99.             try {
  100.                 Entity e = entityClasses[itemstack.getItemDamage()].getConstructor(World.class).newInstance(world);
  101.                 Entity gem2 = EntityGemini2.class.getConstructor(World.class).newInstance(world);
  102.                 Entity pis2 = EntityPisces2.class.getConstructor(World.class).newInstance(world);
  103.                 Random randCordY = new Random();
  104.                 Random randCordZ = new Random();
  105.                 int sF = SpiritCostFormula[itemstack.getItemDamage()];
  106.                 int sB = SpiritCostBase[itemstack.getItemDamage()];
  107.                 int sC = SpiritSummonCost = (int)(Math.ceil((player.experienceLevel) / sF));
  108.                 ExtendedPlayer instance = ExtendedPlayer.get(player);
  109.                 if (!itemstack.hasTagCompound())
  110.                 {
  111.                     itemstack.setTagCompound(new NBTTagCompound());
  112.                     itemstack.stackTagCompound.setString("Contract With: ", player.getDisplayName());
  113.                     itemstack.stackTagCompound.setInteger("Summoned Amount: ", summonedAmount);
  114.                 }
  115.                 else if (itemstack.hasTagCompound())
  116.                 {
  117.                     String owner = itemstack.stackTagCompound.getString("Contract With: ");
  118.                     if (!owner.equals(player.getDisplayName()))
  119.                     {
  120.                         player.addChatComponentMessage(new ChatComponentTranslation ("\u00A74You are not the owner of this contract!"));
  121.                         return false;
  122.                     }
  123.                 }
  124.                 if (!instance.summonedState[itemstack.getItemDamage()])
  125.                 {
  126.                     if ( (player.experienceTotal > sC) && (player.experienceLevel >= sB) )
  127.                     {
  128.                         int rY = randCordY.nextInt(3);
  129.                         int rZ = randCordZ.nextInt(3) + 1;
  130.                         e.setPosition(player.posX, player.posY + rY, player.posZ - rZ);
  131.                         ((EntityTameable) e).func_152115_b(player.getUniqueID().toString());
  132.                         if (itemstack.getItemDamage() == 8)
  133.                         {
  134.                             gem2.setPosition(player.posX + 2, player.posY + rY, player.posZ - rZ);
  135.                             ((EntityTameable) gem2).func_152115_b(player.getUniqueID().toString());
  136.                             world.spawnEntityInWorld(e); //Gemini 1 Master
  137.                             world.spawnEntityInWorld(gem2); //Gemini 2 Mirror
  138.                         }
  139.                         else if (itemstack.getItemDamage() == 10)
  140.                         {
  141.                             pis2.setPosition(player.posX + 2, player.posY + rY, player.posZ - rZ);
  142.                             ((EntityTameable) pis2).func_152115_b(player.getUniqueID().toString());
  143.                             world.spawnEntityInWorld(e); //Pisces 1 Master
  144.                             world.spawnEntityInWorld(pis2); //Pisces 2 Mirror
  145.                         }
  146.                         else
  147.                         {
  148.                             world.spawnEntityInWorld(e);
  149.                         }
  150.                         world.playSoundAtEntity(player, RefStrings.MODID + ":summon-bell", 0.7F, 1.0F);
  151.                         player.addChatComponentMessage(new ChatComponentTranslation ("Come forth "+celKeys2[itemstack.getItemDamage()] +"! I summon you!"));
  152.                         instance.setSummoned(itemstack.getItemDamage(), true);
  153.                         int newAmount = itemstack.stackTagCompound.getInteger("Summoned Amount: ") + 1;
  154.                         itemstack.stackTagCompound.setInteger("Summoned Amount: ", newAmount);
  155.                         if(sC > sB){ player.addExperienceLevel((int)-sC); return true; }else{ player.addExperienceLevel((int)-sB); return true; }
  156.                     }
  157.                     else
  158.                     {
  159.                         player.addChatComponentMessage(new ChatComponentTranslation ("\u00A74You do not have enough Celestial Power!"));
  160.                         return false;
  161.                     }
  162.                 }
  163.                 else
  164.                 {
  165.                     player.addChatComponentMessage(new ChatComponentTranslation (celKeys2[itemstack.getItemDamage()]+" is already summoned!"));
  166.                     return false;
  167.                 }
  168.  
  169.             } catch (InstantiationException e) {
  170.                 e.printStackTrace();
  171.             } catch (IllegalAccessException e) {
  172.                 e.printStackTrace();
  173.             } catch (IllegalArgumentException e) {
  174.                 e.printStackTrace();
  175.             } catch (InvocationTargetException e) {
  176.                 e.printStackTrace();
  177.             } catch (NoSuchMethodException e) {
  178.                 e.printStackTrace();
  179.             } catch (SecurityException e) {
  180.                 e.printStackTrace();
  181.             }
  182.         }
  183.         else if (itemstack.getItemDamage() > 11){};
  184.         return false;
  185.     }
  186.  
  187.     public void addInformation(ItemStack itemstack, EntityPlayer player,List list, boolean par4)
  188.     {
  189.         if (itemstack.stackTagCompound != null) {
  190.             String owner = itemstack.stackTagCompound.getString("Contract With: ");
  191.             int code = itemstack.stackTagCompound.getInteger("Summoned Amount: ");
  192.             list.add((EnumChatFormatting.GREEN + "Contract With: " + owner));
  193.             if (owner.equals(player.getDisplayName()))  //player.getUniqueID().toString())
  194.             {
  195.                 list.add(EnumChatFormatting.AQUA + "Summoned Amount: " + code);
  196.             } else {
  197.                 list.add(EnumChatFormatting.RED + "Summoned Amount: Not Your Key");
  198.                 //+ EnumChatFormatting.OBFUSCATED + code);
  199.             }
  200.         }
  201.     }
  202.  
  203.     @SideOnly(Side.CLIENT)
  204.     public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_)
  205.     {
  206.         for (int i = 0; i < 12; ++i)
  207.         {
  208.             p_150895_3_.add(new ItemStack(p_150895_1_, 1, i));
  209.         }
  210.     }
  211.  
  212.     @SideOnly(Side.CLIENT)
  213.     public void registerIcons(IIconRegister IIcon)
  214.     {
  215.         this.iconID = new IIcon[celKeys2.length];
  216.  
  217.         for (int i = 0; i < celKeys2.length; ++i)
  218.         {
  219.             this.iconID[i] = IIcon.registerIcon(RefStrings.MODID + ":celestialkey" + "_" + celKeys2[i]);
  220.         }
  221.     }
  222. }
Add Comment
Please, Sign In to add comment