Advertisement
Guest User

Komag CompositeBow.java Update

a guest
Sep 6th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.59 KB | None | 0 0
  1. package KeepOfMetalAndGold.Items;
  2.  
  3. //import java.util.ArrayList;
  4.  
  5. import cpw.mods.fml.relauncher.Side;
  6. import cpw.mods.fml.relauncher.SideOnly;
  7.  
  8. import net.minecraft.client.renderer.texture.IconRegister;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.enchantment.Enchantment;
  11. import net.minecraft.enchantment.EnchantmentHelper;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.entity.projectile.EntityArrow;
  14. import net.minecraft.item.EnumAction;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.util.Icon;
  18. import net.minecraft.world.World;
  19. import net.minecraftforge.common.MinecraftForge;
  20. import net.minecraftforge.event.entity.player.ArrowLooseEvent;
  21. import net.minecraftforge.event.entity.player.ArrowNockEvent;
  22.  
  23. public class CompositeBow
  24.   extends Item
  25. {
  26.   public static final String[] bowPullIconNameArray = new String[]
  27.       {"komag:CompositeBow_drawing_1", "komag:CompositeBow_drawing_2", "komag:CompositeBow_drawing_3"};
  28.   @SideOnly(Side.CLIENT)
  29.   private Icon[] iconArray;
  30.  
  31.   public CompositeBow( int par1 )
  32.   {
  33.     super( par1 );
  34.     this.maxStackSize = 1;
  35.     this.setMaxDamage(500);
  36.     this.setCreativeTab(CreativeTabs.tabCombat);
  37.   }
  38.  
  39.   /**
  40.    * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
  41.    */
  42.   public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
  43.   {
  44.       int j = this.getMaxItemUseDuration(par1ItemStack) - par4;
  45.  
  46.       ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
  47.       MinecraftForge.EVENT_BUS.post(event);
  48.       if (event.isCanceled())
  49.       {
  50.           return;
  51.       }
  52.       j = event.charge;
  53.  
  54.       boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;
  55.  
  56.       if (flag || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID))
  57.       {
  58.           float f = (float)j / 20.0F;
  59.           f = (f * f + f * 2.0F) / 3.0F;
  60.  
  61.           if ((double)f < 0.1D)
  62.           {
  63.               return;
  64.           }
  65.  
  66.           if (f > 1.0F)
  67.           {
  68.               f = 1.0F;
  69.           }
  70.  
  71.           EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
  72.  
  73.           if (f == 1.0F)
  74.           {
  75.               entityarrow.setIsCritical(true);
  76.           }
  77.  
  78.           int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
  79.  
  80.           if (k > 0)
  81.           {
  82.               entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
  83.           }
  84.  
  85.           int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
  86.  
  87.           if (l > 0)
  88.           {
  89.               entityarrow.setKnockbackStrength(l);
  90.           }
  91.  
  92.           if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
  93.           {
  94.               entityarrow.setFire(100);
  95.           }
  96.  
  97.           par1ItemStack.damageItem(1, par3EntityPlayer);
  98.           par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  99.  
  100.           if (flag)
  101.           {
  102.               entityarrow.canBePickedUp = 2;
  103.           }
  104.           else
  105.           {
  106.               par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.itemID);
  107.           }
  108.  
  109.           if (!par2World.isRemote)
  110.           {
  111.               par2World.spawnEntityInWorld(entityarrow);
  112.           }
  113.       }
  114.   }
  115.  
  116.   public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  117.   {
  118.       return par1ItemStack;
  119.   }
  120.  
  121.   /**
  122.    * How long it takes to use or consume an item
  123.    */
  124.   public int getMaxItemUseDuration(ItemStack par1ItemStack)
  125.   {
  126.       return 60000;
  127.   }
  128.  
  129.   /**
  130.    * returns the action that specifies what animation to play when the items is being used
  131.    */
  132.   public EnumAction getItemUseAction(ItemStack par1ItemStack)
  133.   {
  134.       return EnumAction.bow;
  135.   }
  136.  
  137.   /**
  138.    * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  139.    */
  140.   public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  141.   {
  142.       ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
  143.       MinecraftForge.EVENT_BUS.post(event);
  144.       if (event.isCanceled())
  145.       {
  146.           return event.result;
  147.       }
  148.  
  149.       if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID))
  150.       {
  151.           par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
  152.       }
  153.  
  154.       return par1ItemStack;
  155.   }
  156.  
  157.   /**
  158.    * Return the enchantability factor of the item, most of the time is based on material.
  159.    */
  160.   public int getItemEnchantability()
  161.   {
  162.       return 12;
  163.   }
  164.  
  165.   @SideOnly(Side.CLIENT)
  166.   public void registerIcons(IconRegister par1IconRegister)
  167.   {
  168.       this.itemIcon = par1IconRegister.registerIcon("komag:CompositeBow");
  169.       this.iconArray = new Icon[bowPullIconNameArray.length];
  170.  
  171.       for (int i = 0; i < this.iconArray.length; ++i)
  172.       {
  173.           this.iconArray[i] = par1IconRegister.registerIcon(bowPullIconNameArray[i]);
  174.       }
  175.   }
  176.  
  177.   @SideOnly(Side.CLIENT)
  178.  
  179.   /**
  180.    * used to cycle through icons based on their used duration, i.e. for the bow
  181.    */
  182.   public Icon getItemIconForUseDuration(int par1)
  183.   {
  184.       return this.iconArray[par1];
  185.   }
  186. }
  187.  
  188. /*
  189. private ArrayList<String> BowDrawingFrames = new ArrayList<String>();
  190. private ArrayList<Icon>   BowDrawingIcons  = new ArrayList<Icon>();
  191.  
  192. public CompositeBow( int ID )
  193. {
  194.   super( ID );
  195.  
  196.   this.setMaxStackSize( 1 );
  197.   this.setCreativeTab( CreativeTabs.tabCombat );
  198.   this.setUnlocalizedName( "KOMAGCompositeBow" );
  199.   this.setMaxDamage( 500 );
  200.  
  201.   this.BowDrawingFrames.add( "komag:CompositeBow_drawing_1" );
  202.   this.BowDrawingFrames.add( "komag:CompositeBow_drawing_2" );
  203.   this.BowDrawingFrames.add( "komag:CompositeBow_drawing_3" );
  204. }
  205.  
  206.  
  207. public EnumAction getItemUseAction( ItemStack par1ItemStack )
  208. {
  209.     return EnumAction.bow;
  210. }
  211.  
  212.  
  213. public Icon getItemIconForUseDuration( int par1 )
  214. {
  215.   return this.BowDrawingIcons.get( par1 );
  216. }
  217.  
  218.  
  219. public void registerIcons( IconRegister register )
  220. {
  221.   this.itemIcon = register.registerIcon( "komag:CompositeBow" );
  222.  
  223.   if ( this.BowDrawingFrames.size() >= 1 )
  224.   {
  225.     for ( String string : this.BowDrawingFrames )
  226.     {
  227.       this.BowDrawingIcons.add( register.registerIcon( string ) );
  228.     }
  229.   }
  230. }
  231.  
  232.  
  233. public int getItemEnchantability()
  234. {
  235.     return 1;
  236. }
  237.  
  238.  
  239. public ItemStack onItemRightClick( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer )
  240. {
  241.   ArrowNockEvent event = new ArrowNockEvent( par3EntityPlayer, par1ItemStack );
  242.   MinecraftForge.EVENT_BUS.post( event );
  243.  
  244.   if ( event.isCanceled() == true )
  245.   {
  246.     return event.result;
  247.   }
  248.  
  249.   if ( par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem( Item.arrow.itemID ) )
  250.   {
  251.     par3EntityPlayer.setItemInUse( par1ItemStack, this.getMaxItemUseDuration() );
  252.   }
  253.  
  254.   return par1ItemStack;
  255. }
  256.  
  257. public int getMaxItemUseDuration()
  258. {
  259.   return 76000;
  260. }
  261.  
  262.  
  263. public ItemStack onEaten( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer )
  264. {
  265.     return par1ItemStack;
  266. }
  267.  
  268.  
  269. public void onPlayerStoppedUsing( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4ItemInUseCount )
  270. {
  271.   int charge = this.getMaxItemUseDuration() - par4ItemInUseCount;
  272.  
  273.   ArrowLooseEvent event = new ArrowLooseEvent( par3EntityPlayer, par1ItemStack, charge );
  274.   MinecraftForge.EVENT_BUS.post( event );
  275.  
  276.   if ( event.isCanceled() == true )
  277.   {
  278.     return;
  279.   }
  280.  
  281.   charge               = event.charge;
  282.   boolean InfiniteUses = par3EntityPlayer.capabilities.isCreativeMode == true || EnchantmentHelper.getEnchantmentLevel( Enchantment.infinity.effectId, par1ItemStack ) > 0;
  283.  
  284.   if ( InfiniteUses == true || par3EntityPlayer.inventory.hasItem( Item.arrow.itemID ) )
  285.   {
  286.     float f = ( float ) charge / 20.0F;
  287.    
  288.     f = ( f * f + f * 2.0F ) / 3.0F;
  289.    
  290.     if ( ( double ) f < 0.1D )
  291.     {
  292.       return;
  293.     }
  294.    
  295.     if ( f > 1.0F )
  296.     {
  297.       f = 1.0F;
  298.     }
  299.    
  300.     EntityArrow entityarrow = new EntityArrow( par2World, par3EntityPlayer, f * 2.0F );
  301.     entityarrow.setIsCritical( f == 1.0F );
  302.  
  303.     int k = EnchantmentHelper.getEnchantmentLevel( Enchantment.power.effectId, par1ItemStack );
  304.  
  305.     if ( k > 0 )
  306.     {
  307.         entityarrow.setDamage( entityarrow.getDamage() + ( double ) k * 0.5D + 0.5D );
  308.     }
  309.  
  310.     int l = EnchantmentHelper.getEnchantmentLevel( Enchantment.punch.effectId, par1ItemStack );
  311.  
  312.     if ( l > 0 )
  313.     {
  314.         entityarrow.setKnockbackStrength( l );
  315.     }
  316.     /*else
  317.     {
  318.       entityarrow.setKnockbackStrength( 1 );
  319.     }*/
  320. /*
  321.     if ( EnchantmentHelper.getEnchantmentLevel( Enchantment.flame.effectId, par1ItemStack ) > 0 )
  322.     {
  323.         entityarrow.setFire( 100 );
  324.     }
  325.  
  326.     par1ItemStack.damageItem( 1, par3EntityPlayer );
  327.     par2World.playSoundAtEntity( par3EntityPlayer, "random.bow", 1.0F, 1.0F / ( itemRand.nextFloat() * 0.4F + 1.2F ) + f * 0.5F );
  328.  
  329.     if ( InfiniteUses == true )
  330.     {
  331.         entityarrow.canBePickedUp = 2;
  332.     }
  333.     else
  334.     {
  335.         par3EntityPlayer.inventory.consumeInventoryItem( Item.arrow.itemID );
  336.     }
  337.  
  338.     if ( par2World.isRemote == false )
  339.     {
  340.         par2World.spawnEntityInWorld( entityarrow );
  341.     }
  342.   }
  343. }
  344. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement