Jump to content

Bow Issues


Texasjake95

Recommended Posts

Just realized I forgot the code!

Here it is:

 

package net.minecraft.src.MyMod;

import net.minecraft.client.Minecraft;
import net.minecraft.src.*;
import net.minecraft.src.forge.*;


public class texasjake95_testBow extends Item implements ITextureProvider
{ 
public texasjake95_testBow(int par1)
    {
        super(par1);
        this.maxStackSize = 1;
        this.setMaxDamage(0);
    }
public int getIconIndex(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
    {
     
        if (usingItem != null && usingItem.getItem().shiftedIndex == mod_MyMod.TestBow.shiftedIndex)
        {
            int k = usingItem.getMaxItemUseDuration() - useRemaining;
            if (k >= 18) return 255;
            if (k >  13) return 254;
            if (k >   0) return 253;
        }
        return getIconIndex(stack);
    }
 public int getIconFromDamage(int i)
     {
             switch(i){
                             case 1: return 26;
                             default: return 25;         
     }
}


 public int setDamageFromMetadata(int i, int metadata)
{
switch(metadata)
{
    case 1: return 1;
    default: return 0;
}
}
private String[] names = new String[]{"item3", "item4"};
public String getItemNameIS(ItemStack itemstack)
    {
        return names[itemstack.getItemDamage()];
    }
 public String getTextureFile()
     {
             return "/texasjake95/MyMod/Items.png";
     }
    /**
     * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
     */
    public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
    {
    	Minecraft mc = ModLoader.getMinecraftInstance();
    	int a = mc.thePlayer.inventory.getCurrentItem().getItemDamage();
    	 
        if (ForgeHooks.onArrowLoose(par1ItemStack, par2World, par3EntityPlayer, getMaxItemUseDuration(par1ItemStack) - par4))
        {
            return;
        }
        
        boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;

        if (var5 || par3EntityPlayer.inventory.hasItem(Item.arrow.shiftedIndex))
        {
            int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4;
            float var7 = (float)var6 / 20.0F;
            var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;

            if ((double)var7 < 0.1D)
            {
                return;
            }

            if (var7 > 1.0F)
            {
                var7 = 1.0F;
            }

            EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F);
           
            if (var7 == 1.0F)
            {
                var8.arrowCritical = true;
            }

                  
           

            if (a == 1)
            {
            	var8.setFire(5);
            }

            par1ItemStack.damageItem(1, par3EntityPlayer);
            par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);

            if (!var5)
            {
                par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.shiftedIndex);
            }
            else
            {
                var8.doesArrowBelongToPlayer = false;
            }

            if (!par2World.isRemote)
            {
                par2World.spawnEntityInWorld(var8);
            }
        }
    }

    public ItemStack onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        return par1ItemStack;
    }

    /**
     * How long it takes to use or consume an item
     */
    public int getMaxItemUseDuration(ItemStack par1ItemStack)
    {
        return 0;
    }

    /**
     * returns the action that specifies what animation to play when the items is being used
     */
    public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
    	return EnumAction.bow;
    }

    /**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        ItemStack stack = ForgeHooks.onArrowNock(par1ItemStack, par2World, par3EntityPlayer);
        if (stack != null)
        {
            return stack;
        }
        
        if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Item.arrow.shiftedIndex))
        {
            par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
        }
       
        return par1ItemStack;
    }
   
    
    /**
     * Return the enchantability factor of the item, most of the time is based on material.
     */
   
    
    public int getItemEnchantability()
    {
        return 0;
    }


}

 

Link to comment
Share on other sites

i havent done this myself, but just looking at the code you should look at this method

 

/**
     * returns the action that specifies what animation to play when the items is being used
     */
    public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
    	return EnumAction.bow;
    }

 

you should probably make a custom EnumAction with your bow in :)

Link to comment
Share on other sites

you can always do it a different way, have a play around with it

 

for example, if youre not bothered about durability, make it add damage stuff while using it, then set the texture based on damage values. but remember to set the damage back to 0 when released

Link to comment
Share on other sites

you can always do it a different way, have a play around with it

 

for example, if youre not bothered about durability, make it add damage stuff while using it, then set the texture based on damage values. but remember to set the damage back to 0 when released

I have done that the problem is it doesn't act like the vanilla bow where the surroundings get streched abit and the player holds it like a bow

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.