Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] Arrows from custom bow are not flying correctly


MrMarnic
 Share

Recommended Posts

Here is my problem.

I have create a custom bow which is working fine but when I am increasing the velocity of the arrows, the arrows have an offset when flying.

They are not flying as straight as the arrows from the vanilla bow.

Here is my code:

public class BasicBow extends ItemBow{

    public BasicBow(String name) {
        setRegistryName(name);
      	setUnlocalizedName(name);
        setMaxDamage(384);
        this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter()
        {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
            {
                if (entityIn == null)
                {
                    return 0.0F;
                }
                else
                {
                    return !(entityIn.getActiveItemStack().getItem() instanceof ItemBow) ? 0.0F : (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20f;
                }
            }
        });
    }

    @Override
    public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
        if (entityLiving instanceof EntityPlayer)
        {
            EntityPlayer entityplayer = (EntityPlayer)entityLiving;
            boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
            ItemStack itemstack = this.findAmmo(entityplayer);

            int i = this.getMaxItemUseDuration(stack) - timeLeft;
            i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
            if (i < 0) return;

            if (!itemstack.isEmpty() || flag)
            {
                if (itemstack.isEmpty())
                {
                    itemstack = new ItemStack(Items.ARROW);
                }

                float f = getArrowVelocity(i);

                if ((double)f >= 0.1D)
                {
                    boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));

                    if (!worldIn.isRemote)
                    {
                        ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
                        EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                        entityarrow = this.customizeArrow(entityarrow);
                        entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 4, 1f);

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

                        int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);

                        if (j > 0)
                        {
                            entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D + settings.getDamage());
                        }

                        int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);

                        if (k > 0)
                        {
                            entityarrow.setKnockbackStrength(k);
                        }

                        if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
                        {
                            entityarrow.setFire(100);
                        }

                        stack.damageItem(1, entityplayer);

                        if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
                        {
                            entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                        }

                        worldIn.spawnEntity(entityarrow);
                    }

                    worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

                    if (!flag1 && !entityplayer.capabilities.isCreativeMode)
                    {
                        itemstack.shrink(1);

                        if (itemstack.isEmpty())
                        {
                            entityplayer.inventory.deleteStack(itemstack);
                        }
                    }

                    entityplayer.addStat(StatList.getObjectUseStats(this));
                }
            }
        }
    }
}

In this line I am applying the velocity:

entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 4.5f, 1f);

When I multiply f with an float higher than 4 the bug is occuring.

It would be nice if you can help me.

Edited by MrMarnic
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.

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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • How did you set up the server? How are you starting it?
    • Code: https://github.com/japanisawesome/FirstForgeMod Hello! I am entirely new to Forge modding (just started today), and I have about 2 years of experience with Java. I was following a tutorial earlier today to make my first item, and I noticed that many of the methods are outdated and deprecated. So I looked on the forums here to find how to make my code to be more up to date, but no matter how long I tried, none of my files in the assets folder would load (lang, model, texture). I am consistently getting the output (latest.log in the github repo) in minecraft. What am I doing wrong? I apologize in advance if I am just really stupid and missing something. Thanks, Dodep
    • This is my code. How can I change it to have "Hello world!" show on the screen? @Mod(Chants2.MODID) public class Chants2 { public static final String MODID = "chants2"; public Chants2(){ final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); final ClientSideOnlyModEventRegistrar clientSideOnlyModEventRegistrar = new ClientSideOnlyModEventRegistrar(modEventBus); registerCommonEvents(modEventBus); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> clientSideOnlyModEventRegistrar::registerClientOnlyEvents); } public void registerCommonEvents(IEventBus eventBus) { //eventBus.register(GuiHandler.class); } } public class ClientSideOnlyModEventRegistrar { private final IEventBus eventBus; public ClientSideOnlyModEventRegistrar(IEventBus eventBus) { this.eventBus = eventBus; } public void registerClientOnlyEvents() { eventBus.register(GuiHandler.class); } } public class GuiHandler { String text = "Hello world!"; @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) { drawString(event.getMatrixStack(), Minecraft.getInstance().font, text, event.getWindow().getWidth() / 2, event.getWindow().getHeight() / 2, Integer.parseInt("33AA66", 16)); } }  
    • why do you need the JDA API in MinecraftForge?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.