Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/compute: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Sync: updated from Minecraft
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{wip}}
{{wip}}
{{In development|Java||26.3}}
{{Infobox command
{{Infobox command
|name = compute
|name = compute
Line 9: Line 8:


== Syntax ==
== Syntax ==
: {{cmd|compute <CONTEXT> <provider> [<scale>]}}
: {{cmd|compute <CONTEXT> float <floatProvider> [<scale>]}}
: {{cmd|compute <CONTEXT> <provider> integer}}
: {{cmd|compute <CONTEXT> integer <intProvider>}}
: Where {{cd|CONTEXT}} is one of:
: Where {{cd|CONTEXT}} is one of:
:: {{cd|default}}
:: {{cd|default}}
::: Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_default|{{cd|minecraft:command_compute_default}}]] context, which provides common parameters such as the execution position and {{cd|this}} entity.
::: Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_default|{{cd|minecraft:command_compute_default}}]] context, which provides common parameters such as the execution position and {{cd|this}} entity.
:: {{cd|block <pos>}}
:: {{cd|block <pos>}}
::: Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_position|{{cd|minecraft:command_compute_position}}]] context, providing the block state and block entity of the block at {{cd|<pos>}}.
::: Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_position|{{cd|minecraft:command_compute_position}}]] context, providing the block state and block entity found at {{cd|<pos>}} alongside the common parameters.
:: {{cd|entity <target>}}
:: {{cd|entity <target>}}
::: Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_entity|{{cd|minecraft:command_compute_entity}}]] context, providing the selected entity as {{cd|target_entity}}.
::: Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_entity|{{cd|minecraft:command_compute_entity}}]] context, providing the selected entity as {{cd|target_entity}} alongside the common parameters.


: In float mode, {{cd|<provider>}} is evaluated as a floating-point value. If {{cd|<scale>}} is specified, the resulting value is multiplied by it. The resulting value is then rounded down to the nearest integer.
Float providers are evaluated to produce a floating-point value, but a command's {{cd|result}} value can only be an integer, so the actual result is rounded down to the nearest integer before being returned. If {{cd|<scale>}} is specified, the result is multiplied by that before being rounded down, allowing more precision to be returned. Integer providers already produce an integer value, so no scaling is needed.
: If {{cd|<scale>}} is omitted, a scale of {{cd|1.0}} is used.
 
: In integer mode, specified by {{cd|integer}}, the provider is evaluated directly as an integer. The {{cd|<scale>}} argument cannot be used with integer mode.
To store a float without losing any precision, see {{cmd|data modify ... compute ...}} instead, which avoids passing the value through {{cd|result}}.


== Arguments ==
== Arguments ==
Line 33: Line 32:
: {{arg desc|je=entity|amount=single|type=entities}}
: {{arg desc|je=entity|amount=single|type=entities}}


{{argument|provider|number_provider}}
{{argument|floatProvider|context_float_provider}}
: Specifies the [[Minecraft:number provider]] to evaluate.
: Specifies the [[Minecraft:context float provider]] to evaluate. Can be an [[Minecraft:identifier]] or an inline definition.
: {{arg desc|je=number_provider}}
: {{arg desc|je=context_float_provider}}
 
{{argument|intProvider|context_int_provider}}
: Specifies the [[Minecraft:context int provider]] to evaluate. Can be an [[Minecraft:identifier]] or an inline definition.
: {{arg desc|je=context_int_provider}}


{{argument|scale|float}}
{{argument|scale|float}}
: Specifies the value by which the provider's result is multiplied in float mode.
: Specifies the value by which the float provider's result is multiplied.
: If omitted, {{cd|1.0}} is used.
: If omitted, {{cd|1.0}} is used.
: The resulting value is rounded down to the nearest integer after scaling.
: The resulting value is rounded down to the nearest integer after scaling.
Line 53: Line 56:
{{Output table}}
{{Output table}}
{{Output table|edition=je|On fail|0|0}}
{{Output table|edition=je|On fail|0|0}}
{{Output table|On success|The integer result produced by the number provider.|the computed result|the computed result}}
{{Output table|cmd=/compute ... float ...|On success|1|1|the computed result, scaled and then rounded down}}
{{Output table|cmd=/compute ... integer ...|On success|1|1|the computed result}}
{{Output table}}
{{Output table}}


Line 60: Line 64:
== History ==
== History ==
{{HistoryTable
{{HistoryTable
|{{HistoryLine|upcoming java}}
|{{HistoryLine|java}}
|{{HistoryLine||26.3|dev=snap10|Added {{cmd|link=none|compute}}.}}
|{{HistoryLine||26.3|dev=snap10|Added {{cmd|link=none|compute}}.}}
|{{HistoryLine||26.3|dev=pre1|Adjusted command syntax to match the separation of number providers into int and float providers.}}
}}
}}



Latest revision as of 11:06, 16 October 2026

Template:Wip Template:Infobox command

Evaluates Minecraft:number providers in various Minecraft:loot contexts.

Syntax

Template:Cmd
Template:Cmd
Where Template:Cd is one of:
Template:Cd
Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_default|Template:Cd]] context, which provides common parameters such as the execution position and Template:Cd entity.
Template:Cd
Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_position|Template:Cd]] context, providing the block state and block entity found at Template:Cd alongside the common parameters.
Template:Cd
Runs the provider with the [[Minecraft:Loot context#minecraft:command_compute_entity|Template:Cd]] context, providing the selected entity as Template:Cd alongside the common parameters.

Float providers are evaluated to produce a floating-point value, but a command's Template:Cd value can only be an integer, so the actual result is rounded down to the nearest integer before being returned. If Template:Cd is specified, the result is multiplied by that before being rounded down, allowing more precision to be returned. Integer providers already produce an integer value, so no scaling is needed.

To store a float without losing any precision, see Template:Cmd instead, which avoids passing the value through Template:Cd.

Arguments

Template:Argument

Specifies the block whose state and block entity are made available to the number provider.
Template:Arg desc

Template:Argument

Specifies the entity whose data is made available to the number provider as Template:Cd.
Template:Arg desc

Template:Argument

Specifies the Minecraft:context float provider to evaluate. Can be an Minecraft:identifier or an inline definition.
Template:Arg desc

Template:Argument

Specifies the Minecraft:context int provider to evaluate. Can be an Minecraft:identifier or an inline definition.
Template:Arg desc

Template:Argument

Specifies the value by which the float provider's result is multiplied.
If omitted, Template:Cd is used.
The resulting value is rounded down to the nearest integer after scaling.
Template:Arg desc

Result

Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table

Output

Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table

When the provider has a registered identifier, a successful command also displays its identifier and the computed result. In float mode, if scaling and rounding change the provider's original value, the output also displays the original floating-point value.

History

Template:HistoryTable

Navigation

Template:Navbox new content Template:Navbox commands

Minecraft:de:Befehl/compute Minecraft:ja:コマンド/compute Minecraft:zh:命令/compute