Commands/gamerule

Sets or queries a game rule value.

Syntax

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


 * Bedrock Edition

Arguments

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


 * rule name (BE: rule: BoolGameRule)
 * Specifies the game rule to set or query. Only certain predefined game rules will 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 will really affect gameplay, except in the case of ,  ,  , and   where any integer 0 or greater will affect gameplay (see Predefined Game Rules below).


 * {| class="wikitable sortable"

! Rule Name ! Description ! Default Value ! Type ! Java Edition ! Bedrock Edition
 * + 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 will spawn in the nighttime
 * style="text-align:center" |
 * Bool
 * Whether players should only be able to craft 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 blocks should have drops
 * style="text-align:center" |
 * Bool
 * Whether the weather will change
 * 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 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 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, and snow golems should be able to change blocks and whether mobs can pick up items
 * 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 will disable random ticks, higher numbers will 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 will spawn 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 will explode
 * 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 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 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, and snow golems should be able to change blocks and whether mobs can pick up items
 * 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 will disable random ticks, higher numbers will 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 will spawn 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 will explode
 * 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 will disable random ticks, higher numbers will 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 will spawn 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 will explode
 * 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 will spawn 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 will explode
 * style="text-align:center" |
 * Bool
 * }
 * The number of blocks outward from the world spawn coordinates that a player will spawn 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 will explode
 * style="text-align:center" |
 * Bool
 * }
 * Whether players in spectator mode can generate chunks
 * style="text-align:center" |
 * Bool
 * Whether TNT will explode
 * style="text-align:center" |
 * Bool
 * }
 * Whether TNT will explode
 * style="text-align:center" |
 * Bool
 * }
 * }
 * }

Result

 * Fails if rule name is not defined and value is not provided (i.e., attempting to query an undefined game rule), or 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:
 * To keep all of your valuables when you die:

Additional Behavior
This section is dedicated to explaining more complex behaviors of certain gamerules.
 * When true, the Bad Omen will not be removed from a player when entering a village.
 * If set to true while a raid is in progress, the raid will stop, but the existing raid mobs will not despawn.
 * When false, containers will still drop their contents, but not themselves.
 * Shulker boxes will not drop anything, causing the items in them to be lost.
 * Prevents creepers from destroying blocks when they explode, though they will still damage entities.
 * Prevents blazes from creating fire.
 * Prevents ghast fireballs from exploding blocks and creating fire.
 * Prevents villagers from farming and picking up items. However, they can still open doors and throw items.
 * Prevents sheep from turning grass blocks into dirt, but does not prevent the regrowth of wool.
 * Prevents the ender dragon from destroying blocks, causing it to just fly through them instead.
 * Prevents the wither and its heads from destroying blocks with their explosions.
 * Prevents endermen from picking up or placing blocks.
 * Prevents zombies from breaking doors.
 * Prevents rabbits from eating carrot crops.
 * Prevents snow golems from creating snow trails.
 * Prevents ravagers from destroying crops and leaves.
 * Prevents Foxes from picking sweet berries from a sweet berry bush
 * Prevents all mobs from trampling crops.
 * Has no effect on the player.
 * Prevents Foxes from picking sweet berries from a sweet berry bush
 * Prevents all mobs from trampling crops.
 * Has no effect on the player.

History
命令/gamerule