How to force specify and restore the state of the step animation?

Mining system (I can't find its original release place)

I want the character to show the step animation when mining
After mining, it will return to its original state

def anime_step(x) copied from https://rpg.blue/thread-220484-1-1.html
alias _minerals_old_update comes from the mining system

Ruby:
    class Game_Player < Game_Character
      def anime_step(x)
        if x == 0
          begin
            @step_anime = @old_step_anime
          rescue
            @step_anime = false
          ensure
            @old_step_anime = nil
          end
        else
          if @old_step_anime == nil && @old_step_anime == nil
            @old_step_anime = @step_anime
          end
          @step_anime = true
        end
      end
    
      alias _minerals_old_update update
      def update *args, &block
        _minerals_old_update *args, &block
    
        if is_mining?
          anime_step(1)
        elsif mining_complete?
          anime_step(0)
        end
    
        update_mining if is_mining?
        @mining.mine! if mining_complete?
        visible_item_popups.each &:update
      end
    end

Now there are two problems

1. Mining first, and then using the command "set moving route-step animation on", the command will be invalid
2. First use the "set movement route-step animation on" command, the character shows the step animation, and then go to mining,
After mining, the character's step status will be off and will not return to the original status (on)

Directly use events on the map to execute "set movement route-step animation on/off" and "set movement route-script-anime_step(0/1)" in different ways. It seems that there is no problem, so is it because I wrote the wrong part of update ??
Bump
Solved
It should be
Ruby:
if @old_step_anime == nil && is_mining?

  anime_step(1)

elsif @old_step_anime != nil && !is_mining?

  anime_step(0)

end

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-force-specify-and-restore-the-state-of-the-step-animation.125368/