Commands/gamerule

Sets or queries a game rule value.

Syntax

 * Java Edition


 * Bedrock Edition
 * $$, gamerules can also be changed in the world options and certain gamerules can be toggled on and off with the command without cheats enabled. This only works in singleplayer, server gamerules and server settings cannot be adjusted using the client settings, even if a player is opped.
 * $$, gamerules can also be changed in the world options and certain gamerules can be toggled on and off with the command without cheats enabled. This only works in singleplayer, server gamerules and server settings cannot be adjusted using the client settings, even if a player is opped.
 * $$, gamerules can also be changed in the world options and certain gamerules can be toggled on and off with the command without cheats enabled. This only works in singleplayer, server gamerules and server settings cannot be adjusted using the client settings, even if a player is opped.

The rule names are listed here.

Arguments
Arguments $$ are case sensitive. Arguments ⇭⇭⇭⇭⇭ are shown for tab autocompletion as lowercase, but when typed are case-insensitive.

(BE:  or  )
 * Specifies the game rule to set or query. Must be one of the predefined game rules; see Game rule.

(BE:  or  ) (optional)
 * Specifies the value to set the game rule to. Only  or   specified for predefined game rules can affect gameplay, except in the case of ,  ,  , and   where any integer 0 or greater affects gameplay; see Game rule.

Result
Fails if the arguments are not specified correctly.

On success, returns the value of the game rule (if  is not provided) or sets the game rule to the specified value (if   is provided).

Examples

 * To stop the day-night cycle:
 * To stop natural healing:
 * To stop creepers, ghasts and other mobs from modifying blocks:
 * To stop the natural cycle of weather:
 * For the player, so that they can keep all of their valuables when they die:
 * To stop TNT from exploding: