Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-215530

The freezing effect isn't immediately removed upon switching into spectator mode

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • None
    • 21w06a, 21w07a, 21w08a, 21w10a, 21w11a, 21w13a, 21w14a, 21w15a, 21w16a, 21w17a, 21w19a, 21w20a, 1.17 Pre-release 1, 1.17 Pre-release 3, 1.17 Pre-release 4, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17 Release Candidate 2, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 3, 1.17.1 Release Candidate 1, 1.17.1, 21w37a, 21w39a, 21w40a, 1.18, 1.18.1, 22w05a, 1.18.2 Pre-release 1, 1.18.2, 1.19, 1.19.2, 1.19.3
    • Confirmed
    • Spectator
    • Rendering
    • Low

    Description

      The Bug:

      The freezing effect isn't immediately removed upon switching into spectator mode.

      Steps to Reproduce:

      1. Switch into creative mode and stand inside of some powder snow.
      2. Wait until the freezing overlay completely covers your screen and then switch into spectator mode.
      3. Take note as to whether or not the freezing effect is immediately removed upon switching into spectator mode.

      Observed Behavior:

      The freezing effect isn't immediately removed upon switching into spectator mode.

      Expected Behavior:

      The freezing effect would be immediately removed upon switching into spectator mode.

      Code Analysis:

      Code analysis by Avoma can be found below.

      The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.

      net.minecraft.server.level.ServerPlayer.java
      public class ServerPlayer extends Player {
         ...
         public boolean setGameMode(GameType gameType) {
            if (!this.gameMode.changeGameModeForPlayer(gameType)) {
               return false;
            } else {
               this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float)gameType.getId()));
               if (gameType == GameType.SPECTATOR) {
                  this.removeEntitiesOnShoulder();
                  this.stopRiding();
               } else {
                  this.setCamera(this);
               }
      
               this.onUpdateAbilities();
               this.updateEffectVisibility();
               return true;
            }
         }
         ...

      If we look at the above class, we can see that only two methods are called when a player switches into spectator mode. These methods are removeEntitiesOnShoulder() and stopRiding(). This basically means that when a player changes into spectator mode, any entities that are riding on their shoulders will be dismounted, along with the player themselves being dismounted if they are riding any entity. As a result of only these two methods being called, the freezing effect isn't immediately removed upon switching into spectator mode.

      Fix:

      Simply calling the setTicksFrozen() method where appropriate within this piece of code will immediately remove the freezing effect upon switching into spectator mode, thus resolving this problem. The following line code can be used to fix this issue.

      this.setTicksFrozen(0);

      Attachments

        1. 2021-05-12_13.09.12.png
          2021-05-12_13.09.12.png
          320 kB
        2. MC-215530.mp4
          2.85 MB
        3. MC-215530 - Current Code.png
          MC-215530 - Current Code.png
          50 kB
        4. MC-215530 - Fixed Code.png
          MC-215530 - Fixed Code.png
          53 kB

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Avoma [Helper] Avoma
              Votes:
              7 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                CHK: