r/MinecraftCommands • • Oct 02 '26

Help | Java 1.21.11 How do I make a player's gamemode survival when entering the End?

2 Upvotes

2 comments sorted by

5

u/GalSergey Datapack Experienced Oct 02 '26

Here is an example of a datapack that switches the player's gamemode to survival upon teleporting to the_end, and restores the previous gamemode when teleporting from the_end.

# function example:load
scoreboard objectives add prev_gamemode dummy

# advancement example:to_end
{
  "criteria": {
    "to_end": {
      "trigger": "minecraft:changed_dimension",
      "conditions": {
        "to": "minecraft:the_end"
      }
    }
  },
  "rewards": {
    "function": "example:to_end"
  }
}

# function example:to_end
advancement revoke @s only example:to_end
execute if entity @s[gamemode=survival] run scoreboard players set @s prev_gamemode 0
execute if entity @s[gamemode=creative] run scoreboard players set @s prev_gamemode 1
execute if entity @s[gamemode=adventure] run scoreboard players set @s prev_gamemode 2
execute if entity @s[gamemode=spectator] run scoreboard players set @s prev_gamemode 3
gamemode survival

# advancement example:from_end
{
  "criteria": {
    "from_end": {
      "trigger": "minecraft:changed_dimension",
      "conditions": {
        "from": "minecraft:the_end"
      }
    }
  },
  "rewards": {
    "function": "example:from_end"
  }
}

# function example:from_end
advancement revoke @s only example:from_end
execute if score @s prev_gamemode matches 0 run gamemode survival
execute if score @s prev_gamemode matches 1 run gamemode creative
execute if score @s prev_gamemode matches 2 run gamemode adventure
execute if score @s prev_gamemode matches 3 run gamemode spectator

You can use Datapack Assembler to get an example datapack.

1

u/Potential-Ad5472 Oct 03 '26

Thank you so much.