Advertisement
Guest User

ItemSapphire_Bow

a guest
Dec 12th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.23 KB | None | 0 0
  1. package tutuicraft3.sapphirecraft;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import net.minecraft.client.renderer.texture.IIconRegister;
  6. import net.minecraft.enchantment.Enchantment;
  7. import net.minecraft.enchantment.EnchantmentHelper;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.item.EnumAction;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.IIcon;
  13. import net.minecraft.world.World;
  14. import net.minecraftforge.common.MinecraftForge;
  15. import net.minecraftforge.event.entity.player.ArrowLooseEvent;
  16. import net.minecraftforge.event.entity.player.ArrowNockEvent;
  17.  
  18. public class ItemSapphire_Bow extends Item
  19. {
  20.     public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
  21.     @SideOnly(Side.CLIENT)
  22.     private IIcon[] iconArray;
  23.     private static final String __OBFID = "CL_00001777";
  24.  
  25.     public ItemSapphire_Bow()
  26.     {
  27.         this.maxStackSize = 1;
  28.         this.setMaxDamage(10000);
  29.     }
  30.  
  31.     /**
  32.      * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
  33.      */
  34.    
  35.     public void onPlayerStoppedUsing(ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_)
  36.     {
  37.         int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_;
  38.  
  39.         ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j);
  40.         MinecraftForge.EVENT_BUS.post(event);
  41.         if (event.isCanceled())
  42.         {
  43.             return;
  44.         }
  45.         j = event.charge;
  46.  
  47.         boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0;
  48.  
  49.         if (flag || p_77615_3_.inventory.hasItem(SapphireCraftItems.Sapphire_Arrow))
  50.         {
  51.             float f = (float)j / 20.0F;
  52.             f = (f * f + f * 2.0F) / 3.0F;
  53.  
  54.             if ((double)f < 0.1D)
  55.             {
  56.                 return;
  57.             }
  58.  
  59.             if (f > 1.0F)
  60.             {
  61.                 f = 1.0F;
  62.             }
  63.             EntitySapphire_Arrow entityarrow = new EntitySapphire_Arrow(p_77615_2_, p_77615_3_, f * 2.0F);
  64.  
  65.             if (f == 1.0F)
  66.             {
  67.                 entityarrow.setIsCritical(true);
  68.             }
  69.  
  70.             int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_);
  71.  
  72.             if (k > 0)
  73.             {
  74.                 entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
  75.             }
  76.             entityarrow.setDamage(1000);
  77.             int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_);
  78.  
  79.             if (l > 0)
  80.             {
  81.                 entityarrow.setKnockbackStrength(l);
  82.             }
  83.  
  84.             //if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0)
  85.             //{
  86.             entityarrow.setFire(100);
  87.             //}
  88.  
  89.             p_77615_1_.damageItem(1, p_77615_3_);
  90.             p_77615_2_.playSoundAtEntity(p_77615_3_, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  91.  
  92.             if (flag)
  93.             {
  94.                 entityarrow.canBePickedUp = 2;
  95.             }
  96.             else
  97.             {
  98.                 p_77615_3_.inventory.consumeInventoryItem(SapphireCraftItems.Sapphire_Arrow);
  99.             }
  100.             if (!p_77615_2_.isRemote)
  101.             {
  102.                 p_77615_2_.spawnEntityInWorld(entityarrow);
  103.             }        
  104.              
  105.         }
  106.     }
  107.    
  108.  
  109.     public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_)
  110.     {
  111.         return p_77654_1_;
  112.     }
  113.  
  114.     /**
  115.      * How long it takes to use or consume an item
  116.      */
  117.     public int getMaxItemUseDuration(ItemStack p_77626_1_)
  118.     {
  119.         return 72000;
  120.     }
  121.  
  122.     /**
  123.      * returns the action that specifies what animation to play when the items is being used
  124.      */
  125.     public EnumAction getItemUseAction(ItemStack p_77661_1_)
  126.     {
  127.         return EnumAction.bow;
  128.     }
  129.  
  130.     /**
  131.      * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  132.      */
  133.     public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
  134.     {
  135.         ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_);
  136.         MinecraftForge.EVENT_BUS.post(event);
  137.         if (event.isCanceled())
  138.         {
  139.             return event.result;
  140.         }
  141.  
  142.         if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(SapphireCraftItems.Sapphire_Arrow))
  143.         {
  144.             p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
  145.         }
  146.  
  147.         return p_77659_1_;
  148.     }
  149.  
  150.     /**
  151.      * Return the enchantability factor of the item, most of the time is based on material.
  152.      */
  153.     public int getItemEnchantability()
  154.     {
  155.         return 1;
  156.     }
  157.     @SideOnly(Side.CLIENT)
  158.     public void registerIcons(IIconRegister p_94581_1_)
  159.     {
  160.         this.itemIcon = p_94581_1_.registerIcon("sc:bow_standby");
  161.         this.iconArray = new IIcon[bowPullIconNameArray.length];
  162.  
  163.         for (int i = 0; i < this.iconArray.length; ++i)
  164.         {
  165.             this.iconArray[i] = p_94581_1_.registerIcon("sc:bow_" + bowPullIconNameArray[i]);
  166.         }
  167.     }
  168.    
  169.    
  170.     @Override
  171.     @SideOnly(Side.CLIENT)
  172.     public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
  173.         if(usingItem == null) { return itemIcon; }
  174.         int ticksInUse = stack.getMaxItemUseDuration() - useRemaining;
  175.         if (ticksInUse > 17) {
  176.             return iconArray[2];
  177.         } else if (ticksInUse > 13) {
  178.             return iconArray[1];
  179.         } else if (ticksInUse > 0) {
  180.             return iconArray[0];
  181.         } else {
  182.             return itemIcon;
  183.         }
  184.     }
  185.    
  186.     /**
  187.      * used to cycle through icons based on their used duration, i.e. for the bow
  188.      */
  189.     @SideOnly(Side.CLIENT)
  190.     public IIcon getItemIconForUseDuration(int p_94599_1_)
  191.     {
  192.         return this.iconArray[p_94599_1_];
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement