Guest User

Bow Class

a guest
Feb 21st, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.72 KB | None | 0 0
  1. package Bows;
  2.  
  3. import TheMod.Main;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.client.resources.model.ModelBakery;
  6. import net.minecraft.client.resources.model.ModelResourceLocation;
  7. import net.minecraft.enchantment.Enchantment;
  8. import net.minecraft.enchantment.EnchantmentHelper;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.item.EnumAction;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemBow;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.stats.StatList;
  15. import net.minecraft.world.World;
  16. import net.minecraftforge.fml.common.registry.GameRegistry;
  17. import net.minecraftforge.fml.relauncher.Side;
  18. import net.minecraftforge.fml.relauncher.SideOnly;
  19.  
  20. public class TheModTitaniteBow extends ItemBow
  21. {
  22.     public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
  23.  
  24.     public TheModTitaniteBow(String name) {
  25.         super();
  26.         this.setUnlocalizedName(name);
  27.         this.setCreativeTab(Main.tabTheMod);
  28.         this.setMaxDamage(300);
  29.         GameRegistry.registerItem(this, name);
  30.  
  31.     }
  32.     public void RegisterRenderer(String modelName)
  33.     {
  34.         System.out.println("REGISTERING ITEM RENDERER: " + modelName);
  35.  
  36.         Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this, 0, new ModelResourceLocation(Main.MODID+":"+modelName, "inventory"));
  37.     }
  38.  
  39.     @Override
  40.     public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining)  {
  41.         ModelResourceLocation mrl = new ModelResourceLocation("tm:titanite_bow");
  42.  
  43.         if(player.getItemInUse() != null) {
  44.             if(useRemaining >= 18) {
  45.                 mrl = new ModelResourceLocation("tm:titanite_bow_pull2", "inventory");
  46.             } else if(useRemaining > 13) {
  47.                 mrl = new ModelResourceLocation("tm:titanite_bow_pull1", "inventory");
  48.             } else if(useRemaining > 0) {
  49.                 mrl = new ModelResourceLocation("tm:titanite_bow_pull0", "inventory");
  50.             }
  51.         }
  52.  
  53.         return mrl;
  54.     }
  55.     @SideOnly(Side.CLIENT)
  56.     public void initModel() {
  57.         ModelResourceLocation titanitepull2 = new ModelResourceLocation("tm:titanite_bow_pull2", "inventory");
  58.         ModelResourceLocation titanitepull1 = new ModelResourceLocation("tm:titanite_bow_pull1", "inventory");
  59.         ModelResourceLocation titanitepull0 = new ModelResourceLocation("tm:titanite_bow_pull0", "inventory");
  60.  
  61.  
  62.         ModelBakery.registerItemVariants(Main.Titanite_Bow, titanitepull2, titanitepull1, titanitepull0);
  63.     }
  64.  
  65.     /**
  66.      * Called when the player stops using an Item (stops holding the right mouse button).
  67.      */
  68.     public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
  69.     {
  70.         boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
  71.  
  72.         if (flag || playerIn.inventory.hasItem(Main.Titanite_Arrow))
  73.         {
  74.             int i = this.getMaxItemUseDuration(stack) - timeLeft;
  75.             net.minecraftforge.event.entity.player.ArrowLooseEvent event = new net.minecraftforge.event.entity.player.ArrowLooseEvent(playerIn, stack, i);
  76.             if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return;
  77.             i = event.charge;
  78.             float f = (float)i / 20.0F;
  79.             f = (f * f + f * 2.0F) / 3.0F;
  80.  
  81.             if ((double)f < 0.1D)
  82.             {
  83.                 return;
  84.             }
  85.  
  86.             if (f > 1.0F)
  87.             {
  88.                 f = 1.0F;
  89.             }
  90.  
  91.             EntityTitaniteArrow entityTitaniteArrow = new EntityTitaniteArrow(worldIn, playerIn, f * 2.0F);
  92.  
  93.             if (f == 1.0F)
  94.             {
  95.                 entityTitaniteArrow.setIsCritical(true);
  96.             }
  97.  
  98.             int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
  99.  
  100.             if (j > 0)
  101.             {
  102.                 entityTitaniteArrow.setDamage(entityTitaniteArrow.getDamage() + (double)j * 0.5D + 0.5D);
  103.             }
  104.  
  105.             int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
  106.  
  107.             if (k > 0)
  108.             {
  109.                 entityTitaniteArrow.setKnockbackStrength(k);
  110.             }
  111.  
  112.             if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
  113.             {
  114.                 entityTitaniteArrow.setFire(100);
  115.             }
  116.  
  117.             stack.damageItem(1, playerIn);
  118.             worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  119.  
  120.             if (flag)
  121.             {
  122.                 entityTitaniteArrow.canBePickedUp = 2;
  123.             }
  124.             else
  125.             {
  126.                 playerIn.inventory.consumeInventoryItem(Main.Titanite_Arrow);
  127.             }
  128.  
  129.             playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
  130.  
  131.             if (!worldIn.isRemote)
  132.             {
  133.                 worldIn.spawnEntityInWorld(entityTitaniteArrow);
  134.             }
  135.         }
  136.     }
  137.  
  138.     /**
  139.      * Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
  140.      * the Item before the action is complete.
  141.      */
  142.     public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn)
  143.     {
  144.         return stack;
  145.     }
  146.  
  147.     /**
  148.      * How long it takes to use or consume an item
  149.      */
  150.     public int getMaxItemUseDuration(ItemStack stack)
  151.     {
  152.         return 72000;
  153.     }
  154.  
  155.     /**
  156.      * returns the action that specifies what animation to play when the items is being used
  157.      */
  158.     public EnumAction getItemUseAction(ItemStack stack)
  159.     {
  160.         return EnumAction.BOW;
  161.     }
  162.  
  163.     /**
  164.      * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  165.      */
  166.     public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
  167.     {
  168.         net.minecraftforge.event.entity.player.ArrowNockEvent event = new net.minecraftforge.event.entity.player.ArrowNockEvent(playerIn, itemStackIn);
  169.         if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return event.result;
  170.  
  171.         if (playerIn.capabilities.isCreativeMode || playerIn.inventory.hasItem(Main.Titanite_Arrow))
  172.         {
  173.             playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
  174.         }
  175.  
  176.         return itemStackIn;
  177.     }
  178.  
  179.     /**
  180.      * Return the enchantability factor of the item, most of the time is based on material.
  181.      */
  182.     public int getItemEnchantability()
  183.     {
  184.         return 1;
  185.     }
  186. }
Add Comment
Please, Sign In to add comment