Calculate Numbers from Providers with the Compute Command
The /compute command lets you evaluate number providers directly in the game. It takes an inline SNBT provider and calculates either an integer or a decimal number based on the context you choose.
Map makers and data pack creators use this command to test math logic, read entity scores, and generate random numbers. You can run the calculation using a default setup, a specific block position, or a targeted entity.
/compute block <computePos> float <provider> [<scale>]/compute block <computePos> integer <provider>/compute default float <provider> [<scale>]/compute default integer <provider>/compute entity <computeTarget> float <provider> [<scale>]/compute entity <computeTarget> integer <provider>/compute default integer <provider>/compute default float <provider> [<scale>]/compute block <computePos> integer <provider>/compute block <computePos> float <provider> [<scale>]/compute entity <computeTarget> integer <provider>/compute entity <computeTarget> float <provider> [<scale>]| Argument | Type | What it means |
|---|---|---|
<computePos> | block position | The three block coordinates (x y z) for the calculation, which can use ~ for relative positions or ^ for local coordinates. |
<provider> | context float provider | The context int provider or context float provider written inline as SNBT to define how the number is calculated. |
<scale> | decimal number | An optional decimal number that multiplies the result of a float provider before rounding it to a whole number. |
<provider> | context int provider | The context int provider or context float provider written inline as SNBT to define how the number is calculated. |
<computeTarget> | target selector one target | A player name, UUID, or target selector like @p or @s that selects a single entity. |
/compute default integer {type:"minecraft:constant",value:10}Evaluates a simple constant provider and returns the whole number 10.
/compute default float {type:"minecraft:constant",value:2.5} 2Takes the decimal value 2.5, multiplies it by a scale of 2, and returns the rounded value of 5.
/compute default integer {type:"minecraft:binomial",n:10,p:0.5}Generates a random whole number using a binomial distribution with 10 trials and a 0.5 probability.
/compute block 0 -60 0 integer {type:"minecraft:constant",value:7}Runs an integer provider using the block at coordinates 0 -60 0 as the context to return 7.
/compute entity @e[limit=1] integer {type:"minecraft:score",target:"this",score:"x"}Reads and returns the scoreboard value of objective x from a single nearby entity.
/compute entity @p integer {type:"minecraft:score",target:"this",score:"coins"}Finds the nearest player and returns their current score in the coins objective.
/compute block ~ ~-1 ~ float {type:"minecraft:constant",value:1.25} 4Uses the block directly beneath you to evaluate 1.25 multiplied by 4, returning a rounded result of 5.
Measured from the game files of every Java release from 1.13 to 26.3.
The /compute command is only available in Minecraft Java Edition starting in version 26.3. Bedrock Edition does not have a command with this name.
The /compute command was added to Minecraft Java Edition in version 26.3.
The command expects a context provider written in SNBT format rather than a bare number, so you must format it like {type:"minecraft:constant",value:10}.
The optional scale argument multiplies the decimal number from the float provider and then rounds the final answer to a whole number.