mojira.dev
MC-69216

Switching to spectator mode while fishing keeps rod cast

The Bug

When holding a cast fishing rod when switching to spectator mode, the rod remains cast.

Steps to Reproduce

  • Obtain a fishing rod and cast it.

  • Switch into spectator mode.

  • Take note as to whether or not fishing rods remain cast when switching into spectator mode.

Observed Behavior

Fishing rods remain cast when switching into spectator mode.

Expected Behavior

Fishing rods would not remain cast when switching into spectator mode.

Code Analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 17

Confirmed.

Confirmed for 1.11.2

The following is based on a decompiled version of Minecraft 1.12 using MCP 9.40pre-1. (By the way, 1.12 should be marked as affected here)

The method net.minecraft.entity.player.EntityPlayerMP.setGameType() doesn't invoke the method net.minecraft.entity.player.EntityPlayerMP.fishEntity.handleHookRetraction() which removes the fish hook entity from the player's world and returns the amount of damage which should be applied to the fishing rod after its retraction.

A simple solution to this issue would be to add this specific method invocation to the setGameType() method.

Suggested fix

public void setGameType(GameType gameType)
{
    // ...

    if (gameType == GameType.SPECTATOR)
    {
        this.func_192030_dh();
        this.dismountRidingEntity();
        if(this.fishEntity != null) {
            this.fishEntity.handleHookRetraction();
        }
    }
    else
    {
        this.setSpectatingEntity(this);
    }

    // ...
}

if(this.fishEntity != null) checks if the player has casted a fish hook. Without this If-statement the game would throw a NullPointerException because it obviously can't remove a fishEntity that doesn't exist.

Can confirm in 20w51a.

Can confirm in 21w03a.

7 more comments

Can confirm for 21w42a.
When going to spectator the rods remain cast, also when left clicking you can still see the swing animation in the wire of the rod.
Also the sound that you have a fish hanging on the rod can still play.

Affects 1.18.1

Can confirm in 1.18.2.

Can confirm in 1.19.

Can confirm in 1.19.2.

AJ Ruckman

lord.quadrato

(Unassigned)

Confirmed

Platform

Low

Player

casting, fishing_rod, game-mode-switch, spectator, use-item

Minecraft 1.8-pre1, Minecraft 1.8.8, Minecraft 15w32c, Minecraft 1.8.9, Minecraft 16w04a, ..., 1.20.4, 1.20.5, 1.21, 1.21.4, 25w02a

Retrieved