Java 26.2
Gamerule Command
Gamerule
@p
/gamerule keepInventory true
World rules
Gamerules are world switches, and the usual mistake is the value type: keepInventory takes true or false while randomTickSpeed takes an integer, and a mistyped rule name fails without much feedback. Pick the rule here and the generator constrains the value to what that rule accepts.
/gamerule keepInventory true. It takes a true/false value; typing a number instead is a common error, which is why the generator constrains the value to the type each rule expects.
/gamerule mobGriefing false stops creepers, endermen and other mobs from changing blocks. Note it also disables villager farming and some other block interactions.
randomTickSpeed takes an integer, not true/false, and controls crop growth, fire spread and leaf decay. Very high values can lag the world; keep it modest unless you are testing.
Java 26.2
@p
/gamerule keepInventory true