Advertisement
Guest User

Untitled

a guest
Dec 7th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.86 KB | None | 0 0
  1. package com.lyesdoesmods.items.classes;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import com.lyesdoesmods.items.LinguamInterpresItem;
  7. import com.lyesdoesmods.lib.ExtraFunctions;
  8. import com.lyesdoesmods.lib.ReferenceVariables;
  9.  
  10. import net.minecraft.entity.Entity;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.entity.player.EntityPlayerMP;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.nbt.NBTTagCompound;
  16. import net.minecraft.world.World;
  17. import net.minecraft.world.WorldSettings.GameType;
  18. import net.minecraftforge.fml.relauncher.Side;
  19. import net.minecraftforge.fml.relauncher.SideOnly;
  20.  
  21. public class FortitudoMarsClass extends Item{
  22.    
  23.     int currIcon = 0, waitTime = 20, currTime = 0;
  24.    
  25.     @Override
  26.     public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) {    
  27.        
  28.         if(!itemStack.hasTagCompound())
  29.         {
  30.             NBTTagCompound tagCompound = new NBTTagCompound();
  31.             tagCompound.setBoolean("fMarsIsActive", false);
  32.             tagCompound.setInteger("fMarsCurrIcon", 0);
  33.             tagCompound.setInteger("fMarsCurrTime", 0);
  34.             itemStack.setTagCompound(tagCompound);
  35.         }
  36.        
  37.         if(entity instanceof EntityPlayer)
  38.         {
  39.             EntityPlayer player = (EntityPlayer)entity;
  40.                
  41.             if(player != null)
  42.             {
  43.                 if(itemStack.getTagCompound().getInteger("fMarsCurrTime") >= waitTime)
  44.                 {
  45.                     if(itemStack.getTagCompound().getInteger("fMarsCurrIcon") > 0 && itemStack.getTagCompound().getBoolean("fMarsIsActive"))
  46.                     {  
  47.                         NBTTagCompound tagCompound = itemStack.getTagCompound();
  48.                         tagCompound.setInteger("fMarsCurrIcon", itemStack.getTagCompound().getInteger("fMarsCurrIcon") - 1);
  49.                         itemStack.setTagCompound(tagCompound);
  50.                     }
  51.                     else
  52.                     {
  53.                         NBTTagCompound tagCompound = itemStack.getTagCompound();
  54.                         tagCompound.setInteger("fMarsCurrIcon", 0);
  55.                         tagCompound.setBoolean("fMarsIsActive", false);
  56.                         itemStack.setTagCompound(tagCompound);
  57.                     }
  58.                     NBTTagCompound tagCompound = itemStack.getTagCompound();
  59.                     tagCompound.setInteger("fMarsCurrTime", 0);
  60.                     itemStack.setTagCompound(tagCompound);
  61.                 }
  62.                
  63.                 if(itemStack.getTagCompound().getInteger("fMarsCurrIcon") > 0)
  64.                 {
  65.                     player.heal(100f);
  66.                 }
  67.             }
  68.         }
  69.        
  70.         NBTTagCompound tagCompound = itemStack.getTagCompound();
  71.         tagCompound.setInteger("fMarsCurrTime", itemStack.getTagCompound().getInteger("fMarsCurrTime") + 1);
  72.         itemStack.setTagCompound(tagCompound);
  73.     }
  74.    
  75.     boolean isCreative = false;
  76.    
  77.     @Override
  78.     public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
  79.             boolean get;
  80.             get = itemStack.getTagCompound().getBoolean("fMarsIsActive");
  81.            
  82.             isCreative = false;
  83.            
  84.             //IsCreativeVariableSet
  85.             if(player instanceof EntityPlayerMP)
  86.             {
  87.                 EntityPlayerMP pMP = (EntityPlayerMP)player;
  88.                 isCreative = pMP.theItemInWorldManager.getGameType() == GameType.CREATIVE;
  89.             }
  90.  
  91.            
  92.             if(!get == true && (player.experienceLevel >= 30 || isCreative))
  93.             {              
  94.                 if(!isCreative)
  95.                     player.addExperienceLevel(-30);
  96.                
  97.                 NBTTagCompound tagCompound = itemStack.getTagCompound();
  98.                 tagCompound.setInteger("fMarsCurrIcon", 10);
  99.                 tagCompound.setBoolean("fMarsIsActive", true);
  100.                 itemStack.setTagCompound(tagCompound);
  101.                 get = true;
  102.             }
  103.             else
  104.             {
  105.                 NBTTagCompound tagCompound = itemStack.getTagCompound();
  106.                 tagCompound.setBoolean("fMarsIsActive", false);
  107.                 itemStack.setTagCompound(tagCompound);
  108.                 get = false;
  109.             }
  110.                        
  111.             player.swingItem();
  112.            
  113.         return super.onItemRightClick(itemStack, world, player);
  114.     }
  115.    
  116.     Random rand = new Random();
  117.     int informationTickUpdate = 0;
  118.     String currentString = "";
  119.     String extraString = "";
  120.  
  121.     @Override
  122.     public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
  123.         list.add("\u00A78" + currentString);
  124.         list.add("\u00A78" + extraString);
  125.         informationTickUpdate++;
  126.         if(player.inventory.hasItem(LinguamInterpresItem.item))
  127.         {
  128.             for(int i = 0; i < player.inventory.getSizeInventory(); i++)
  129.             {
  130.                 if(player.inventory.getStackInSlot(i) != null)
  131.                 if(player.inventory.getStackInSlot(i).hasTagCompound())
  132.                 {
  133.                     if(player.inventory.getStackInSlot(i).getTagCompound().hasKey("linguaIsActive"))
  134.                     {
  135.                         if(player.inventory.getStackInSlot(i).getTagCompound().getBoolean("linguaIsActive") == true)
  136.                         {
  137.                             currentString = "Strength of Mars";
  138.                             extraString = "Usage: 30XP";
  139.                             return;
  140.                         }
  141.                     }
  142.                 }
  143.             }
  144.         }
  145.        
  146.         if(informationTickUpdate > 5)
  147.         {
  148.             currentString = ExtraFunctions.generateRandomString(rand, 8) + " " + ExtraFunctions.generateRandomString(rand, 2) + " " + ExtraFunctions.generateRandomString(rand, 4);
  149.             extraString = ExtraFunctions.generateRandomString(rand, 6) + " " + ExtraFunctions.generateRandomString(rand, 4);
  150.             informationTickUpdate = 0;
  151.         }
  152.         super.addInformation(itemStack, player, list, par4);
  153.     }
  154.    
  155.     IIcon[] iconArray;
  156.     @Override
  157.     @SideOnly(Side.CLIENT)
  158.     public void registerIcons(IIconRegister iconRegister)
  159.     {
  160.         iconArray = new IIcon[11];
  161.         iconArray[0] = iconRegister.registerIcon(ReferenceVariables.MODID + ":FortitudoMarsItemOff");
  162.         for(int i = 1; i <= 10; i++)
  163.         {
  164.             iconArray[i] = iconRegister.registerIcon(ReferenceVariables.MODID + ":FortitudoMarsItem" + String.valueOf(i));
  165.         }
  166.     }
  167.    
  168.     @Override
  169.     @SideOnly(Side.CLIENT)
  170.     public IIcon getIconIndex(ItemStack stack) {
  171.         int output = 0;
  172.         if(stack.hasTagCompound())
  173.         {
  174.             output = stack.stackTagCompound.getInteger("fMarsCurrIcon");
  175.         }
  176.         return iconArray[output];
  177.     }
  178.  
  179.     @Override
  180.     @SideOnly(Side.CLIENT)
  181.     public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
  182.         int output = 0;
  183.         if(stack.hasTagCompound())
  184.         {
  185.             output = stack.stackTagCompound.getInteger("fMarsCurrIcon");
  186.         }
  187.         return iconArray[output];  
  188.     }
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement