Jump to content

[1.18.1] How can I make my custom bow/item use my custom arrow/item/ammo?


Recommended Posts

Here is my main class for it:

public class Musket extends BowItem

    public Musket(Properties p_40660_)

    public int getDefaultProjectileRange() {
        return 15;

    public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
        if (entityLiving instanceof Player) {
            Player playerentity = (Player) entityLiving;
            if (stack.getDamageValue() < (stack.getMaxDamage() - 1)) {
                playerentity.getCooldowns().addCooldown(this, 45);
                Player player = (Player) entityLiving;
                ItemStack itemstack = player.getProjectile(stack);
                if (itemstack.isEmpty()) {
                    itemstack = new ItemStack(ModItems.MUSKET_BULLET.get());
                    MusketBullet arrowitem = (MusketBullet) (itemstack.getItem() instanceof MusketBullet ? itemstack.getItem() : ModItems.MUSKET_BULLET.get());
                    MusketAmmo abstractarrow = (MusketAmmo) arrowitem.createMusket(worldIn, itemstack, player);
                    abstractarrow = customeArrow(abstractarrow);
                    boolean flag1 = player.getAbilities().instabuild || (itemstack.getItem() instanceof MusketBullet && ((MusketBullet) itemstack.getItem())
                            .isInfinite(itemstack, stack, player));

                if (!worldIn.isClientSide) {
                    MusketAmmo abstractarrowentity = createArrow(worldIn, stack, playerentity);
                    abstractarrowentity = customeArrow(abstractarrowentity);
                    abstractarrowentity.shootFromRotation(playerentity, playerentity.getXRot(), playerentity.getYRot(),
                            0.0F, 1.0F * 3.0F, 1.0F);

                    abstractarrowentity.tickCount = 35;

                    stack.hurtAndBreak(1, entityLiving, p -> p.broadcastBreakEvent(entityLiving.getUsedItemHand()));
                    worldIn.playSound((Player) null, playerentity.getX(), playerentity.getY(), playerentity.getZ(),
                            ModSoundEvents.MUSKET.get(), SoundSource.PLAYERS, 1.0F,
                            1.0F / (worldIn.random.nextFloat() * 0.4F + 1.2F) + 0.25F * 0.5F);

                    if (!flag1 && !player.getAbilities().instabuild) {
                        if (itemstack.isEmpty()) {

    public InteractionResultHolder<ItemStack> use(Level p_40672_, Player p_40673_, InteractionHand p_40674_) {
        ItemStack itemstack = p_40673_.getItemInHand(p_40674_);
        boolean flag = !p_40673_.getProjectile(itemstack).isEmpty();

        InteractionResultHolder<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, p_40672_, p_40673_, p_40674_, flag);
        if (ret != null) return ret;

        if (!p_40673_.getAbilities().instabuild && !flag) {
            return InteractionResultHolder.fail(itemstack);
        } else {
            return InteractionResultHolder.consume(itemstack);

    public MusketAmmo createArrow(Level worldIn, ItemStack stack, LivingEntity shooter)
        MusketAmmo arrowentity = new MusketAmmo(worldIn, shooter);
        return arrowentity;

    public UseAnim getUseAnimation(ItemStack stack)
        return UseAnim.BOW;

    public MusketAmmo customeArrow(MusketAmmo arrow)
        return arrow;


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.

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.

  • Create New...

Important Information

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