mojira.dev
MCPE-231915

Player cannot switch out of Spectator mode in Hardcore, even if they haven't died

After setting the player’s gamemode to Spectator using player.setGamemode(GameMode), but attempting to change to any other gamemode afterward, doesn't work and there is no error thrown. My guess is that this is because the hardcore world is supposed to become inaccessible after the player dies and changes (permanently) to spectator mode. However, in this case, the player has not yet died and should not lose the world.

Expectation:

The ScriptAPI allows the player to change gamemodes freely until the player dies.

Actual:

As soon as the player enters spectator mode (whether they have died or not), the world becomes inaccessible.

Comments 2

Could you include steps to reproduce the issue?

Yep! We can access setGameMode() through a custom command like this:

import { system, CustomCommandParamType, CommandPermissionLevel } from "@minecraft/server";

system.beforeEvents.startup.subscribe((event) => {
    event.customCommandRegistry.registerCommand({
        name: 'debug:setgamemode',
        description: "Changes your gamemode using the Script API instead of the vanilla command.",
        mandatoryParameters: [{ name: "gamemode", type: CustomCommandParamType.String }],
        permissionLevel: CommandPermissionLevel.Any,
        cheatsRequired: false
    }, gamemodeCmdCallback);
});

function gamemodeCmdCallback(origin, gamemode) {
    const source = origin.sourceEntity;
    system.run(() => origin.sourceEntity.setGameMode(gamemode));
};

Upon using this command with the desired gamemodes in hardcore mode, we can see that the only gamemode change that works is Survival → Spectator.

ForestOfLight

(Unassigned)

Unconfirmed

Multiple

1.21.123 Hotfix

Retrieved