Advertisement
Guest User

Untitled

a guest
Dec 7th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.56 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 linguamInterpresClass extends Item{
  22.  
  23.     boolean isCreative = false;
  24.    
  25.     @Override
  26.     public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
  27.             boolean get;
  28.             get = itemStack.getTagCompound().getBoolean("linguaIsActive");
  29.            
  30.             isCreative = false;
  31.             if(player instanceof EntityPlayerMP)
  32.             {
  33.                 EntityPlayerMP pMP = (EntityPlayerMP)player;
  34.                 isCreative = pMP.theItemInWorldManager.getGameType() == GameType.CREATIVE;
  35.             }
  36.            
  37.             if(!get == true && (player.experienceLevel >= 5 || isCreative))
  38.             {              
  39.                 if(!isCreative)
  40.                 player.addExperienceLevel(-5);
  41.                
  42.                 NBTTagCompound tc = itemStack.getTagCompound();
  43.                 tc.setBoolean("linguaIsActive", true);
  44.                 itemStack.setTagCompound(tc);
  45.                 get = true;
  46.             }
  47.             else
  48.             {
  49.                 NBTTagCompound tc = itemStack.getTagCompound();
  50.                 tc.setBoolean("linguaIsActive", false);
  51.                 itemStack.setTagCompound(tc);
  52.                 get = false;
  53.             }
  54.                        
  55.             player.swingItem();
  56.            
  57.         return super.onItemRightClick(itemStack, world, player);
  58.     }
  59.    
  60.     @Override
  61.     public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4,
  62.             boolean par5) {    
  63.         if(!itemStack.hasTagCompound())
  64.         {
  65.             NBTTagCompound tc = new NBTTagCompound();
  66.             tc.setBoolean("linguaIsActive", false);
  67.             itemStack.setTagCompound(tc);
  68.         }
  69.        
  70.     }
  71.    
  72.     IIcon[] iconArray;
  73.     @Override
  74.     @SideOnly(Side.CLIENT)
  75.     public void registerIcons(IIconRegister iconRegister)
  76.     {
  77.         iconArray = new IIcon[2];
  78.         iconArray[0] = iconRegister.registerIcon(ReferenceVariables.MODID + ":LinguamInterpresItemOff");
  79.         iconArray[1] = iconRegister.registerIcon(ReferenceVariables.MODID + ":LinguamInterpresItemOn");
  80.     }
  81.    
  82.    
  83.    
  84.     @Override
  85.     @SideOnly(Side.CLIENT)
  86.     public IIcon getIconIndex(ItemStack stack) {
  87.         if(stack.hasTagCompound())
  88.         {
  89.             if(stack.stackTagCompound.hasKey("linguaIsActive"))
  90.             {
  91.                 if(stack.stackTagCompound.getBoolean("linguaIsActive"))
  92.                 {
  93.                     return iconArray[1];
  94.                 }
  95.                 else
  96.                 {
  97.                     return iconArray[0];
  98.                 }
  99.             }
  100.             else
  101.             {
  102.                 return iconArray[0];
  103.             }
  104.         }
  105.         else
  106.         {
  107.             return iconArray[0];
  108.         }
  109.     }
  110.  
  111.     @Override
  112.     @SideOnly(Side.CLIENT)
  113.     public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
  114.        
  115.         if(stack.hasTagCompound())
  116.         {
  117.             if(stack.stackTagCompound.hasKey("linguaIsActive"))
  118.             {
  119.                 if(stack.stackTagCompound.getBoolean("linguaIsActive"))
  120.                 {
  121.                     return iconArray[1];
  122.                 }
  123.                 else
  124.                 {
  125.                     return iconArray[0];
  126.                 }
  127.             }
  128.             else
  129.             {
  130.                 return iconArray[0];
  131.             }
  132.         }
  133.         else
  134.         {
  135.             return iconArray[0];
  136.         }
  137.     }
  138.  
  139.     Random rand = new Random();
  140.     int informationTickUpdate = 0;
  141.     String currentString = "";
  142.     String extraString = "";
  143.  
  144.     @Override
  145.     public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
  146.         list.add("\u00A78" + currentString);
  147.         list.add("\u00A78" + extraString);
  148.         informationTickUpdate++;
  149.         if(player.inventory.hasItem(LinguamInterpresItem.item))
  150.         {
  151.             for(int i = 0; i < player.inventory.getSizeInventory(); i++)
  152.             {
  153.                 if(player.inventory.getStackInSlot(i) != null)
  154.                 if(player.inventory.getStackInSlot(i).hasTagCompound())
  155.                 {
  156.                     if(player.inventory.getStackInSlot(i).getTagCompound().hasKey("linguaIsActive"))
  157.                     {
  158.                         if(player.inventory.getStackInSlot(i).getTagCompound().getBoolean("linguaIsActive") == true)
  159.                         {
  160.                             currentString = "Language Translator";
  161.                             extraString = "Usage: 5XP";
  162.                             return;
  163.                         }
  164.                     }
  165.                 }
  166.             }
  167.         }
  168.        
  169.         if(informationTickUpdate > 5)
  170.         {
  171.             currentString = ExtraFunctions.generateRandomString(rand, 8) + " " + ExtraFunctions.generateRandomString(rand, 10);
  172.             extraString = ExtraFunctions.generateRandomString(rand, 6) + " " + ExtraFunctions.generateRandomString(rand, 3);
  173.             informationTickUpdate = 0;
  174.         }
  175.         super.addInformation(itemStack, player, list, par4);
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement