mojira.dev
MC-215531

The carved pumpkin overlay is rendered in spectator mode

The Bug:

The carved pumpkin overlay is rendered in spectator mode.

Steps to Reproduce:

  1. Equip a carved pumpkin on your head by using the command provided below.

    /item replace entity @s armor.head with minecraft:carved_pumpkin
  2. Switch to spectator mode.

  3. Take note as to whether or not the carved pumpkin overlay is rendered in spectator mode.

Observed Behavior:

The carved pumpkin overlay is rendered.

Expected Behavior:

The carved pumpkin overlay would not be rendered.

Code Analysis:

Code analysis by @unknown can be found below.

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

net.minecraft.client.gui.Gui.java

public class Gui extends GuiComponent {
   ...
   public void render(PoseStack poseStack, float v) {
      ...
      if (this.minecraft.options.getCameraType().isFirstPerson()) {
         if (this.minecraft.player.isScoping()) {
            this.renderSpyglassOverlay(this.scopeScale);
         } else {
            ...
            ItemStack itemstack = this.minecraft.player.getInventory().getArmor(3);
            if (itemstack.is(Blocks.CARVED_PUMPKIN.asItem())) {
               this.renderTextureOverlay(PUMPKIN_BLUR_LOCATION, 1.0F);
            }
         }
      }
      ...

If we look at the above class, we can see that there are two checks that are carried out before allowing the carved pumpkin overlay to render. One of these checks is to see if the player is in first person and the other is to check if the player has a carved pumpkin on their head. If both of these requirements are met, the carved pumpkin overlay is rendered. The game doesn't check if the player is in spectator mode before allowing the carved pumpkin overlay to render, therefore resulting in this problem occurring.

Fix:

Simply altering the appropriate existing "if" statement within this piece of code to check if the player is in spectator mode before allowing the carved pumpkin overlay to render will resolve this problem.

Current "if" statement:

if (itemstack.is(Blocks.CARVED_PUMPKIN.asItem()))

Fixed "if" statement:

if (itemstack.is(Blocks.CARVED_PUMPKIN.asItem()) && !this.minecraft.player.isSpectator())

Linked issues

Attachments

Comments 2

Can confirm for 1.16.5

Avoma

(Unassigned)

Confirmed

Platform

Normal

Rendering

game-mode-switch

1.16.5, 21w06a, 21w07a, 21w08a, 21w08b, ..., 1.21 Pre-Release 1, 1.21, 1.21.3, 1.21.4, 1.21.7

Retrieved