Jump to content

Better Bows (Need help with icon arrays and some custom arrows)


Zeratul_Auditore
 Share

Recommended Posts

I am working on a mod that i call Better Bows and i have currently 5 different bows added in. One bow for each material and an explosive bow which i am currently working on. However at the moment i am having two problems.

 

1)With all of my bows I am having trouble with having the icons cycle through so the bow looks like it is animated. The code for the icon array that i am using is basically just the code from the vanilla bow slightly modified so that it would theoretically work with my added bows.

 

2)I have added in an explosive arrow and an explosive bow but when in game and shooting in survival the explosive arrow spins and does some weird stuff but still stays on the normal trajectory of an arrow however while in creative the explosive arrow shoots straight as an arrow. (if you know what i mean) :P

 

 

For me the whole arrow spinning is not that big of a deal but if anyone has had this problem and fixed this please let me know. On the other hand I spent the time to individually make all the textures for the bows so i would like to be able to use them.

 

 

PS:

If you would like to see some of the code to help me out just ask and i will post it and by the way in the custom bows for each material i am using a Enum class so i kinda want the icon array to use my bow material function so i don't have to paste the code 4 times one for each bow. Not sure if this is possible but if you think it is than I would love to hear your ideas.

Link to comment
Share on other sites

Hi! IDK about number two but I can help you with number one.

 

First off, it is very hard to use the vanilla bow animation code. This is some simpler code that I use:

@SideOnly(Side.CLIENT)
private Icon[] bowIcon;
    private Icon[] bowIcon1 = new Icon[4];


public void registerIcons(IconRegister iconreg){ 
    
    {
     
    	itemIcon = iconreg.registerIcon("mcenrichment:" + this.getUnlocalizedName().substring(5) + "_0");
             for (int N = 0; N < 4; N++)
             {
                     this.bowIcon1[N] = iconreg.registerIcon("mcenrichment:" + this.getUnlocalizedName().substring(5) + "_" + N);
                     
             }
    }
    }
    public Icon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
    {
             if(player.getItemInUse() == null) return this.itemIcon;
             int time = stack.getMaxItemUseDuration() - useRemaining;
             if (time >= 18)
             {
                     return bowIcon1[3];
             }
             else if (time > 13)
             {
                     return bowIcon1[2];
             }
             else if (time > 0)
             {
                     return bowIcon1[1];
             }             
             return bowIcon1[0];
             }
    
}

You need to replace "mcenrichment" with whatever your mod folder is called, and make the unlocalized name of the bow whatever the first part of your bow texture is. For example, if your textures were called:

mybow_0

mybow_1

mybow_2

mybow_3,

 

than you need to make the unlocalized name "mybow".

Link to comment
Share on other sites

Thanks for the help your code worked great for my explosive bow. I just had to change a few variables and it was great but i still am having a little trouble with my bows that are made out of the vanilla materials. I had trouble because i am using 4 different items defined in one class using the a custom Enum class just like whats used for swords and tools. Anyways I'm still trying to figure out how i can use your code to apply to this case.

Link to comment
Share on other sites

Thanks for the help your code worked great for my explosive bow i just had to change a few variables and it was great but i still am having a little trouble with my bows that are made out of the vanilla materials i had some troubles because i am using 4 different items defined in one class using the a custom Enum class just like whats used for swords and tools so im still trying to figure out how i can use your code to apply to this class.

Ever heard of a period? It looks like this: "." USE IT. Got it? Good. Grammar nazi-ing aside...

 

Is this a default survival behavior (re #2) that you're trying to remove? If not, I'd like to see how you're registering the entity (although survival/creative behaviour difference is just odd.)

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

I fixed my use of periods to be honest that post was going to say something totally different but when i went to look up what the error was it was fixed. therefore the whole post got a bit jumbled up but i fixed it just for you. <3 Anyways my EntityExplosiveArrow class was just a copy of the EntityArrow class changed to use a different texture. Pluss a few areas where when the arrow hits the ground or a mob it blows up. In my ExplosiveBow class instead of entityarrow i have entityexplosivearrow.

 

package BetterBows;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import BetterBows.EntityExplosiveArrow;

public class ExplosiveBow extends ItemBow
{

    public ExplosiveBow(int par1)
    {
        super(par1);
        this.maxStackSize = 1;
        this.setMaxDamage(384);
        this.setCreativeTab(CreativeTabs.tabCombat);
    }

    /**
     * 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)
    {
        int j = this.getMaxItemUseDuration(par1ItemStack) - par4;

        ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled())
        {
            return;
        }
        j = event.charge;

        boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;

        if (flag || par3EntityPlayer.inventory.hasItem(mod_BetterBows.explosiveArrow.itemID))
        {
            float f = (float)j / 20.0F;
            f = (f * f + f * 2.0F) / 3.0F;

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

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

            EntityExplosiveArrow entityExplosiveArrow = new EntityExplosiveArrow(par2World, par3EntityPlayer, f * 2.0F);

            if (f == 1.0F)
            {
            	entityExplosiveArrow.setIsCritical(true);
            }

            int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);

            if (k > 0)
            {
            	entityExplosiveArrow.setDamage(entityExplosiveArrow.getDamage() + (double)k * 0.5D + 0.5D);
            }

            int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);

            if (l > 0)
            {
            	entityExplosiveArrow.setKnockbackStrength(l);
            }

            if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
            {
            	entityExplosiveArrow.setFire(100);
            }

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

            if (flag)
            {
            	entityExplosiveArrow.canBePickedUp = 2;
            }
            else
            {
                par3EntityPlayer.inventory.consumeInventoryItem(mod_BetterBows.explosiveArrow.itemID);
            }

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

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

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

    /**
     * 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)
    {
        ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled())
        {
            return event.result;
        }

        if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(mod_BetterBows.explosiveArrow.itemID))
        {
            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 1;
    }

    @SideOnly(Side.CLIENT)
    private Icon[] bowIcon;
    private Icon[] bowIcon1 = new Icon[4];


    public void registerIcons(IconRegister iconreg)
    { 
        itemIcon = iconreg.registerIcon("BetterBows:ExplosiveBow");
        for (int N = 0; N < 3; N++)
        {
                 this.bowIcon1[N] = iconreg.registerIcon("BetterBows:ExplosiveBow_pull_" + N);
                 
        }
    }
    public Icon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
    {
         if(player.getItemInUse() == null) return this.itemIcon;
         int time = stack.getMaxItemUseDuration() - useRemaining;
         if (time >= 18)
         {
          	 return bowIcon1[2];
         }
         else if (time > 13)
         {
         	 return bowIcon1[1];
         }
         else if (time > 0)
         {
        	 return bowIcon1[0];
         }             
         return bowIcon1[0];
    }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

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