Jump to content

[1.18.2] Reload animation problem


TheMajorN

Recommended Posts

Heya, so I'm making an old-style revolver and have mostly everything working aside from the reload animation.

I have a condition set so that the animation is supposed to play while the reload method is being executed.  However, the reload method executes immediately and the animation never plays because it never has time to.

Will I have to make the item a tile entity for this to work or is there a way for me to use ticks in the class without a tile entity?

Here is the relevant methods I used:

	public static int magazine = 6;
  
    public void reload(Level worldIn, Player playerIn) {
        worldIn.playSound((Player) null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundInit.CALDWELL_RELOAD_SOUND.get(), SoundSource.NEUTRAL, 2.0F, 1.0F);
        playerIn.getCooldowns().addCooldown(this, 60);
        magazine = 6;
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand handIn) {
        ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);

        player.getCooldowns().addCooldown(this, 10);
        if(!level.isClientSide) {
            if (magazine > 0) {
                shoot(level, player);
            } else {
                reload(level, player);
            }
        }

        player.awardStat(Stats.ITEM_USED.get(this));

        return InteractionResultHolder.sidedSuccess(stack, true);
    }

 
  
    private <E extends IAnimatable>PlayState predicate(AnimationEvent<E> event) {
        if (magazine > 0) {
            event.getController().setAnimation(new AnimationBuilder().addAnimation("caldwell_reload_anim", true));
            return PlayState.CONTINUE;
        } else {
            return PlayState.STOP;
        }
    }

Any help or points in the right direction are much appreciated!

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.