Minecraft:Number provider: Difference between revisions
More actions
Sync: updated from Minecraft |
Sync: updated from Minecraft |
||
| Line 2: | Line 2: | ||
{{For|a similar data structure used in enchantments|Enchantment definition#Level-based value}} | {{For|a similar data structure used in enchantments|Enchantment definition#Level-based value}} | ||
{{Exclusive|Java}} | {{Exclusive|Java}} | ||
{{Update|[[Minecraft:Java Edition 26.3 Snapshot | {{Update|[[Minecraft:Java Edition 26.3 Snapshot 10]]}} | ||
{{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]], and in data components{{Upcoming|Java 26.3}} ({{DCL|compostable}}, {{DCL|cooking_fuel}}, and {{DCL|brewing_fuel}}). | 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]], and in data components{{Upcoming|Java 26.3}} ({{DCL|compostable}}, {{DCL|cooking_fuel}}, and {{DCL|brewing_fuel}}). | ||
| Line 13: | Line 13: | ||
<div class="treeview"> | <div class="treeview"> | ||
*{{File|archive|''data pack name''.zip}} or {{File|directory|''data pack name''}} | *{{File|archive|''data pack name''.zip}} or {{File|directory|''data pack name''}} | ||
**{{File|file|[[ | **{{File|file|[[Minecraft:pack.mcmeta]]}} | ||
**{{File|directory|data}} | **{{File|directory|data}} | ||
***{{File|directory|''namespace''}} | ***{{File|directory|''namespace''}} | ||
| Line 329: | Line 329: | ||
* {{nbt|compound}} | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|sum}} | ** {{nbt|string|type}}: {{cd|sum}} | ||
** {{nbt|list| | ** {{nbt|list|operands}}: List of number providers to sum. | ||
</div> | |||
====Product==== | |||
The product of the multiplication of multiple value providers | |||
<div class="treeview" id="product" style="margin-block-end: 1em;"> | |||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|product}} | |||
** {{nbt|list|operands}}: List of number providers to multiply. | |||
</div> | |||
====Minimum==== | |||
The minimum of multiple value providers | |||
<div class="treeview" id="minimum" style="margin-block-end: 1em;"> | |||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|minimum}} | |||
** {{nbt|list|operands}}: List of number providers to compare. | |||
</div> | |||
====Maximum==== | |||
The maximum of multiple value providers | |||
<div class="treeview" id="maximum" style="margin-block-end: 1em;"> | |||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|maximum}} | |||
** {{nbt|list|operands}}: List of number providers to compare. | |||
</div> | |||
====Average==== | |||
The average of multiple value providers | |||
<div class="treeview" id="average" style="margin-block-end: 1em;"> | |||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|average}} | |||
** {{nbt|list|operands}}: List of number providers to average. | |||
</div> | </div> | ||
Revision as of 11:09, 1 September 2026
Template:For Template:Exclusive Template:Update Template:Wip 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 tables, Minecraft:predicates, Minecraft:item modifiers, villager trade, Minecraft:trade sets, and in data componentsTemplate:Upcoming (Template:DCL, Template:DCL, and Template:DCL).
JSON definition
Number providers can be defined in Minecraft:data packs, as part of the directory structure below.
Use
Number providers are used in Minecraft:loot tables, Minecraft:predicates, Minecraft:item modifiers, villager trade, and Minecraft:trade sets.
Template:InUpcoming, number provider Minecraft:registry can be used in the components Template:DCL, Template:DCL and Template:DCL. In this case, only number providers and constants are accepted, not inline definitions.
Vanila registries
There are registry number providers used in vanilla Minecraft:data pack.
Template:File: Number providers used in the default component Template:DCL: Template:JSON file Template:JSON file Template:JSON file Template:JSON file Template:JSON file
Template:File: Number providers used in the default component Template:DCL, except Template:Cd: Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:JSON file/cooking Template:File: Template:JSON file Template:JSON file
See Template:Slink for a list of items that use such number providers in the component Template:Cd by default.
Format
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.
- Template:Nbt: Constant number provider.
Or:
- Template:Nbt: The root tag. Shorthand for a uniform distributionTemplate:Until.
- Template:NbtTemplate:Nbt: Number provider. The minimum value.
- Template:NbtTemplate:Nbt: Number provider. The maximum value.
Or:
- Template:Nbt: Namespaced ID pointing to an element of number provider Minecraft:registry. See Template:Slink.Template:Upcoming
Or:
- Template:Nbt: The root tag.
- Template:Nbt: The number provider type as a Minecraft:resource location. It can be Template:Cd,Template:CdTemplate:Upcoming, Template:CdTemplate:Upcoming, and Template:CdTemplate:Upcoming.
- Extra fields of the number provider, described below.
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.
By default, the integer is the float converted to the nearest integer (Template:Cd). 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.
Constant
A constant value. Note that the value provided must be a float. If the number provider requires an integer, it will be converted later.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: The exact value.
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:Nbt
- Template:Nbt: Template:Cd
- Template:PastTemplate:Nbt: Number provider. The minimum value (Template:Cd).
- Template:PastTemplate:Nbt: Number provider. The maximum value (Template:Cd).
Binomial
A random number following a binomial distribution. The returned float has the same value as the int.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:PastTemplate:Nbt: Number provider. The amount of trials.
- Template:PastTemplate:Nbt: Number provider. The probability of success on an individual trial.
Score
To query and use a Minecraft:scoreboard value. Return Template:Cd if the scoreboard cannot be calculated.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: To choose which player name or entity UUID to query.
- Template:Nbt: Set to Template:Cd to manually specify a player name or UUID. Set to Template:Cd to use an entity from loot context.
- Template:Nbt: Included only if Template:Nbt is set to Template:Cd. Specifies the name of the player, or the entity's UUID (in hypenated hexadecimal format) whose score to query.
- Template:Nbt: Included only if Template:Nbt is set to Template:Cd. Specifies an entity from loot context to query the score of. Can be Template:Loot entity target
- Template:Nbt: The scoreboard objective to query on the selected player name or UUID.
- Template:Nbt: (Optional. Default Template:Cd) Scale to multiply the score before returning it.
Storage
A value in Minecraft:command storage.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: The Minecraft:resource location of the storage.
- Template:Nbt: The Minecraft:nbt path to the field in storage.
Enchantment level
A value dependent on the level of the Minecraft:loot context enchantment.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: Minecraft:Level-based value calculating the value based on the enchantment.
Sum
The sum of multiple value providers
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: List of number providers to sum.
Product
The product of the multiplication of multiple value providers
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: List of number providers to multiply.
Minimum
The minimum of multiple value providers
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: List of number providers to compare.
Maximum
The maximum of multiple value providers
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: List of number providers to compare.
Average
The average of multiple value providers
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: List of number providers to average.
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:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: An environment attribute ID to fetch.
Number dispatcher
Returns the first case which fulfills its condition or the default if none do.
- Template:Nbt
- Template:Nbt: Template:CdTemplate:Upcoming
- Template:Nbt: A list of cases in the order that the dispatcher will try to execute them.
- Template:Nbt: A single case:
- Template:Nbt: A Minecraft:predicate to be tested in this case.
- Template:PastTemplate:Nbt: A number provider, which is executed if the Template:Nbt is fulfilled.
- Template:Nbt: A single case:
- Template:PastTemplate:Nbt: (Optional. Default Template:Cd) A number provider, which runs if none of the conditions in Template:Nbt is fulfilled.
Conditional
Returns the value from Template:PastTemplate:Nbt if its Template:Nbt or Template:PastTemplate:Nbt if not.
- Template:Nbt
- Template:Nbt: Template:CdTemplate:Upcoming
- Template:Nbt: A Minecraft:predicate to test which value will be returned.
- Template:PastTemplate:Nbt: A number provider, which runs if the Template:Nbt is fulfilled.
- Template:PastTemplate:Nbt: (Optional. Default Template:Cd) A number provider, which runs if the Template:Nbt is not fulfilled.
Weighted list
Returns a value from a distribution of weighted number providers.
- Template:Nbt
- Template:Nbt: Template:CdTemplate:Upcoming
- 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].
- Template:Nbt: A single weighted number provider:
History
Template:Navbox Java Edition technical
Minecraft:de:Zahlenanbieter Minecraft:fr:Fournisseur de nombre Minecraft:ja:ナンバープロバイダー Minecraft:zh:数值提供器