Minecraft:Number provider: Difference between revisions
More actions
Sync: updated from Minecraft |
Sync: updated from Minecraft |
||
| Line 22: | Line 22: | ||
== Use == | == Use == | ||
In most uses of number provider, it is used as an [[Minecraft:NBT]] object, within a larger structure | In most uses of number provider, it is used as an [[Minecraft:NBT]] object, within a larger structure. This includes all uses in [[Minecraft:loot table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifiers]], [[Minecraft:Villager_trade_definition|villager trade]], and [[Minecraft:trade sets]]. | ||
In Java 26.3, number provider [[Minecraft:registry]] can be used in the component {{DCL|compostable}} to define how many layers are added when using [[Minecraft:composter]]. In this case, only number providers are accepted, not line definitions. | In Java 26.3, number provider [[Minecraft:registry]] can be used in the component {{DCL|compostable}} to define how many layers are added when using [[Minecraft:composter]]. In this case, only number providers are accepted, not line definitions. | ||
| Line 29: | Line 29: | ||
{{in development|Java|section=1||26.3}} | {{in development|Java|section=1||26.3}} | ||
There are registry number providers used in vanilla data pack. | There are registry number providers used in vanilla [[Minecraft:data pack]]. | ||
{{File|directory|compostable}}: Number providers used in the component {{DCL|compostable}} | {{File|directory|compostable}}: Number providers used in the default component {{DCL|compostable}}: | ||
{{JSON file|always_add_one|1.0}} | {{JSON file|always_add_one|1.0}} | ||
{{JSON file|low|{ | {{JSON file|low|{ | ||
| Line 150: | Line 150: | ||
}} | }} | ||
{{File|directory|cooking}}: Number providers used in the component {{DCL|cooking_fuel.burn_time}} | {{File|directory|cooking}}: Number providers used in the default component {{DCL|cooking_fuel.burn_time}}, except {{cd|speed_default}}: | ||
{{JSON file/cooking|speed_default|1.0|2.0}} | {{JSON file/cooking|speed_default|1.0|2.0|desc=: Used in the default components {{cd|cooking_fuel.speed_multiplier}} and {{DCL|brewing_fuel.speed_multiplier}}}} | ||
{{JSON file/cooking|time_bamboo|50.0|25.0}} | {{JSON file/cooking|time_bamboo|50.0|25.0}} | ||
{{JSON file/cooking|time_blaze|2400.0|1200.0}} | {{JSON file/cooking|time_blaze|2400.0|1200.0}} | ||
| Line 171: | Line 171: | ||
{{JSON file/cooking|time_wool_slabs|50.0|25.0}} | {{JSON file/cooking|time_wool_slabs|50.0|25.0}} | ||
{{File|directory|brewing}}: | {{File|directory|brewing}}: | ||
{{JSON file|speed_default|1.0}} | {{JSON file|speed_default|1.0|desc=: Not used}} | ||
{{JSON file|uses_default|20.0}} | {{JSON file|uses_default|20.0|desc=: Used in the default component {{DCL|brewing_fuel.uses}}}} | ||
See {{Slink|Composter|Composting}} for a list of items that use such number providers in the component {{cd|compostable}} by default. | See {{Slink|Composter|Composting}} for a list of items that use such number providers in the component {{cd|compostable}} by default. | ||
<!-- | |||
=== [[Minecraft:Loot table]] === | |||
In the {{cd|rolls}} and {{cd|bonus_rolls}} fields of pool, a number provider is used. | |||
<div class="treeview"> | |||
* {{nbt|compound}} The root. | |||
** {{nbt|int}}{{nbt|compound|rolls}}: Specifies the number of rolls on the pool. | |||
** {{nbt|float}}{{nbt|compound|bonus_rolls}}: (Optional. Defaults to {{cd|0.0}}). Specifies the number of bonus rolls on the pool per level of luck (including [[Minecraft:Attributes#Attributes_for_players|luck attribute]] and [[Minecraft:Enchantment definition|fishing_luck_bonus]] on fishing tool). Rounded down after multiplying. [[Minecraft:Enchantment definition|Fishing_luck_bonus]] applies only to fishing. In vanilla games, luck attribute is from the [[Minecraft:Luck]] status effect, and [[Minecraft:Enchantment definition|fishing_luck_bonus]] is from the [[Minecraft:Luck of the Sea]] enchantment. | |||
</div> | |||
Loot tables also use fields with, for example, item predicates and item modifiers, which also use number provider. | |||
{| class="wikitable" | |||
! Register | |||
! [[Minecraft:NBT path]] | |||
! type | |||
! Number format | |||
! [[Minecraft:Loot context]] | |||
! Default | |||
! Use | |||
|- | |||
|rowspan="2"| [[Minecraft:Loot table]] | |||
| pools[].rolls | |||
| - | |||
| {{nbt|int}} Int | |||
| The same as the loot table. | |||
| - | |||
| Specifies the number of rolls on the pool. | |||
|- | |||
| pools[].bonus_rolls | |||
| - | |||
| {{nbt|int}} Int | |||
| The same as the loot table. | |||
| {{cd|0.0}} | |||
| Specifies the number of bonus rolls on the pool per level of luck. | |||
{{cd|count {{=}} rolls + floor(bonusRolls × luck)}} | |||
|- | |||
|} | |||
--> | |||
== Format == | == Format == | ||
| Line 185: | Line 226: | ||
Or: | Or: | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{nbt|compound}}: The root tag. Shorthand for a uniform distribution. | * {{nbt|compound}}: The root tag. Shorthand for a uniform distribution{{Until|Java 26.3}}. | ||
** {{nbt|int}}{{nbt|float}}{{nbt|compound|min}}: Number provider. The minimum value. | ** {{nbt|int}}{{nbt|float}}{{nbt|compound|min}}: Number provider. The minimum value. | ||
** {{nbt|int}}{{nbt|float}}{{nbt|compound|max}}: Number provider. The maximum value. | ** {{nbt|int}}{{nbt|float}}{{nbt|compound|max}}: Number provider. The maximum value. | ||
</div> | |||
Or: | |||
<div class="treeview"> | |||
* {{nbt|string}}: Namespaced ID pointing to an element of number provider [[Minecraft:registry]]. See {{Slink||Vanila registries}}.{{Upcoming|JE 26.3}} | |||
</div> | </div> | ||
| Line 197: | Line 243: | ||
</div> | </div> | ||
=== Number providers | === Number providers types === | ||
{{past|n|copy={{nbt|string}}{{nbt|int}}{{nbt|float}}}} | |||
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 {{cd|minecraft}}, for example using the type {{cd|uniform}} or {{cd|minecraft:uniform}} has the same effect. | |||
Number provider types can ''not'' be customized via data packs. | |||
==== Constant ==== | |||
A constant value. | |||
<div class="treeview" id="constant" style="margin-block-end: 1em;"> | <div class="treeview" id="constant" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|constant}} | |||
** {{nbt|int}}{{nbt|float|value}}: The exact value. | ** {{nbt|int}}{{nbt|float|value}}: The exact value. | ||
</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}} ≤ {{cd|min}}, the provided number is {{cd|min}}. | |||
<div class="treeview" id="uniform" style="margin-block-end: 1em;"> | <div class="treeview" id="uniform" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt| | ** {{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> | ||
==== Binomial ==== | |||
A random number following a [[Minecraft:w:Binomial distribution|binomial distribution]]. The returned float has the same value as the int. | |||
<div class="treeview" id="binomial" style="margin-block-end: 1em;"> | <div class="treeview" id="binomial" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{ | ** {{nbt|string|type}}: {{cd|binomial}} | ||
** {{ | ** {{past|n}}{{nbt|compound|n}}: Number provider. The amount of trials. | ||
** {{past|n}}{{nbt|compound|p}}: Number provider. The probability of success on an individual trial. | |||
</div> | </div> | ||
==== Score ==== | |||
To query and use a [[Minecraft:scoreboard]] value. Return {{cd|0.0}} if the scoreboard cannot be calculated. | |||
<div class="treeview" id="score" style="margin-block-end: 1em;"> | <div class="treeview" id="score" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|score}} | |||
** {{nbt|compound|target}}: To choose which player name or entity UUID to query. | ** {{nbt|compound|target}}: To choose which player name or entity UUID to query. | ||
*** {{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|type}}: Set to {{cd|fixed}} to manually specify a player name or UUID. Set to {{cd|context}} to use an entity from loot context. | ||
| Line 225: | Line 294: | ||
*** {{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|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. | ** {{nbt|string|score}}: The scoreboard objective to query on the selected player name or UUID. | ||
** {{nbt|float|scale}}: (Optional) Scale to multiply the score before returning it. | ** {{nbt|float|scale}}: (Optional. Default {{cd|1.0}}) Scale to multiply the score before returning it. | ||
</div> | </div> | ||
==== Storege ==== | |||
A value in [[Minecraft:command storage]]. | |||
<div class="treeview" id="storage" style="margin-block-end: 1em;"> | <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|storage}}: The [[Minecraft:resource location]] of the storage. | ||
** {{nbt|string|path}}: The [[Minecraft:nbt path]] to the field in storage. | ** {{nbt|string|path}}: The [[Minecraft:nbt path]] to the field in storage. | ||
</div> | </div> | ||
==== Enchantment level ==== | |||
A value dependent on the level of the [[Minecraft:loot context]] enchantment. | |||
<div class="treeview" id="enchantment_level" style="margin-block-end: 1em;"> | <div class="treeview" id="enchantment_level" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|amount}}: [[Minecraft: | ** {{nbt|string|type}}: {{cd|enchantment_level}} | ||
** {{nbt|string|amount}}: [[Minecraft:Level-based value]] calculating the value based on the enchantment. | |||
</div> | </div> | ||
====Sum==== | |||
The sum of multiple value providers | |||
<div class="treeview" id="sum" style="margin-block-end: 1em;"> | <div class="treeview" id="sum" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|sum}} | |||
** {{nbt|list|summands}}: List of number providers to sum. | ** {{nbt|list|summands}}: List of number providers to sum. | ||
</div> | </div> | ||
==== 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. | |||
<div class="treeview" id="environment_attribute" style="margin-block-end: 1em;"> | <div class="treeview" id="environment_attribute" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|environment_attribute}} | |||
** {{nbt|string|attribute}}: An | ** {{nbt|string|attribute}}: An environment attribute ID to fetch. | ||
</div> | </div> | ||
==== Number dispatcher ==== | |||
Returns the first case which fulfills its condition or the default if none do. | |||
<div class="treeview" id="number_dispatcher" style="margin-block-end: 1em;"> | <div class="treeview" id="number_dispatcher" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|number_dispatcher}}{{Upcoming|Java 26.3}} | |||
** {{nbt|list|cases}}: A list of cases in the order that the dispatcher will try to execute them. | ** {{nbt|list|cases}}: A list of cases in the order that the dispatcher will try to execute them. | ||
*** {{nbt|compound}}: A single case: | *** {{nbt|compound}}: A single case: | ||
**** {{nbt|compound|condition}}: A '''[[Minecraft:predicate]]''' to be tested in this case. | **** {{nbt|compound|condition}}: A '''[[Minecraft:predicate]]''' to be tested in this case. | ||
**** {{ | **** {{past|n}}{{nbt|compound|number_provider}}: A number provider, which is executed if the {{nbt|compound|condition}} is fulfilled. | ||
** {{ | ** {{past|n}}{{nbt|compound|default}}: (Optional. Default {{cd|0.0}}) A number provider, which runs if none of the conditions in {{nbt|list|cases}} is fulfilled. | ||
</div> | </div> | ||
==== Conditional ==== | |||
Returns the value from {{past|n}}{{nbt|compound|on_true}} if its {{nbt|compound|conditions}} or {{past|n}}{{nbt|compound|on_false}} if not. | |||
<div class="treeview" id="conditional" style="margin-block-end: 1em;"> | <div class="treeview" id="conditional" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|conditional}}{{Upcoming|Java 26.3}} | |||
** {{nbt|compound|conditions}}: A '''[[Minecraft:predicate]]''' to test which value will be returned. | ** {{nbt|compound|conditions}}: A '''[[Minecraft:predicate]]''' to test which value will be returned. | ||
** {{ | ** {{past|n}}{{nbt|compound|on_true}}: A number provider, which runs if the {{nbt|compound|conditions}} is fulfilled. | ||
** {{ | ** {{past|n}}{{nbt|compound|on_false}}: (Optional. Default {{cd|0.0}}) A number provider, which runs if the {{nbt|compound|conditions}} is not fulfilled. | ||
</div> | </div> | ||
====Weighted list==== | |||
Returns a value from a distribution of weighted number providers. | |||
<div class="treeview" id="weighted_list" style="margin-block-end: 1em;"> | <div class="treeview" id="weighted_list" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt|string|type}}: {{cd|weighted_list}}{{Upcoming|Java 26.3}} | |||
** {{nbt|list|distribution}}: Returns a value from a distribution of weighted number providers. | ** {{nbt|list|distribution}}: Returns a value from a distribution of weighted number providers. | ||
*** {{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. | ||
**** {{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> | ||
Revision as of 11:12, 18 July 2026
Template:For Template:Exclusive 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 the data component Template:DCLTemplate:Upcoming.
JSON definition
Number providers can be defined in Minecraft:data packs, as part of the directory structure below.
Use
In most uses of number provider, it is used as an Minecraft:NBT object, within a larger structure. This includes all uses in Minecraft:loot tables, Minecraft:predicates, Minecraft:item modifiers, villager trade, and Minecraft:trade sets.
In Java 26.3, number provider Minecraft:registry can be used in the component Template:DCL to define how many layers are added when using Minecraft:composter. In this case, only number providers are accepted, not line 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:NbtTemplate:Nbt: Constant number provider.
Or:
- Template:Nbt: The root tag. Shorthand for a uniform distributionTemplate:Until.
- Template:NbtTemplate:NbtTemplate:Nbt: Number provider. The minimum value.
- Template:NbtTemplate: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.
Constant
A constant value.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:NbtTemplate: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.
Storege
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.
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: