Snake Minigame Dying Problem

I'm using this script for a snake mini game, which can be found here.
For those of you who know how the game snake is like, if the snake touches its own body, it's game over. But for this script in particular, the game ends if the player presses a backward button. So if the snake is moving right and the player accidentally clicks the 'left' button, it's game over. Which, should not happen since the snake did NOT touch its own body. Also, it's just not how the game should be. The same goes for 'up' and 'down' commands as well. It's game over if the player clicks the direction button opposite the way the snake is headed. Is there a way to prevent this from happening?
Place below the snake script.
Spoiler: Direction fix
Code:
class Scene_Snake < Scene_Base
  def get_direction
    
    if Input.press?(Input::DOWN)
      return if @direction == 2
      @direction = 0
    end
    if Input.press?(Input::UP)
      return if @direction == 0
      @direction = 2
    end
    if Input.press?(Input::LEFT)
      return if @direction == 1
      @direction = 3
    end
    if Input.press?(Input::RIGHT)
      return if @direction == 3
      @direction = 1
    end
  end
end
Place below the snake script.
Spoiler: Direction fix
Code:
class Scene_Snake < Scene_Base
  def get_direction
   
    if Input.press?(Input::DOWN)
      return if @direction == 2
      @direction = 0
    end
    if Input.press?(Input::UP)
      return if @direction == 0
      @direction = 2
    end
    if Input.press?(Input::LEFT)
      return if @direction == 1
      @direction = 3
    end
    if Input.press?(Input::RIGHT)
      return if @direction == 3
      @direction = 1
    end
  end
end
Wow that was fast! Thank you so much! It works!

Original thread: https://forums.rpgmakerweb.com/threads/snake-minigame-dying-problem.108781/