[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / world/GameRuleManager

# world/GameRuleManager

## Classes

- [GameRuleManager](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/GameRuleManager/classes/GameRuleManager.md)

## Type Aliases

### GameRuleChangeListener

> **GameRuleChangeListener** = (`name`, `value`, `editable`) => `void`

Defined in: [packages/prismarine/src/world/GameRuleManager.ts:66](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/GameRuleManager.ts#L66)

Called after [GameRuleManager.setGameRule](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/GameRuleManager/classes/GameRuleManager.md#setgamerule) stores a change, with the name spelled as
the wire wants it. Not called for the defaults a manager starts with.

#### Parameters

##### name

`string`

##### value

`boolean` \| `number`

##### editable

`boolean`

#### Returns

`void`

***

### GameRuleEntry

> **GameRuleEntry** = \[`value`: `boolean` \| `number`, `editable`: `boolean`\]

Defined in: [packages/prismarine/src/world/GameRuleManager.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/GameRuleManager.ts#L60)

What a rule holds: its value, and whether a player may change it from the settings screen.

## Variables

### GameRules

> `const` **GameRules**: `object`

Defined in: [packages/prismarine/src/world/GameRuleManager.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/GameRuleManager.ts#L19)

The rules every world registers, spelled the way the client spells them.

The client matches a rule by exact string, so these are the camelCase names protocol 2193's
pinned Bedrock Dedicated Server sends in `StartGamePacket` (`doDayLightCycle` with a capital L,
`pvp` all lowercase). They used to be all lowercase, and a client given `showcoordinates`
had no rule by that name to turn on.

Lookups through [GameRuleManager](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/GameRuleManager/classes/GameRuleManager.md) ignore case, so `DoDayLightCycle`,
`dodaylightcycle` and the constant here all name the same rule.

#### Type Declaration

##### CommandBlockOutput

> `readonly` **CommandBlockOutput**: `"commandBlockOutput"` = `'commandBlockOutput'`

##### CommandBlocksEnabled

> `readonly` **CommandBlocksEnabled**: `"commandBlocksEnabled"` = `'commandBlocksEnabled'`

##### DoDayLightCycle

> `readonly` **DoDayLightCycle**: `"doDayLightCycle"` = `'doDayLightCycle'`

##### DoEntityDrops

> `readonly` **DoEntityDrops**: `"doEntityDrops"` = `'doEntityDrops'`

##### DoFireTick

> `readonly` **DoFireTick**: `"doFireTick"` = `'doFireTick'`

##### DoImmediateRespawn

> `readonly` **DoImmediateRespawn**: `"doImmediateRespawn"` = `'doImmediateRespawn'`

##### DoInsomnia

> `readonly` **DoInsomnia**: `"doInsomnia"` = `'doInsomnia'`

##### DoLimitedCrafting

> `readonly` **DoLimitedCrafting**: `"doLimitedCrafting"` = `'doLimitedCrafting'`

##### DoMobLoot

> `readonly` **DoMobLoot**: `"doMobLoot"` = `'doMobLoot'`

##### DoMobSpawning

> `readonly` **DoMobSpawning**: `"doMobSpawning"` = `'doMobSpawning'`

##### DoTileDrops

> `readonly` **DoTileDrops**: `"doTileDrops"` = `'doTileDrops'`

##### DoWeatherCycle

> `readonly` **DoWeatherCycle**: `"doWeatherCycle"` = `'doWeatherCycle'`

##### DrowningDamage

> `readonly` **DrowningDamage**: `"drowningDamage"` = `'drowningDamage'`

##### FallDamage

> `readonly` **FallDamage**: `"fallDamage"` = `'fallDamage'`

##### FireDamage

> `readonly` **FireDamage**: `"fireDamage"` = `'fireDamage'`

##### FreezeDamage

> `readonly` **FreezeDamage**: `"freezeDamage"` = `'freezeDamage'`

##### FunctionCommandLimit

> `readonly` **FunctionCommandLimit**: `"functionCommandLimit"` = `'functionCommandLimit'`

##### KeepInventory

> `readonly` **KeepInventory**: `"keepInventory"` = `'keepInventory'`

##### MaxCommandChainLength

> `readonly` **MaxCommandChainLength**: `"maxCommandChainLength"` = `'maxCommandChainLength'`

##### MobGriefing

> `readonly` **MobGriefing**: `"mobGriefing"` = `'mobGriefing'`

##### NaturalRegeneration

> `readonly` **NaturalRegeneration**: `"naturalRegeneration"` = `'naturalRegeneration'`

##### PlayersSleepingPercentage

> `readonly` **PlayersSleepingPercentage**: `"playersSleepingPercentage"` = `'playersSleepingPercentage'`

##### ProjectilesCanBreakBlocks

> `readonly` **ProjectilesCanBreakBlocks**: `"projectilesCanBreakBlocks"` = `'projectilesCanBreakBlocks'`

##### PVP

> `readonly` **PVP**: `"pvp"` = `'pvp'`

##### RandomTickSpeed

> `readonly` **RandomTickSpeed**: `"randomTickSpeed"` = `'randomTickSpeed'`

##### RecipesUnlock

> `readonly` **RecipesUnlock**: `"recipesUnlock"` = `'recipesUnlock'`

##### RespawnBlocksExplode

> `readonly` **RespawnBlocksExplode**: `"respawnBlocksExplode"` = `'respawnBlocksExplode'`

##### sendCommandFeedback

> `readonly` **sendCommandFeedback**: `"sendCommandFeedback"` = `'sendCommandFeedback'`

##### ShowBorderEffect

> `readonly` **ShowBorderEffect**: `"showBorderEffect"` = `'showBorderEffect'`

##### ShowCoordinates

> `readonly` **ShowCoordinates**: `"showCoordinates"` = `'showCoordinates'`

##### ShowDaysPlayed

> `readonly` **ShowDaysPlayed**: `"showDaysPlayed"` = `'showDaysPlayed'`

##### ShowDeathMessages

> `readonly` **ShowDeathMessages**: `"showDeathMessages"` = `'showDeathMessages'`

##### ShowRecipeMessages

> `readonly` **ShowRecipeMessages**: `"showRecipeMessages"` = `'showRecipeMessages'`

##### ShowTags

> `readonly` **ShowTags**: `"showTags"` = `'showTags'`

##### SpawnRadius

> `readonly` **SpawnRadius**: `"spawnRadius"` = `'spawnRadius'`

##### TNTExplodes

> `readonly` **TNTExplodes**: `"tntExplodes"` = `'tntExplodes'`

##### TNTExplosionDropDecay

> `readonly` **TNTExplosionDropDecay**: `"tntExplosionDropDecay"` = `'tntExplosionDropDecay'`

## Functions

### defaultGameRule()

> **defaultGameRule**(`name`): `number` \| `boolean` \| `undefined`

Defined in: [packages/prismarine/src/world/GameRuleManager.ts:138](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/GameRuleManager.ts#L138)

The value every world starts a rule at, found by any spelling of its name.

#### Parameters

##### name

`string`

#### Returns

`number` \| `boolean` \| `undefined`

The default, or undefined for a rule no world registers.

***

### isJavaOnlyGameRule()

> **isJavaOnlyGameRule**(`name`): `boolean`

Defined in: [packages/prismarine/src/world/GameRuleManager.ts:131](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/GameRuleManager.ts#L131)

Whether a rule is one a Bedrock client has no counterpart for.

#### Parameters

##### name

`string`

The rule's name as the manager stores it, in any casing.

#### Returns

`boolean`

***

### toNetworkGameRule()

> **toNetworkGameRule**(`name`, `value`, `editable`): [`GameRuleFields`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#gamerulefields)

Defined in: [packages/prismarine/src/world/GameRuleManager.ts:153](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/GameRuleManager.ts#L153)

Shapes one stored rule as the protocol's `GameRule`.

A boolean travels as the boolean alternative, a whole number as a signed int32 and
anything else as a float. The integer used to go out through `writeUnsignedIntLE`, which
threw on a negative value; the docs type it `int32`.

#### Parameters

##### name

`string`

The rule's name, spelled as the wire wants it.

##### value

`number` \| `boolean`

The rule's value.

##### editable

`boolean`

Whether a player may change it from the settings screen.

#### Returns

[`GameRuleFields`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#gamerulefields)
