Game rules (gamerule) in Minecraft: the most useful ones
keepInventory, doDaylightCycle, mobGriefing, playersSleepingPercentage and more: how to change game rules, what they do and how to tune your world.
Updated:

Game rules change the world's basic behaviour: whether you lose items on death, whether day and night cycle, whether creepers destroy blocks. You set them with the /gamerule command or on the world creation screen.
How to change a rule
- With a command:
/gamerule name value, for example/gamerule keepInventory true. You need cheats or operator rights — see commands. - When creating a world: “More World Options” → “Game Rules”.
- Without a value the command shows the current one:
/gamerule keepInventory.
Rules are stored in the world itself. In the newest versions rule names may differ — Tab after /gamerule shows the current list.
The most useful rules
keepInventory true— items and XP don't drop on death.doDaylightCycle false— stop time (eternal day or night).doWeatherCycle false— stop weather changes.mobGriefing false— creepers don't destroy blocks, endermen don't steal them.doFireTick false— fire doesn't spread.playersSleepingPercentage 0— the night is skipped when just one player sleeps; 50 means half.doInsomnia false— no phantoms.doMobSpawning false— mobs don't spawn on their own.randomTickSpeed 3— plant growth speed (3 is default; higher values speed it up and load the game).doImmediateRespawn true— respawn without the death screen.commandBlockOutput false— command blocks don't spam chat. See command blocks.
On a server
An operator types the same commands in chat or the server console. A rule applies to the specific world; the Nether and the End don't need separate setup.
Download TCLauncher — world backups in the launcher let you experiment with rules safely.
FAQ
How do I keep my items after death?
With the command /gamerule keepInventory true.
How do I skip the night when one player sleeps?
/gamerule playersSleepingPercentage 0.
How do I stop creepers destroying blocks?
/gamerule mobGriefing false — but it also stops other mobs that change blocks.