Jump to content

[1.7.2] Bow with Multiple Arrows?


drok0920

Recommended Posts

Hello MCF forums,

I would like to know how i would go about making a bow that fires multiple arrows but off-set from where the normal bow spawns its arrow. I have tried(i know that what i tried was most likely a nooby way to try to do it but i tried and its the effort that counts xD): 'if (!par2World.isRemote) {

            par2World.spawnEntityInWorld(entityarrow);

            par2World.spawnEntityInWorld(entityarrow) + 2;' in my onPlayerStopUsing method but it gives me any error.

 

Thank you,

Drok

Link to comment
Share on other sites

You know how you create the EntityArrow in the first place?

EntityArrow arrow = new EntityArrow(world, player, charge);

Well, once you've done that and before you spawn it into the world, you can alter the arrow.posX, arrow.posY, arrow.posZ slightly. Create two (or more) arrow entities, leave the first one unchanged, and change the others as you need. You might want to look into the player's lookVector or you will find your arrows look right only in one direction.

Link to comment
Share on other sites

Ok cool i got it to work.  Thank you for you help collAlias. Here is what i used for anyone that needs it.


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(Items.arrow))
        {
            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 = 10.0F;
            }

            EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
            EntityArrow entityarrow1 = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
            EntityArrow entityarrow2 = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
            
            double pos1x = entityarrow1.posX + 0D;
            double pos1y = entityarrow1.posY + 1D;
            double pos1z = entityarrow1.posZ + 0D;
            
            entityarrow1.setPosition(pos1x, pos1y, pos1z);

            if (f == 1.0F) {
            	entityarrow.setIsCritical(true);
            	entityarrow1.setIsCritical(true);
            	entityarrow2.setIsCritical(true);
            }

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

            if (flag)  {
            	entityarrow.canBePickedUp = 2;
                
            }
            else {
                par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow);
            }

            if (!par2World.isRemote) {
            	par2World.spawnEntityInWorld(entityarrow);
            	par2World.spawnEntityInWorld(entityarrow1);
            	par2World.spawnEntityInWorld(entityarrow2);
            	
            }
        }
    }

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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