Guest User

bow class

a guest
Oct 26th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.80 KB | None | 0 0
  1. import net.minecraft.client.renderer.texture.IIconRegister;
  2. import net.minecraft.creativetab.CreativeTabs;
  3. import net.minecraft.enchantment.Enchantment;
  4. import net.minecraft.enchantment.EnchantmentHelper;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.entity.projectile.EntityArrow;
  7. import net.minecraft.init.Items;
  8. import net.minecraft.item.EnumAction;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.util.IIcon;
  12. import net.minecraft.world.World;
  13. import net.minecraftforge.common.MinecraftForge;
  14. import net.minecraftforge.event.entity.player.ArrowLooseEvent;
  15. import net.minecraftforge.event.entity.player.ArrowNockEvent;
  16. import cpw.mods.fml.relauncher.Side;
  17. import cpw.mods.fml.relauncher.SideOnly;
  18.  
  19. public class blazeBow extends Item
  20. {
  21.    
  22.     public static final String[] blazebowPullIconNameArray = new String[] {"yesodmod:blazebow_pulling_0", "yesodmod:blazebow_pulling_1", "yesodmod:blazebow_pulling_2"};
  23.     @SideOnly(Side.CLIENT)
  24.     private IIcon[] iconArray;
  25.    
  26.  public blazeBow()
  27.   {
  28.       super();
  29.     maxStackSize = 1;
  30.     setMaxDamage(500);
  31.     setCreativeTab(CreativeTabs.tabCombat);
  32.     setUnlocalizedName("blazeBow");
  33.   }
  34.  
  35.  
  36.   /**
  37.    * returns the action that specifies what animation to play when the items is being used
  38.    */
  39.  public EnumAction getItemUseAction(ItemStack par1)
  40.  {
  41.      return EnumAction.bow;
  42.  }
  43.  
  44.   @SideOnly(Side.CLIENT)
  45.   public IIcon getItemIconForUseDuration(int par1)
  46.   {
  47.       return this.iconArray[par1];
  48.   }
  49.  
  50.   @SideOnly(Side.CLIENT)
  51.   public void registerIcons(IIconRegister par1)
  52.   {
  53.       this.itemIcon = par1.registerIcon("yesodmod:" + "blazebow" + "_pulling_0");
  54.       this.iconArray = new IIcon[blazebowPullIconNameArray.length];
  55.  
  56.       for (int i = 0; i < this.iconArray.length; ++i)
  57.       {
  58.           this.iconArray[i] = par1.registerIcon(blazebowPullIconNameArray[i]);
  59.       }
  60.   }
  61.  
  62.   /**
  63.    * Metodo per consumare frecce
  64.    * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
  65.    */
  66.   public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
  67.   {
  68.       int j = this.getMaxItemUseDuration(par1ItemStack) - par4;
  69.  
  70.       ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
  71.       MinecraftForge.EVENT_BUS.post(event);
  72.       if (event.isCanceled())
  73.       {
  74.           return;
  75.       }
  76.       j = event.charge;
  77.  
  78.       boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;
  79.  
  80.       //arrow use
  81.       if (flag || par3EntityPlayer.inventory.hasItem(Generic.explosiveArrow) ||par3EntityPlayer.inventory.hasItem(Items.arrow))
  82.       {
  83.           float f = (float)j / 20.0F;
  84.           f = (f * f + f * 2.0F) / 3.0F;
  85.  
  86.           if ((double)f < 0.1D)
  87.           {
  88.               return;
  89.           }
  90.  
  91.           if (f > 1.0F)
  92.           {
  93.               f = 1.0F;
  94.           }
  95.  
  96.           EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
  97.  
  98.           if (f == 1.0F)
  99.           {
  100.               entityarrow.setIsCritical(true);
  101.           }
  102.  
  103.           int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
  104.  
  105.           if (k > 0)
  106.           {
  107.               entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
  108.           }
  109.  
  110.           int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
  111.  
  112.           if (l > 0)
  113.           {
  114.               entityarrow.setKnockbackStrength(l);
  115.           }
  116.  
  117.           if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
  118.           {
  119.               entityarrow.setFire(100);
  120.           }
  121.  
  122.           par1ItemStack.damageItem(1, par3EntityPlayer);
  123.           par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  124.  
  125.           if (flag)
  126.           {
  127.               entityarrow.canBePickedUp = 2;
  128.           }
  129.           else
  130.           {
  131.               if (par3EntityPlayer.inventory.hasItem(Generic.explosiveArrow)){
  132.               par3EntityPlayer.inventory.consumeInventoryItem(Generic.explosiveArrow);
  133.               }
  134.               else
  135.               {par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow);
  136.               }
  137.              
  138.           }
  139.  
  140.           if (!par2World.isRemote)           
  141.           {
  142.               if (par3EntityPlayer.inventory.hasItem(Generic.explosiveArrow))
  143.               {
  144.           par2World.spawnEntityInWorld(new entityExplosiveArrow(par2World, par3EntityPlayer));
  145.               }
  146.               else {
  147.               par2World.spawnEntityInWorld(entityarrow);
  148.               }
  149.           }
  150.       }
  151.         }
  152.  
  153.   public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  154.   {
  155.       return par1ItemStack;
  156.   }
  157.  
  158.   /**
  159.    * Metodo per sparare tenendo premuto il destro.
  160.    */
  161.  
  162.   public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  163.   {
  164.       ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
  165.       MinecraftForge.EVENT_BUS.post(event);
  166.       if (event.isCanceled())
  167.       {
  168.           return event.result;
  169.       }
  170.  
  171.       if (par3EntityPlayer.capabilities.isCreativeMode ||par3EntityPlayer.inventory.hasItem(Generic.explosiveArrow) ||par3EntityPlayer.inventory.hasItem(Items.arrow))
  172.       {
  173.           par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
  174.       }
  175.  
  176.       return par1ItemStack;
  177.   }
  178.  
  179.   /**
  180.    * How long it takes to use or consume an item
  181.    */
  182.   public int getMaxItemUseDuration(ItemStack par1ItemStack)
  183.   {
  184.       return 72000;
  185.   }
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment