
Command
/compute
Calculates a number from a number provider and reports it, so it can be read in chat or stored with /execute store.
| /compute (block <computePos>|entity <computeTarget>) float <provider> [<scale>] |
| /compute (block <computePos>|entity <computeTarget>) integer <provider> |
| /compute default float <provider> [<scale>] |
| /compute default integer <provider> |
| Argument | Kind of value | What to type |
|---|---|---|
| <computePos> | Block position | For block: the position of the block the calculation looks at. |
| <provider> | Decimal number provider | The number provider to calculate: an id, or a definition written inline. After integer it must be a whole-number provider, after float a decimal-number provider. |
| <scale> | Decimal number | For float only: a number the value is multiplied by before rounding down. Defaults to 1. |
| <computeTarget> | Target selector | For entity: the single entity the calculation looks at. One entity only. |
| Permission level | 2: operators, worlds with cheats on, command blocks and functions |
| Works in | Singleplayer with cheats enabled and multiplayer servers. Needs permission level 2 (gamemasters): server operators, players with cheats, command blocks, and functions can all run it. |
| Result | Reports the value the number provider returned. The number /execute store saves is that value. For float, the value is multiplied by the scale and rounded down to a whole number, and the message shows both the original and the rounded value when they differ. |
| default | Calculates with only the basic information: the position the command runs at and, if there is one, the entity running it. |
| block | Also gives the calculation the block at the given position, with its block state and its stored data if it has any. The position must be loaded. |
| entity | Also gives the calculation the given entity as its target entity. |
| integer | Uses a whole-number provider and returns its value unchanged. |
| float | Uses a decimal-number provider. The optional scale multiplies the value before it is rounded down, so a scale of 100 keeps two decimals. |
| Provider | The provider is either the id of a number provider from the game or a data pack, such as minecraft:brewing/uses_default, or one written directly in the command, such as a plain number or {type:"minecraft:uniform",min:1,max:6}. |
| Invalid values | Fails with "returned invalid value" if the calculation cannot produce a usable number, for example a division by zero or a result that is not a finite number. |
/compute default integer minecraft:brewing/uses_defaultShows the value of the built-in brewing uses number provider, which is 20.
/compute default integer {type:"minecraft:uniform",min:1,max:6}Rolls a random whole number from 1 to 6.
/compute block ~ ~-1 ~ integer minecraft:cooking/time_coalCalculates the built-in Coal cooking time provider for the block below you.
/compute default float minecraft:cooking/fast_speed_multiplier 100Shows the fast cooking speed multiplier and returns it multiplied by 100.

