Commands/gamerule

Sets or queries a game rule value.

Syntax

 * Java Edition
 * Arguments $$ are case sensitive.
 * Arguments $$ are case sensitive.


 * Bedrock Edition
 * ⇭⇭⇭, gamerules can also be changed in the world options.
 * ⇭⇭⇭, gamerules can also be changed in the world options.
 * ⇭⇭⇭, gamerules can also be changed in the world options.

Arguments

 * Arguments in Bedrock Edition are shown for tab autocompletion as lowercase, but when typed are case-insensitive.


 * rule name (BE: rule: BoolGameRule or rule: IntGameRule)
 * Specifies the game rule to set or query. Only certain predefined game rules affect gameplay (see Predefined Game Rules below).


 * value (BE: true|false or value: int) (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 Predefined game rules below).


 * {| class="wikitable sortable"

! Rule name !class="unsortable"| Description ! Default value ! Type ! Avalibility in BE
 * + Predefined game rules
 * Whether advancements should be announced in chat
 * style="text-align:center" |
 * Bool
 * Whether command blocks should be enabled in-game
 * style="text-align:center" |
 * Bool
 * Whether command blocks should notify admins when they perform commands
 * style="text-align:center" |
 * Bool
 * Whether the server should skip checking player speed when the player is wearing elytra. Often helps with jittering due to lag in multiplayer, but may also be used to travel unfairly long distances in survival mode (cheating).
 * style="text-align:center" |
 * Bool
 * Whether raids are disabled.
 * style="text-align:center" |
 * Bool
 * Whether the day-night cycle and moon phases progress
 * style="text-align:center" |
 * Bool
 * Whether entities that are not mobs should have drops
 * style="text-align:center" |
 * Bool
 * Whether fire should spread and naturally extinguish
 * style="text-align:center" |
 * Bool
 * Whether phantoms can spawn in the nighttime
 * style="text-align:center" |
 * Bool
 * Java:  Bedrock:
 * Players respawn immediately without showing the death screen
 * style="text-align:center" |
 * Bool
 * Whether players should be able to craft only those recipes that they've unlocked first
 * style="text-align:center" |
 * Bool
 * Whether mobs should drop items
 * style="text-align:center" |
 * Bool
 * Whether mobs should naturally spawn. Does not affect monster spawners.
 * style="text-align:center" |
 * Bool
 * Whether patrols can spawn.
 * style="text-align:center" |
 * Bool
 * Whether blocks should have drops
 * style="text-align:center" |
 * Bool
 * Whether wandering traders can spawn.
 * style="text-align:center" |
 * Bool
 * Whether the weather can change naturally. The command can still change weather.
 * style="text-align:center" |
 * Bool
 * Whether the player should take damage when drowning
 * style="text-align:center" |
 * Bool
 * Whether the player should take fall damage
 * style="text-align:center" |
 * Bool
 * Whether the player should take fire damage
 * style="text-align:center" |
 * Bool
 * Whether the player should keep items and experience in their inventory after death
 * style="text-align:center" |
 * Bool
 * Whether to log admin commands to server log
 * style="text-align:center" |
 * Bool
 * Determines the number at which the chain command block acts as a "chain".
 * style="text-align:center" |
 * Int
 * The maximum number of other pushable entities a mob or player can push, before taking suffocation damage per half-second.  Setting to 0 or lower disables the rule.  Damage affects survival-mode or adventure-mode players, and all mobs but bats.  Pushable entities include non-spectator-mode players, any mob except bats, as well as boats and minecarts.
 * style="text-align:center" |
 * Int
 * Whether creepers, zombies, endermen, ghasts, withers, ender dragons, rabbits, sheep, villagers, silverfish, and snow golems should be able to change blocks and whether mobs can pick up items. This also affects the capability of zombie-like creatures like zombie pigmen and drowned to pathfind to turtle eggs. This will also prevent villagers from breeding.
 * style="text-align:center" |
 * Bool
 * Whether the player can regenerate health naturally if their hunger is full enough (doesn't affect external healing, such as golden apples, the Regeneration effect, etc.)
 * style="text-align:center" |
 * Bool
 * Whether the player can fight with other players
 * style="text-align:center" |
 * Bool
 * How often a random block tick occurs (such as plant growth, leaf decay, etc.) per chunk section per game tick. 0 disables random ticks, higher numbers increase random ticks. Setting to a high integer results in high speeds of decay and growth
 * style="text-align:center" |
 * Int
 * Whether the debug screen shows all or reduced information; and whether the effects of (entity hitboxes) and  (chunk boundaries) are shown.
 * style="text-align:center" |
 * Bool
 * Whether the feedback from commands executed by a player should show up in chat. Also affects the default behavior of whether command blocks store their output text
 * style="text-align:center" |
 * Bool
 * Whether the player's coordinates are displayed
 * style="text-align:center" |
 * Bool
 * Whether death messages are put into chat when a player dies. Also affects whether a message is sent to the pet's owner when the pet dies.
 * style="text-align:center" |
 * Bool
 * The number of blocks outward from the world spawn coordinates that a player spawns in when first joining a server or when dying without a personal spawnpoint.
 * style="text-align:center" |
 * Int
 * Whether players in spectator mode can generate chunks
 * style="text-align:center" |
 * Bool
 * Whether TNT explodes after activation
 * style="text-align:center" |
 * Bool
 * Hides the Can place on and Can destroy block lists from item lore.
 * style="text-align:center" |
 * Bool
 * }
 * Whether the player should take fall damage
 * style="text-align:center" |
 * Bool
 * Whether the player should take fire damage
 * style="text-align:center" |
 * Bool
 * Whether the player should keep items and experience in their inventory after death
 * style="text-align:center" |
 * Bool
 * Whether to log admin commands to server log
 * style="text-align:center" |
 * Bool
 * Determines the number at which the chain command block acts as a "chain".
 * style="text-align:center" |
 * Int
 * The maximum number of other pushable entities a mob or player can push, before taking suffocation damage per half-second.  Setting to 0 or lower disables the rule.  Damage affects survival-mode or adventure-mode players, and all mobs but bats.  Pushable entities include non-spectator-mode players, any mob except bats, as well as boats and minecarts.
 * style="text-align:center" |
 * Int
 * Whether creepers, zombies, endermen, ghasts, withers, ender dragons, rabbits, sheep, villagers, silverfish, and snow golems should be able to change blocks and whether mobs can pick up items. This also affects the capability of zombie-like creatures like zombie pigmen and drowned to pathfind to turtle eggs. This will also prevent villagers from breeding.
 * style="text-align:center" |
 * Bool
 * Whether the player can regenerate health naturally if their hunger is full enough (doesn't affect external healing, such as golden apples, the Regeneration effect, etc.)
 * style="text-align:center" |
 * Bool
 * Whether the player can fight with other players
 * style="text-align:center" |
 * Bool
 * How often a random block tick occurs (such as plant growth, leaf decay, etc.) per chunk section per game tick. 0 disables random ticks, higher numbers increase random ticks. Setting to a high integer results in high speeds of decay and growth
 * style="text-align:center" |
 * Int
 * Whether the debug screen shows all or reduced information; and whether the effects of (entity hitboxes) and  (chunk boundaries) are shown.
 * style="text-align:center" |
 * Bool
 * Whether the feedback from commands executed by a player should show up in chat. Also affects the default behavior of whether command blocks store their output text
 * style="text-align:center" |
 * Bool
 * Whether the player's coordinates are displayed
 * style="text-align:center" |
 * Bool
 * Whether death messages are put into chat when a player dies. Also affects whether a message is sent to the pet's owner when the pet dies.
 * style="text-align:center" |
 * Bool
 * The number of blocks outward from the world spawn coordinates that a player spawns in when first joining a server or when dying without a personal spawnpoint.
 * style="text-align:center" |
 * Int
 * Whether players in spectator mode can generate chunks
 * style="text-align:center" |
 * Bool
 * Whether TNT explodes after activation
 * style="text-align:center" |
 * Bool
 * Hides the Can place on and Can destroy block lists from item lore.
 * style="text-align:center" |
 * Bool
 * }
 * style="text-align:center" |
 * Int
 * Whether the debug screen shows all or reduced information; and whether the effects of (entity hitboxes) and  (chunk boundaries) are shown.
 * style="text-align:center" |
 * Bool
 * Whether the feedback from commands executed by a player should show up in chat. Also affects the default behavior of whether command blocks store their output text
 * style="text-align:center" |
 * Bool
 * Whether the player's coordinates are displayed
 * style="text-align:center" |
 * Bool
 * Whether death messages are put into chat when a player dies. Also affects whether a message is sent to the pet's owner when the pet dies.
 * style="text-align:center" |
 * Bool
 * The number of blocks outward from the world spawn coordinates that a player spawns in when first joining a server or when dying without a personal spawnpoint.
 * style="text-align:center" |
 * Int
 * Whether players in spectator mode can generate chunks
 * style="text-align:center" |
 * Bool
 * Whether TNT explodes after activation
 * style="text-align:center" |
 * Bool
 * Hides the Can place on and Can destroy block lists from item lore.
 * style="text-align:center" |
 * Bool
 * }
 * The number of blocks outward from the world spawn coordinates that a player spawns in when first joining a server or when dying without a personal spawnpoint.
 * style="text-align:center" |
 * Int
 * Whether players in spectator mode can generate chunks
 * style="text-align:center" |
 * Bool
 * Whether TNT explodes after activation
 * style="text-align:center" |
 * Bool
 * Hides the Can place on and Can destroy block lists from item lore.
 * style="text-align:center" |
 * Bool
 * }
 * Whether TNT explodes after activation
 * style="text-align:center" |
 * Bool
 * Hides the Can place on and Can destroy block lists from item lore.
 * style="text-align:center" |
 * Bool
 * }
 * Hides the Can place on and Can destroy block lists from item lore.
 * style="text-align:center" |
 * Bool
 * }
 * }

Result

 * Fails if rule is not defined and value is not provided (i.e., attempting to query an undefined game rule).
 * Not execute if "rule name is not a predefined game rule.
 * On success, returns the value of the game rule (if value is not provided) or sets the game rule to the specified value (if value 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:

Additional behavior
This section is dedicated to explaining more complex behaviors of certain gamerules.
 * When true, the Bad Omen effect is not removed from a player when entering a village.
 * Stops a raid if set to true while a raid is in progress, but the existing raid mobs do not despawn.
 * When false, items cannot be removed from item frames.
 * Affects only natural mob spawning. Mobs from structures, spawners, and events still spawn when set to false.
 * When false, containers still drop their contents, but not themselves.
 * Shulker boxes do not drop anything, causing the items in them to be lost.
 * When false, destroying an armor stand does not drop it nor any armor it had equipped.
 * When false, item frames will still drop themselves and their items.
 * When false, the player will still lose air, but will not take damage when the air is depleted.
 * When true, players will also retain their experience upon death.
 * When true, health and hunger are still reset as normal upon death.
 * When false, prevents:
 * All mobs from:
 * Trampling crops.
 * Picking up items.
 * Blazes from creating fire or lighting campfires.
 * Creepers from destroying blocks when they explode, although they still damage entities.
 * The ender dragon from destroying blocks, causing it to just fly through them instead.
 * Endermen from picking up or placing blocks.
 * Foxes from picking sweet berries from a sweet berry bush.
 * Ghast fireballs from exploding blocks and creating fire. They will still damage entities.
 * Rabbits from eating carrot crops.
 * Ravagers from destroying crops and leaves.
 * Sheep from turning grass blocks into dirt, but does not prevent the regrowth of wool.
 * Snow golems from creating snow trails.
 * Villagers from farming and picking up items. However, they can still open doors and throw items.
 * The wither and its heads from destroying blocks with their explosions. Entities will still be damaged, and wither roses will drop as an item.
 * Zombies from breaking doors.
 * Has no effect on the player.
 * Ravagers from destroying crops and leaves.
 * Sheep from turning grass blocks into dirt, but does not prevent the regrowth of wool.
 * Snow golems from creating snow trails.
 * Villagers from farming and picking up items. However, they can still open doors and throw items.
 * The wither and its heads from destroying blocks with their explosions. Entities will still be damaged, and wither roses will drop as an item.
 * Zombies from breaking doors.
 * Has no effect on the player.

History
Befehl/gamerule 命令/gamerule