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

Minecraft:Number provider: 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 4: Line 4:
{{Update|[[Minecraft:Java Edition 26.3 Pre-Release 1]]}}
{{Update|[[Minecraft:Java Edition 26.3 Pre-Release 1]]}}
{{wip|Add history, better specify the uses, talk about how it depends on the [[Minecraft:loot context]] and how each use defines the context.}}
{{wip|Add history, better specify the uses, talk about how it depends on the [[Minecraft:loot context]] and how each use defines the context.}}
A '''number provider''' is a data structure used to provide a number, which can be simply a constant, a random number within a certain distribution, a number under a certain condition, etc. Number providers are used in [[Minecraft:loot table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifiers]], [[Minecraft:Villager_trade_definition|villager trade]], [[Minecraft:trade sets]], [[Minecraft:Commands/compute|the compute command]], and in data components ({{DCL|compostable}}, {{DCL|cooking_fuel}}, and {{DCL|brewing_fuel}}).
A '''number provider''' or '''context number provider''' is a data structure used to provide a number, which can be a constant, a random number within a certain distribution, or read from [[Minecraft:scores]] or [[Minecraft:storage]] etc., and mathematical operations or conditional dispatches can be applied. Number providers are used in [[Minecraft:loot table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifiers]], [[Minecraft:Villager_trade_definition|villager trade]], [[Minecraft:trade sets]], the {{cmd|compute}} command, the {{cd|compute}} operation in the {{cmd|data modify}} command, and by reference in data components ({{DCL|compostable}}, {{DCL|cooking_fuel}}, and {{DCL|brewing_fuel}}).


== JSON definition ==
== JSON definition ==
Line 21: Line 21:
== Use ==  
== Use ==  


Number providers are used in [[Minecraft:loot table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifiers]], [[Minecraft:Villager_trade_definition|villager trade]], and [[Minecraft:trade sets]].  
Number providers can be written in-line in [[Minecraft:loot table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifiers]], [[Minecraft:Villager_trade_definition|villager trade]], and [[Minecraft:trade sets]].  


Number provider [[Minecraft:registry]] can be used in the components {{DCL|compostable}}, {{DCL|brewing_fuel}} and {{DCL|cooking_fuel}}. In this case, only number providers and constants are accepted, not inline definitions.
They can additionally be registered by a data pack from the {{cd|context_float_provider}} or {{cd|context_int_provider}} [[Minecraft:registry]], and referenced using a [[Minecraft:namespaced identifier]]. References to registered number providers can be used in data components, such as {{DCL|compostable}}, {{DCL|brewing_fuel}} and {{DCL|cooking_fuel}}. Only a constant or [[Minecraft:namespaced identifier]] may be used here, not inline definitions, due to the data structure only being understood server-side.
 
Number providers can additionally be used in-line or by reference in {{cmd|compute}} and {{cmd|data modify}} to perform operations on data in scoreboards and storage. This is the only way to perform floating-point mathematics with commands.


=== Vanilla context_float_provider registries ===
=== Vanilla context_float_provider registries ===
Line 386: Line 388:
=== Number providers types ===
=== Number providers types ===


{{past|n|copy={{nbt|string}}{{nbt|int}}}}
{{past|n|copy={{nbt|string}}}}
Each type of number provider specifies the rules by which the number will be provided. To do this, they use associated extra contents, which function differently for each type.  
Each type of number provider specifies the rules by which the number will be provided. To do this, they use associated extra contents, which function differently for each type.  


Line 393: Line 395:
Number provider types can ''not'' be customized via data packs.
Number provider types can ''not'' be customized via data packs.


Each type has two ways to get a number: an [[Minecraft:integer]] or a [[Minecraft:float]].  
Each type has two ways to get a number: an [[Minecraft:integer]] or a [[Minecraft:float]], which can be used in {{cd|minecraft:context_int_provider}} and {{cd|minecraft:context_float_provider}} respectively.  
 
<!--By default, the integer is the float converted to the nearest integer ({{cd|floor(x+0.5)}}). Numbers less than or equal to -2,147,483,648.0 are returned as -2,147,483,648, numbers greater than or equal to 2,147,483,648.0 are returned as 2,147,483,647. However, in many types, there is a specific method for gat a integers.-->
<!--By default, the integer is the float converted to the nearest integer ({{cd|floor(x+0.5)}}). Numbers less than or equal to -2,147,483,648.0 are returned as -2,147,483,648, numbers greater than or equal to 2,147,483,648.0 are returned as 2,147,483,647. However, in many types, there is a specific method for gat a integers.-->


==== Integer Providers ====
==== Table of types ====
These can be used in {{cd|minecraft:context_int_provider}}
{| class="wikitable"
 
|+
===== Abs =====
!Type
Returns the absolute value of the input.
!Description
 
!Integer
<div class="treeview" id="constant" style="margin-block-end: 1em;">
!Float
!Nbt
|-
|abs
|Returns the absolute value of the input.
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|abs}}
** {{nbt|string|type}}: {{cd|abs}}
** {{Nbt|string}}{{nbt|compound|input}}: The number to take the absolute value of
** {{Nbt|string}}{{nbt|compound|input}}: The number provider to take the absolute value of
 
</div>
===== Avg =====
|-
The mean of all inputs. Note this rounds towards 0.
|avg
 
|The mean of all inputs.  
|{{Table choice|yes|Note this rounds towards 0.}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|avg}}
** {{nbt|string|type}}: {{cd|avg}}
** {{nbt|list|inputs}}: The numbers to take the mean of
** {{nbt|list|inputs}}: The numbers to take the mean of
</div>
</div>
 
|-
===== Binomial =====
|binomial
A random number following a [[Minecraft:w:Binomial distribution|binomial distribution]]. The returned float has the same value as the int.
|A random number following a [[Minecraft:w:Binomial distribution|binomial distribution]]. The returned float has the same value as the int.
 
|{{Table choice|yes}}
<div class="treeview" id="binomial" style="margin-block-end: 1em;">
|{{Table choice|no}}
|<div class="treeview" id="binomial" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|binomial}}  
** {{nbt|string|type}}: {{cd|binomial}}  
Line 425: Line 437:
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|p}}: Number provider. The probability of success on an individual trial.
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|p}}: Number provider. The probability of success on an individual trial.
</div>
</div>
 
|-
===== Conditional =====
|ceil
Returns the value from {{nbt|string}}{{nbt|int}}{{nbt|compound|on_true}} if its {{Nbt|string}}{{nbt|compound|condition}} is met or {{nbt|string}}{{nbt|int}}{{nbt|compound|on_false}} if not.
|Returns the ceiling (i.e. rounded towards positive infinity) value of the input.
 
|{{Table choice|no}}
<div class="treeview" id="conditional" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|ceil}}
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|input}}: The number provider to round.
</div>
|-
|conditional
|Returns the value from {{nbt|string}}{{nbt|compound|on_true}} if its {{Nbt|string}}{{nbt|compound|condition}} is met or {{nbt|string}}{{nbt|compound|on_false}} if not.
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="conditional" style="margin-block-end: 1em;">
*{{nbt|compound}}
** {{nbt|string|type}}: {{cd|conditional}}
** {{nbt|string|type}}: {{cd|conditional}}
** {{Nbt|string}}{{nbt|compound|condition}}: A '''[[Minecraft:predicate]]''' to test which value will be returned.
** {{Nbt|string}}{{nbt|compound|condition}}: A '''[[Minecraft:predicate]]''' to test which value will be returned.
** {{nbt|string}}{{nbt|int}}{{nbt|compound|on_true}}: A number provider, which runs if the {{Nbt|string}}{{nbt|compound|condition}} is met.
** {{nbt|string}}{{nbt|compound|on_true}}: A number provider, which runs if the {{Nbt|string}}{{nbt|compound|condition}} is met.
** {{nbt|string}}{{nbt|int}}{{nbt|compound|on_false}}: (Optional. Default {{cd|0}}) A number provider,  which runs if the {{Nbt|string}}{{nbt|compound|condition}} is not met.
** {{nbt|string}}{{nbt|compound|on_false}}: (Optional. Default {{cd|0}}) A number provider,  which runs if the {{Nbt|string}}{{nbt|compound|condition}} is not met.
</div>
</div>
 
|-
===== Constant =====
|constant
A constant value.  
|A constant value.
 
|{{Table choice|yes}}
<div class="treeview" id="constant" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|constant}}
** {{nbt|string|type}}: {{cd|constant}}
** {{nbt|int|value}}: The exact value.
** {{nbt|int}} / {{nbt|float|value}}: The exact value.
</div>
</div>
 
|-
===== Sub =====
|cos
Subtracts {{nbt|string}}{{nbt|int}}{{nbt|compound|right}} from {{nbt|string}}{{nbt|int}}{{nbt|compound|left}} and then returns that value
|Returns the cosine of the input.
 
|{{Table choice|no}}
<div class="treeview" id="sum" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|cos}}
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|input}}: The number provider to cosine.
</div>
|-
|sub
|Subtracts {{nbt|string}}{{nbt|compound|right}} from {{nbt|string}}{{nbt|compound|left}} and then returns that value
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="sum" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|sub}}
** {{nbt|string|type}}: {{cd|sub}}
** {{nbt|string}}{{nbt|int}}{{nbt|compound|left}}: The left of the equation
** {{nbt|string}}{{nbt|compound|left}}: The left of the equation
** {{nbt|string}}{{nbt|int}}{{nbt|compound|right}}: The right of the equation<br />
** {{nbt|string}}{{nbt|compound|right}}: The right of the equation
</div>
</div>
===== Uniform =====
|-
A random number following a uniform distribution between two values. The values are inclusive, meaning the provided number can be either {{cd|min}} or {{cd|max}}, except if the provided number is a float, in which case it must be strictly less than {{cd|max}}. If {{cd|max}} &le; {{cd|min}}, the provided number is {{cd|min}}.
|enchantment level
 
|A value dependent on the level of the [[Minecraft:loot context]] enchantment.
<div class="treeview" id="uniform" style="margin-block-end: 1em;">
|{{Table choice|no}}
|{{Table choice|yes}}
|<div class="treeview" id="enchantment_level" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|uniform}}
** {{nbt|string|type}}: {{cd|enchantment_level}}
** {{past|n}}{{nbt|compound|min}}: Number provider. The minimum value ({{cd|min}}).
** {{nbt|string|amount}}: [[Minecraft:Level-based value]] calculating the value based on the enchantment.
** {{past|n}}{{nbt|compound|max}}: Number provider. The maximum value ({{cd|max}}).
</div>
</div>
 
|-
===== Score =====
|floor
To query and use a [[Minecraft:scoreboard]] value.
|Returns the floor (i.e. rounded towards negative infinity) value of the input.
<div class="treeview" id="score" style="margin-block-end: 1em;">
|{{Table choice|no}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|score}}
** {{nbt|string|type}}: {{cd|floor}}
** {{Nbt|string}}{{nbt|compound|target}}: To choose which player name or entity UUID to query. (Must be an object unless specifying an entity from loot context using the same options as {{nbt|string|target}})
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|input}}: The number provider to round.
*** {{nbt|string|type}}: Set to {{cd|fixed}} to manually specify a player name or UUID. Set to {{cd|context}} to use an entity from loot context.
*** {{nbt|string|name}}: Included only if {{nbt|string|type}} is set to {{cd|fixed}}. Specifies the name of the player, or the entity's [[Minecraft:Universally unique identifier|UUID]] <small>(in hypenated hexadecimal format)</small> whose score to query.
*** {{nbt|string|target}}: Included only if {{nbt|string|type}} is set to {{cd|context}}. Specifies an entity from [[#Loot context types|loot context]] to query the score of. Can be {{Loot entity target}}
** {{nbt|string|score}}: The scoreboard objective to query on the selected player name or UUID.
** {{Past|n}}{{Nbt|compound|fallback}}: (Optional. Default {{Code|0}}) The value to return if {{nbt|string|target}} or {{nbt|string|score}} do not exist.
</div>
</div>
 
|-
===== Storage =====
|from_float
A value in [[Minecraft:command storage]].
|Converts a float provider to an integer value.
 
Non integer values will be rounded towards zero.
<div class="treeview" id="storage" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|{{Table choice|no}}
|<div class="treeview" id="maximum" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|storage}}  
** {{nbt|string|type}}: {{cd|from_float}}
** {{nbt|string|storage}}: The [[Minecraft:resource location]] of the storage.
** {{nbt|string}}{{nbt|float}}{{nbt|compound|input}}: A float number provider to convert.
** {{nbt|string|path}}: The [[Minecraft:nbt path]] to the field in storage.
** {{Past|n}}{{Nbt|compound|fallback}}: (Optional. Default {{Code|0}}) The value to return if {{nbt|string|storage}} or {{nbt|string|path}} do not exist.
</div>
</div>
 
|-
===== Enchantment level =====
|from_int
A value dependent on the level of the [[Minecraft:loot context]] enchantment.
|Converts an integer provider to a float value.
 
|{{Table choice|no}}
<div class="treeview" id="enchantment_level" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="maximum" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|enchantment_level}}
** {{nbt|string|type}}: {{cd|from_int}}
** {{nbt|string|amount}}: [[Minecraft:Level-based value]] calculating the value based on the enchantment.
** {{nbt|string}}{{nbt|int}}{{nbt|compound|input}}: An integer number provider to convert.
</div>
</div>
 
|-
===== Add =====
|length
The sum of multiple value providers
|Calculates the [[Minecraft:Euclidean distance]] between two points.
 
The amount of dimensions is the amount of {{nbt|list|inputs}} (For instance, 3 inputs is 3D distance).
<div class="treeview" id="sum" style="margin-block-end: 1em;">
|{{Table choice|no}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|add}}  
** {{nbt|string|type}}: {{cd|length}}
** {{nbt|list|inputs}}: List of number providers to sum.
** {{nbt|list|inputs}}: The axis aligned lengths.  
</div>
</div>
 
|-
===== Mul =====
|max
The product of the multiplication of multiple value providers
|The maximum of multiple value providers
 
|{{Table choice|yes}}
<div class="treeview" id="product" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="maximum" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|mul}}
** {{nbt|string|type}}: {{cd|max}}
** {{nbt|list|inputs}}: List of number providers to multiply.
** {{nbt|list|inputs}}: List of number providers to compare.
</div>
</div>
 
|-
===== Min =====
|min
The minimum of multiple value providers
|The minimum of multiple value providers
 
|{{Table choice|yes}}
<div class="treeview" id="minimum" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="minimum" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|min}}
** {{nbt|string|type}}: {{cd|min}}
** {{nbt|list|inputs}}: List of number providers to compare.
** {{nbt|list|inputs}}: List of number providers to compare.
</div>
</div>
 
|-
===== Max =====
|mod
The maximum of multiple value providers
|Does {{nbt|string}}{{nbt|compound|right}} [[Minecraft:w:Modulo|modulus]] {{nbt|string}}{{nbt|compound|left}} and then returns that value.
 
|{{Table choice|yes|Note this rounds towards zero}}
<div class="treeview" id="maximum" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="sum" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|max}}
** {{nbt|string|type}}: {{cd|mod}}
** {{nbt|list|inputs}}: List of number providers to compare.
** {{nbt|string}}{{nbt|compound|left}}: The left of the equation
** {{nbt|string}}{{nbt|compound|right}}: The right of the equation
</div>
</div>
 
|-
===== Average =====
|floor_mod
The average of multiple value providers
|Does {{nbt|string}}{{nbt|compound|right}} modulus {{nbt|string}}{{nbt|compound|left}} and then returns that value.
 
|{{Table choice|yes|Note this rounds towards negative infinity}}
<div class="treeview" id="average" style="margin-block-end: 1em;">
|{{Table choice|no}}
|<div class="treeview" id="sum" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|average}}  
** {{nbt|string|type}}: {{cd|floor_mod}}
** {{nbt|list|operands}}: List of number providers to average.
** {{nbt|string}}{{nbt|integer}}{{nbt|compound|left}}: The left of the equation
** {{nbt|string}}{{nbt|int}}{{nbt|compound|right}}: The right of the equation
</div>
</div>
 
|-
===== Environment attribute =====
|environment_attribute
Fetches and provides the value of an [[Minecraft:environment attribute]] (that can be represented as a number).
|Fetches and provides the value of an [[Minecraft:environment attribute]] (that can be represented as a number).


This provider requires a context with an origin position set as long as the environment attribute can vary positionally.
This provider requires a context with an origin position set as long as the environment attribute can vary positionally.
 
|{{Table choice|yes}}
<div class="treeview" id="environment_attribute" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="environment_attribute" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|environment_attribute}}  
** {{nbt|string|type}}: {{cd|environment_attribute}}  
** {{nbt|string|attribute}}: An environment attribute ID to fetch.
** {{nbt|string|attribute}}: An environment attribute ID to fetch.
</div>
</div>
 
|-
===== Number dispatcher =====
|negate
Returns the first case which fulfills its condition or the default if none do.
|Returns the negation of the input.
 
|{{Table choice|yes}}
<div class="treeview" id="number_dispatcher" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|negate}}
** {{Nbt|string}}{{nbt|compound|input}}: The number provider to negate.
</div>
|-
|Number dispatcher
|Returns the first case which fulfills its condition or the default if none do.
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="number_dispatcher" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|number_dispatcher}}
** {{nbt|string|type}}: {{cd|number_dispatcher}}
Line 566: Line 620:
** {{past|n}}{{nbt|compound|default}}: (Optional. Default {{cd|0}}) A number provider, which runs if none of the conditions in {{nbt|list|cases}} are met.
** {{past|n}}{{nbt|compound|default}}: (Optional. Default {{cd|0}}) A number provider, which runs if none of the conditions in {{nbt|list|cases}} are met.
</div>
</div>
 
|-
<div class="treeview" id="conditional" style="margin-block-end: 1em;">
|pow
**
|Does {{nbt|string}}{{nbt|compound|base}} to the power of {{nbt|string}}{{nbt|compound|exponent}} and then returns that value.
|{{Table choice|yes|The exponent can't be negative}}
|{{Table choice|yes}}
|<div class="treeview" id="sum" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|pow}}
** {{nbt|string}}{{nbt|compound|base}}: The base of the equation
** {{nbt|string}}{{nbt|compound|exponent}}: The exponent of the equation
</div>
|-
|mul
|The product of the multiplication of multiple value providers
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="product" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|mul}}
** {{nbt|list|inputs}}: List of number providers to multiply.
</div>
|-
|div
|Divides {{nbt|string}}{{nbt|compound|left}} by {{nbt|string}}{{nbt|compound|right}} and then returns that value.
|{{Table choice|yes|Rounds towards zero}}
|{{Table choice|yes}}
|<div class="treeview" id="sum" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|div}}
** {{nbt|string}}{{nbt|compound|left}}: The left of the equation
** {{nbt|string}}{{nbt|compound|right}}: The right of the equation
</div>
|-
|floor_div
|Divides {{nbt|string}}{{nbt|compound|left}} by {{nbt|string}}{{nbt|compound|right}} and then returns that value.
|{{Table choice|yes|Rounds towards negative infinity}}
|{{Table choice|no}}
|<div class="treeview" id="sum" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|floor_div}}
** {{nbt|string}}{{nbt|compound|left}}: The left of the equation
** {{nbt|string}}{{nbt|compound|right}}: The right of the equation
</div>
|-
|round
|Returns the rounded (towards the nearest integer, with ties rounding towards positive infinity) value of the input.
|{{Table choice|no}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|round}}
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|input}}: The number provider to round.
</div>
|-
|sin
|Returns the sine of the input.
|{{Table choice|no}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|sin}}
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|input}}: The number provider to sine.
</div>
|-
|sqrt
|Returns the square root of the input.
|{{Table choice|no}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|sqrt}}
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|input}}: The number provider to square root.
</div>
|-
|score
|To query and use a [[Minecraft:scoreboard]] value.
|{{Table choice|yes}}
|{{Table choice|no}}
|<div class="treeview" id="score" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|score}}
** {{Nbt|string}}{{nbt|compound|target}}: To choose which player name or entity UUID to query. (Must be an object unless specifying an entity from loot context using the same options as {{nbt|string|target}})
*** {{nbt|string|type}}: Set to {{cd|fixed}} to manually specify a player name or UUID. Set to {{cd|context}} to use an entity from loot context.
*** {{nbt|string|name}}: Included only if {{nbt|string|type}} is set to {{cd|fixed}}. Specifies the name of the player, or the entity's [[Minecraft:Universally unique identifier|UUID]] <small>(in hypenated hexadecimal format)</small> whose score to query.
*** {{nbt|string|target}}: Included only if {{nbt|string|type}} is set to {{cd|context}}. Specifies an entity from [[#Loot context types|loot context]] to query the score of. Can be {{Loot entity target}}
** {{nbt|string|score}}: The scoreboard objective to query on the selected player name or UUID.
** {{Past|n}}{{Nbt|compound|fallback}}: (Optional. Default {{Code|0}}) The value to return if {{nbt|string|target}} or {{nbt|string|score}} do not exist.
</div>
|-
|storage
|A value in [[Minecraft:command storage]].
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="storage" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|storage}}
** {{nbt|string|storage}}: The [[Minecraft:resource location]] of the storage.
** {{nbt|string|path}}: The [[Minecraft:nbt path]] to the field in storage.
** {{Past|n}}{{Nbt|compound|fallback}}: (Optional. Default {{Code|0}}) The value to return if {{nbt|string|storage}} or {{nbt|string|path}} do not exist.
</div>
|-
|add
|The sum of multiple value providers
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="sum" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|add}}
** {{nbt|list|inputs}}: List of number providers to sum.
</div>
|-
|truncate
|Returns the truncated (rounded towards zero) value of the input.
|{{Table choice|no}}
|{{Table choice|yes}}
|<div class="treeview" id="constant" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|truncate}}
** {{Nbt|string}}{{Nbt|float}}{{nbt|compound|input}}: The number provider to round.
</div>
|-
|uniform
|A random number following a uniform distribution between two values. The values are inclusive, meaning the provided number can be either {{cd|min}} or {{cd|max}}, except if the provided number is a float, in which case it must be strictly less than {{cd|max}}. If {{cd|max}} &le; {{cd|min}}, the provided number is {{cd|min}}.
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="uniform" style="margin-block-end: 1em;">
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|uniform}}
** {{past|n}}{{nbt|compound|min}}: Number provider. The minimum value ({{cd|min}}).
** {{past|n}}{{nbt|compound|max}}: Number provider. The maximum value ({{cd|max}}).
</div>
</div>
 
|-
===== Weighted list =====
|weighted_list
Returns a value from a distribution of weighted number providers.
|Returns a value from a distribution of weighted number providers.
<div class="treeview" id="weighted_list" style="margin-block-end: 1em;">
|{{Table choice|yes}}
|{{Table choice|yes}}
|<div class="treeview" id="weighted_list" style="margin-block-end: 1em;">
* {{nbt|compound}}
* {{nbt|compound}}
** {{nbt|string|type}}: {{cd|weighted_list}}
** {{nbt|string|type}}: {{cd|weighted_list}}
Line 579: Line 762:
*** {{nbt|compound}}: A single weighted number provider:
*** {{nbt|compound}}: A single weighted number provider:
**** {{past|n}}{{nbt|compound|data}}: A number provider, which is executed if the weighted number provider is chosen.
**** {{past|n}}{{nbt|compound|data}}: A number provider, which is executed if the weighted number provider is chosen.
**** {{nbt|int|weight}}: A positive integer. Determines how often this weighted number provider is chosen out of all data in the distribution. Weighted number provider with higher weights are used more often. The chance of an weighted number provider being chosen is [this weighted number provider's weight ÷ total weight of all weighted number provider in the distribution].  
**** {{nbt|int|weight}}: A positive integer. Determines how often this weighted number provider is chosen out of all data in the distribution. Weighted number provider with higher weights are used more often. The chance of an weighted number provider being chosen is [this weighted number provider's weight ÷ total weight of all weighted number provider in the distribution].
</div>
</div>
 
|}
== History ==
== History ==
{{HistoryTable
{{HistoryTable

Latest revision as of 11:13, 16 October 2026

Template:For Template:Exclusive Template:Update Template:Wip A number provider or context number provider is a data structure used to provide a number, which can be a constant, a random number within a certain distribution, or read from Minecraft:scores or Minecraft:storage etc., and mathematical operations or conditional dispatches can be applied. Number providers are used in Minecraft:loot tables, Minecraft:predicates, Minecraft:item modifiers, villager trade, Minecraft:trade sets, the Template:Cmd command, the Template:Cd operation in the Template:Cmd command, and by reference in data components (Template:DCL, Template:DCL, and Template:DCL).

JSON definition

Use

Number providers can be written in-line in Minecraft:loot tables, Minecraft:predicates, Minecraft:item modifiers, villager trade, and Minecraft:trade sets.

They can additionally be registered by a data pack from the Template:Cd or Template:Cd Minecraft:registry, and referenced using a Minecraft:namespaced identifier. References to registered number providers can be used in data components, such as Template:DCL, Template:DCL and Template:DCL. Only a constant or Minecraft:namespaced identifier may be used here, not inline definitions, due to the data structure only being understood server-side.

Number providers can additionally be used in-line or by reference in Template:Cmd and Template:Cmd to perform operations on data in scoreboards and storage. This is the only way to perform floating-point mathematics with commands.

Vanilla context_float_provider registries

These are registry context_float_providers used in the vanilla Minecraft:data pack

Template:File: Number providers used in the default component Template:Data component link:Template:JSON fileTemplate:File: Number providers used in the default component Template:Data component link Template:JSON fileTemplate:JSON fileTemplate:JSON file/cooking

Vanilla context_int_provider registries

These are registry context_int_providers used in the vanilla Minecraft:data pack.

Template:File: Number providers used in the default component Template:Data component link:Template:JSON file

Template:File: Number providers used in the default component Template:DCL: Template:JSON file Template:JSON file Template:JSON file Template:JSON fileTemplate:JSON fileTemplate:File: Number providers used in the default component Template:DCL:Template:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON fileTemplate:JSON file Template:JSON file Template:JSON fileSee Template:Slink for a list of items that use such number providers in the component Template:Cd by default.

Format

Template:UpdateTemplate:Incomplete section A a number provider can be an Template:Nbt or Template:Nbt. They can either be defined as a constant value or as an object.

Or:

Or:

Or:

Number providers types

Template:Past Each type of number provider specifies the rules by which the number will be provided. To do this, they use associated extra contents, which function differently for each type.

The type values can omit or include the namespace Template:Cd, for example using the type Template:Cd or Template:Cd has the same effect.

Number provider types can not be customized via data packs.

Each type has two ways to get a number: an Minecraft:integer or a Minecraft:float, which can be used in Template:Cd and Template:Cd respectively.

Table of types

Type Description Integer Float Nbt
abs Returns the absolute value of the input. Template:Table choice Template:Table choice
avg The mean of all inputs. Template:Table choice Template:Table choice
binomial A random number following a binomial distribution. The returned float has the same value as the int. Template:Table choice Template:Table choice
ceil Returns the ceiling (i.e. rounded towards positive infinity) value of the input. Template:Table choice Template:Table choice
conditional Returns the value from Template:NbtTemplate:Nbt if its Template:NbtTemplate:Nbt is met or Template:NbtTemplate:Nbt if not. Template:Table choice Template:Table choice
constant A constant value. Template:Table choice Template:Table choice
cos Returns the cosine of the input. Template:Table choice Template:Table choice
sub Subtracts Template:NbtTemplate:Nbt from Template:NbtTemplate:Nbt and then returns that value Template:Table choice Template:Table choice
enchantment level A value dependent on the level of the Minecraft:loot context enchantment. Template:Table choice Template:Table choice
floor Returns the floor (i.e. rounded towards negative infinity) value of the input. Template:Table choice Template:Table choice
from_float Converts a float provider to an integer value.

Non integer values will be rounded towards zero.

Template:Table choice Template:Table choice
from_int Converts an integer provider to a float value. Template:Table choice Template:Table choice
length Calculates the Minecraft:Euclidean distance between two points.

The amount of dimensions is the amount of Template:Nbt (For instance, 3 inputs is 3D distance).

Template:Table choice Template:Table choice
max The maximum of multiple value providers Template:Table choice Template:Table choice
min The minimum of multiple value providers Template:Table choice Template:Table choice
mod Does Template:NbtTemplate:Nbt modulus Template:NbtTemplate:Nbt and then returns that value. Template:Table choice Template:Table choice
floor_mod Does Template:NbtTemplate:Nbt modulus Template:NbtTemplate:Nbt and then returns that value. Template:Table choice Template:Table choice
environment_attribute Fetches and provides the value of an Minecraft:environment attribute (that can be represented as a number).

This provider requires a context with an origin position set as long as the environment attribute can vary positionally.

Template:Table choice Template:Table choice
negate Returns the negation of the input. Template:Table choice Template:Table choice
Number dispatcher Returns the first case which fulfills its condition or the default if none do. Template:Table choice Template:Table choice
pow Does Template:NbtTemplate:Nbt to the power of Template:NbtTemplate:Nbt and then returns that value. Template:Table choice Template:Table choice
mul The product of the multiplication of multiple value providers Template:Table choice Template:Table choice
div Divides Template:NbtTemplate:Nbt by Template:NbtTemplate:Nbt and then returns that value. Template:Table choice Template:Table choice
floor_div Divides Template:NbtTemplate:Nbt by Template:NbtTemplate:Nbt and then returns that value. Template:Table choice Template:Table choice
round Returns the rounded (towards the nearest integer, with ties rounding towards positive infinity) value of the input. Template:Table choice Template:Table choice
sin Returns the sine of the input. Template:Table choice Template:Table choice
sqrt Returns the square root of the input. Template:Table choice Template:Table choice
score To query and use a Minecraft:scoreboard value. Template:Table choice Template:Table choice
storage A value in Minecraft:command storage. Template:Table choice Template:Table choice
add The sum of multiple value providers Template:Table choice Template:Table choice
truncate Returns the truncated (rounded towards zero) value of the input. Template:Table choice Template:Table choice
uniform A random number following a uniform distribution between two values. The values are inclusive, meaning the provided number can be either Template:Cd or Template:Cd, except if the provided number is a float, in which case it must be strictly less than Template:Cd. If Template:Cd ≤ Template:Cd, the provided number is Template:Cd. Template:Table choice Template:Table choice
weighted_list Returns a value from a distribution of weighted number providers. Template:Table choice Template:Table choice
  • Template:Nbt
    • Template:Nbt: Template:Cd
    • Template:Nbt: Returns a value from a distribution of weighted number providers.
      • Template:Nbt: A single weighted number provider:
        • Template:PastTemplate:Nbt: A number provider, which is executed if the weighted number provider is chosen.
        • Template:Nbt: A positive integer. Determines how often this weighted number provider is chosen out of all data in the distribution. Weighted number provider with higher weights are used more often. The chance of an weighted number provider being chosen is [this weighted number provider's weight ÷ total weight of all weighted number provider in the distribution].

History

Template:HistoryTable

Navigation

Minecraft:de:Zahlenanbieter Minecraft:fr:Fournisseur de nombre Minecraft:ja:ナンバープロバイダー Minecraft:lzh:供值器 Minecraft:zh:数值提供器