daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest May 4th, 2014 12 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.uxfuncraft.uxfuncraftmod.items.bows;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import fr.uxfuncraft.uxfuncraftmod.UxFunCraftMod;
  6. import net.minecraft.client.renderer.texture.IIconRegister;
  7. import net.minecraft.creativetab.CreativeTabs;
  8. import net.minecraft.enchantment.Enchantment;
  9. import net.minecraft.enchantment.EnchantmentHelper;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.entity.projectile.EntityArrow;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.item.EnumAction;
  14. import net.minecraft.item.ItemBow;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.IIcon;
  17. import net.minecraft.world.World;
  18. import net.minecraftforge.common.MinecraftForge;
  19. import net.minecraftforge.event.entity.player.ArrowLooseEvent;
  20. import net.minecraftforge.event.entity.player.ArrowNockEvent;
  21.  
  22. public class LittleSkeletonBow extends ItemBow
  23. {
  24.     public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
  25.     @SideOnly(Side.CLIENT)
  26.     private IIcon[] iconArray;
  27.     private static final String __OBFID = "CL_00001777";
  28.  
  29.     public LittleSkeletonBow()
  30.     {
  31.         this.maxStackSize = 1;
  32.         this.setMaxDamage(384);
  33.         this.setCreativeTab(CreativeTabs.tabCombat);
  34.     }
  35.  
  36.     /**
  37.      * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
  38.      */
  39.     public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
  40.     {
  41.         int j = this.getMaxItemUseDuration(par1ItemStack) - par4;
  42.  
  43.         ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
  44.         MinecraftForge.EVENT_BUS.post(event);
  45.         if (event.isCanceled())
  46.         {
  47.             return;
  48.         }
  49.         j = event.charge;
  50.  
  51.         boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;
  52.  
  53.         if (flag || par3EntityPlayer.inventory.hasItem(Items.arrow))
  54.         {
  55.             float f = (float)j / 20.0F;
  56.             f = (f * f + f * 2.0F) / 3.0F;
  57.  
  58.             if ((double)f < 0.1D)
  59.             {
  60.                 return;
  61.             }
  62.  
  63.             if (f > 1.0F)
  64.             {
  65.                 f = 1.0F;
  66.             }
  67.  
  68.             EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
  69.  
  70.             if (f == 1.0F)
  71.             {
  72.                 entityarrow.setIsCritical(true);
  73.             }
  74.  
  75.             int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
  76.  
  77.             if (k > 0)
  78.             {
  79.                 entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
  80.             }
  81.  
  82.             int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
  83.  
  84.             if (l > 0)
  85.             {
  86.                 entityarrow.setKnockbackStrength(l);
  87.             }
  88.  
  89.             if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
  90.             {
  91.                 entityarrow.setFire(100);
  92.             }
  93.  
  94.             par1ItemStack.damageItem(1, par3EntityPlayer);
  95.             par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  96.  
  97.             if (flag)
  98.             {
  99.                 entityarrow.canBePickedUp = 2;
  100.             }
  101.             else
  102.             {
  103.                 par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow);
  104.             }
  105.  
  106.             if (!par2World.isRemote)
  107.             {
  108.                 par2World.spawnEntityInWorld(entityarrow);
  109.             }
  110.         }
  111.     }
  112.  
  113.     public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  114.     {
  115.         return par1ItemStack;
  116.     }
  117.  
  118.     /**
  119.      * How long it takes to use or consume an item
  120.      */
  121.     public int getMaxItemUseDuration(ItemStack par1ItemStack)
  122.     {
  123.         return 72000;
  124.     }
  125.  
  126.     /**
  127.      * returns the action that specifies what animation to play when the items is being used
  128.      */
  129.     public EnumAction getItemUseAction(ItemStack par1ItemStack)
  130.     {
  131.         return EnumAction.bow;
  132.     }
  133.  
  134.     /**
  135.      * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  136.      */
  137.     public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  138.     {
  139.         ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
  140.         MinecraftForge.EVENT_BUS.post(event);
  141.         if (event.isCanceled())
  142.         {
  143.             return event.result;
  144.         }
  145.  
  146.         if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Items.arrow))
  147.         {
  148.             par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
  149.         }
  150.  
  151.         return par1ItemStack;
  152.     }
  153.  
  154.     /**
  155.      * Return the enchantability factor of the item, most of the time is based on material.
  156.      */
  157.     public int getItemEnchantability()
  158.     {
  159.         return 1;
  160.     }
  161.  
  162.     @SideOnly(Side.CLIENT)
  163.     public void registerIcons(IIconRegister par1IconRegister)
  164.     {
  165.         this.itemIcon = par1IconRegister.registerIcon(UxFunCraftMod.MODID + ":littleskeletonbow_standby");
  166.         this.iconArray = new IIcon[bowPullIconNameArray.length];
  167.  
  168.         for (int i = 0; i < this.iconArray.length; ++i)
  169.         {
  170.             this.iconArray[i] = par1IconRegister.registerIcon(UxFunCraftMod.MODID + ":littleskeletonbow_" + bowPullIconNameArray[i]);
  171.         }
  172.     }
  173.  
  174.     /**
  175.      * used to cycle through icons based on their used duration, i.e. for the bow
  176.      */
  177.     @SideOnly(Side.CLIENT)
  178.     public IIcon getItemIconForUseDuration(int par1)
  179.     {
  180.         return this.iconArray[par1];
  181.     }
  182. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top