Minecraft:Number provider: Difference between revisions
More actions
Sync: new page from Minecraft |
Sync: updated from Minecraft |
||
| (15 intermediate revisions by the same user not shown) | |||
| 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 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]], and | 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}}). | ||
== JSON definition == | == JSON definition == | ||
{{in development|Java|section=1||26.3}} | {{in development|Java|section=1||26.3}} | ||
Number providers can be defined in [[Minecraft:data pack]]s, as part of the directory structure below. | A number provider can be of two types: a {{cd|minecraft:context_float_provider}} or a {{cd|minecraft:context_int_provider}}. Number providers can be defined in [[Minecraft:data pack]]s, as part of the directory structure below, depending on if they are a {{cd|minecraft:context_float_provider}} or a {{cd|minecraft:context_int_provider}}. | ||
<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''}} | ||
****{{File|directory|''' | ****{{File|directory|context_float_provider}} | ||
*****{{File|file|'''{{ph|name}}.json'''}} | |||
****{{File|directory|context_int_provider}} | |||
*****{{File|file|'''{{ph|name}}.json'''}} | *****{{File|file|'''{{ph|name}}.json'''}} | ||
****[[Minecraft:Data pack#Folder_structure|More directories…]] | ****[[Minecraft:Data pack#Folder_structure|More directories…]] | ||
| Line 22: | Line 25: | ||
== 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]]. | |||
{{InUpcoming|Java 26.3}}, number provider [[Minecraft:registry]] can be used in the components {{DCL|compostable}}, {{DCL|brewing}} and {{DCL|cooking_fuel}}. In this case, only number providers and constants are accepted, not inline definitions. | |||
=== | === Vanilla registries === | ||
{{in development|Java|section=1||26.3}} | {{in development|Java|section=1||26.3}} | ||
There are | 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|low|{ | |||
}} | |||
{{ | |||
"type": "minecraft:number_dispatcher", | "type": "minecraft:number_dispatcher", | ||
"cases": [ | "cases": [ | ||
| Line 64: | Line 63: | ||
] | ] | ||
} | } | ||
} | } | ||
}} | }} | ||
{{ | {{JSON file|low_medium|{ | ||
"type": "minecraft:number_dispatcher", | "type": "minecraft:number_dispatcher", | ||
"cases": [ | "cases": [ | ||
| Line 94: | Line 92: | ||
] | ] | ||
} | } | ||
} | } | ||
}} | }} | ||
{{ | {{JSON file|medium|{ | ||
"type": "minecraft:number_dispatcher", | "type": "minecraft:number_dispatcher", | ||
"cases": [ | "cases": [ | ||
| Line 124: | Line 121: | ||
] | ] | ||
} | } | ||
} | } | ||
}} | }} | ||
{{ | {{JSON file|medium_high|{ | ||
"type": "minecraft:number_dispatcher", | "type": "minecraft:number_dispatcher", | ||
"cases": [ | "cases": [ | ||
| Line 154: | Line 150: | ||
] | ] | ||
} | } | ||
} | } | ||
}} | }} | ||
{{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|desc=: Used in the default components {{cd|cooking_fuel.speed_multiplier}}}} | |||
{{JSON file/cooking|time_bamboo|50.0|25.0}} | |||
{{JSON file/cooking|time_blaze|2400.0|1200.0}} | |||
{{JSON file/cooking|boats|1200.0|600.0}} | |||
{{JSON file/cooking|coal|1600.0|8000.0}} | |||
{{JSON file/cooking|time_coal_block|16000.0|8000}} | |||
{{JSON file/cooking|time_dried_kelp_block|4001.0|2000.5}} | |||
{{JSON file/cooking|time_dry_plants|100.0|50.0}} | |||
{{JSON file/cooking|time_hanging_signs|800.0|400.0}} | |||
{{JSON file/cooking|time_lava_bucket|20000.0|10000.0}} | |||
{{JSON file/cooking|time_roots|300.0|150.0}} | |||
{{JSON file/cooking|time_wood_blocks|300.0|150.0}} | |||
{{JSON file/cooking|time_wood_items_extra_small|100.0|50.0}} | |||
{{JSON file/cooking|time_wood_items_large|200.0|100.0}} | |||
{{JSON file/cooking|time_wood_items_small|300.0|150.0}} | |||
{{JSON file/cooking|time_wood_slabs|150.0|75.0}} | |||
{{JSON file/cooking|time_wool|100.0|50.0}} | |||
{{JSON file/cooking|time_wool_carpets|67.0|33.5}} | |||
{{JSON file/cooking|time_wool_slabs|50.0|25.0}} | |||
{{File|directory|brewing}}: | |||
{{JSON file|speed_default|1.0|desc=: Used in the default component {{DCL|brewing_fuel.speed_multiplier}}}} | |||
{{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 == | ||
A a number provider can be an {{nbt|int}} or {{nbt|float}}. They can either be defined as a constant value or as an object. | A a number provider can be an {{nbt|int}} or {{nbt|float}}. They can either be defined as a constant value or as an object. | ||
<div class="treeview"> | |||
* {{nbt|float}}: Constant number provider. | |||
</div> | |||
Or: | |||
<div class="treeview"> | <div class="treeview"> | ||
* {{nbt| | * {{nbt|compound}}: The root tag. Shorthand for a uniform distribution{{Until|Java 26.3}}. | ||
** {{nbt|float}}{{nbt|compound|min}}: Number provider. The minimum value. | |||
** {{nbt|float}}{{nbt|compound|max}}: Number provider. The maximum value. | |||
</div> | </div> | ||
Or: | Or: | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{nbt| | * {{nbt|string}}: Namespaced ID pointing to an element of number provider [[Minecraft:registry]]. See {{Slink||Vanila registries}}.{{Upcoming|JE 26.3}} | ||
</div> | </div> | ||
| Line 176: | Line 242: | ||
<div class="treeview"> | <div class="treeview"> | ||
* {{nbt|compound}}: The root tag. | * {{nbt|compound}}: The root tag. | ||
** {{nbt|string|type}}: The number provider type as a [[Minecraft:resource location]]. It can be {{cd|binomial|constant|enchantment_level|environment_attribute|score|storage|sum|uniform|d=comma}},{{cd|conditional}}{{Upcoming|Java 26.3}}, {{cd|number_dispatcher}}{{Upcoming|Java 26.3}}, and {{cd|weighted_list}}{{Upcoming|Java 26.3}}. | ** {{nbt|string|type}}: The number provider type as a [[Minecraft:resource location]]. <!--It can be {{cd|binomial|constant|enchantment_level|environment_attribute|score|storage|sum|uniform|d=comma}},{{cd|conditional}}{{Upcoming|Java 26.3}}, {{cd|number_dispatcher}}{{Upcoming|Java 26.3}}, and {{cd|weighted_list}}{{Upcoming|Java 26.3}}-->. | ||
** Extra fields of the number provider, described below. | ** Extra fields of the number provider, described below. | ||
</div> | </div> | ||
=== Number providers | === Number providers types === | ||
{{past|n|copy={{nbt|string}}{{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. | |||
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 ({{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 ==== | |||
These can be used in {{cd|minecraft:context_int_provider}} | |||
===== Abs ===== | |||
Returns the absolute value of the input. | |||
<div class="treeview" id="constant" style="margin-block-end: 1em;"> | |||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|abs}} | |||
** {{nbt|compound|input}}: The number to take the absolute value of | |||
===== Avg ===== | |||
The mean of all inputs. Note this rounds towards 0. | |||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|avg}} | |||
** {{nbt|list|inputs}}: The numbers to take the mean of | |||
</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;"> | |||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|binomial}} | |||
** {{nbt|string}}{{nbt|int}}{{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> | |||
===== Conditional ===== | |||
Returns the value from {{nbt|string}}{{nbt|int}}{{nbt|compound|on_true}} if its {{nbt|compound|conditions}} or {{nbt|string}}{{nbt|int}}{{nbt|compound|on_false}} if not. | |||
<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|string}}{{nbt|int}}{{nbt|compound|on_true}}: A number provider, which runs if the {{nbt|compound|conditions}} is fulfilled. | |||
** {{nbt|string}}{{nbt|int}}{{nbt|compound|on_false}}: (Optional. Default {{cd|0}}) A number provider, which runs if the {{nbt|compound|conditions}} is not fulfilled. | |||
</div> | |||
===== 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. | |||
<div class="treeview" id="constant" style="margin-block-end: 1em;"> | <div class="treeview" id="constant" style="margin-block-end: 1em;"> | ||
* | * {{nbt|compound}} | ||
** {{nbt| | ** {{nbt|string|type}}: {{cd|constant}} | ||
** {{nbt|int|value}}: The exact value. | |||
</div> | </div> | ||
<div class="treeview" id=" | ===== Sub ===== | ||
* | Subtracts {{nbt|string}}{{nbt|int}}{{nbt|compound|right}} from {{nbt|string}}{{nbt|int}}{{nbt|compound|left}} and then returns that value | ||
** {{nbt| | |||
** {{nbt| | <div class="treeview" id="sum" style="margin-block-end: 1em;"> | ||
* {{nbt|compound}} | |||
** {{nbt|string|type}}: {{cd|add}} | |||
** {{nbt|string}}{{nbt|int}}{{nbt|compound|left}}: The left of the equation | |||
** {{nbt|string}}{{nbt|int}}{{nbt|compound|right}}: The right of the equation | |||
</div> | </div> | ||
<div class="treeview" id=" | <!--Outdated--> | ||
* | |||
** {{ | ===== 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;"> | |||
* {{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> | ||
===== 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 208: | Line 340: | ||
*** {{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> | ||
===== Storage ===== | |||
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> | ||
===== Add ===== | |||
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|list| | ** {{nbt|string|type}}: {{cd|add}} | ||
** {{nbt|list|inputs}}: List of number providers to sum. | |||
</div> | |||
===== Mul ===== | |||
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|mul}} | |||
** {{nbt|list|inputs}}: 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> | </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> | |||
===== 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| | ** {{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> | ||
<div class="treeview" id="conditional" style="margin-block-end: 1em;"> | <div class="treeview" id="conditional" style="margin-block-end: 1em;"> | ||
* | ** | ||
* | |||
</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> | ||
== History == | |||
{{info needed section|everything before 26.3, which I don't think is a lot}} | |||
{{HistoryTable | |||
|{{HistoryLine|java}} | |||
|{{HistoryLine||?|Added number providers.}} | |||
|{{HistoryLine|upcoming java}} | |||
|{{HistoryLine||26.3|dev=snap4|The {{cd|type}} field always needs to be specified explicitly when using an inline number provider (it was previously defaulting to {{cd|minecraft:uniform}}).|Added vanilla number providers: {{cd|minecraft:cooking/time_bamboo}}, {{cd|minecraft:cooking/time_blaze_rod}}, {{cd|minecraft:cooking/time_boats}}, {{cd|minecraft:cooking/time_coal}}, {{cd|minecraft:cooking/time_coal_block}}, {{cd|minecraft:cooking/time_dried_kelp_block}}, {{cd|minecraft:cooking/time_dry_plants}}, {{cd|minecraft:cooking/time_hanging_signs}}, {{cd|minecraft:cooking/time_lava_bucket}}, {{cd|minecraft:cooking/time_roots}}, {{cd|minecraft:cooking/time_wood_blocks}}, {{cd|minecraft:cooking/time_wood_items_extra_small}}, {{cd|minecraft:cooking/time_wood_items_large}}, {{cd|minecraft:cooking/time_wood_items_small}}, {{cd|minecraft:cooking/time_wood_slabs}}, {{cd|minecraft:cooking/time_wool}}, {{cd|minecraft:cooking/time_wool_carpets}}, {{cd|minecraft:cooking/time_wool_slabs}}, {{cd|minecraft:cooking/speed_default}}, {{cd|minecraft:brewing/speed_default}}, {{cd|minecraft:brewing/uses_default}}.}} | |||
|{{HistoryLine|||dev=snap9|Changed {{cd|minecraft:sum}}: The {{cd|summands}} field was renamed to {{cd|operands}} and now accepts an inline value, a single namespaced ID, a list of namespaced IDs, a list of inline values, or a hash-prefixed tag ID of a {{cd|minecraft:number_provider}} type. Now requires at least one operand. When used in integer mode, integer mode is used for intermediate steps as well.|Added {{cd|minecraft:product}}, {{cd|minecraft:minimum}}, {{cd|minecraft:maximum}} and {{cd|minecraft:average}}.}} | |||
|{{HistoryLine|||dev=Pre-Release 1|Number provider types and values have been split into separate registries for integer and float calculations. | |||
|Renamed the following number providers: | |||
* {{cd|sum}} to {{cd|add}} | |||
* {{cd|product}} to {{cd|mul}} | |||
* {{cd|minimum}} to {{cd|min}} | |||
* {{cd|maximum}} to {{cd|max}} | |||
* {{cd|average}} to {{cd|avg}} | |||
}} | |||
}} | |||
== Navigation == | == Navigation == | ||
{{Navbox Java Edition technical|datapack}} | {{Navbox Java Edition technical|datapack}} | ||
[[Minecraft:de:Zahlenanbieter]] | |||
[[Minecraft:fr:Fournisseur de nombre]] | |||
[[Minecraft:ja:ナンバープロバイダー]] | |||
[[Minecraft:zh:数值提供器]] | |||
Latest revision as of 11:16, 6 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
A number provider can be of two types: a Template:Cd or a Template:Cd. Number providers can be defined in Minecraft:data packs, as part of the directory structure below, depending on if they are a Template:Cd or a Template:Cd.
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.
Vanilla 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. .
- 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.
Integer Providers
These can be used in Template:Cd
Abs
Returns the absolute value of the input.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: The number to take the absolute value of
Avg
The mean of all inputs. Note this rounds towards 0.
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: The numbers to take the mean of
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:NbtTemplate:NbtTemplate:Nbt: Number provider. The amount of trials.
- Template:PastTemplate:Nbt: Number provider. The probability of success on an individual trial.
Conditional
Returns the value from Template:NbtTemplate:NbtTemplate:Nbt if its Template:Nbt or Template:NbtTemplate:NbtTemplate:Nbt if not.
- Template:Nbt
- Template:Nbt: Template:CdTemplate:Upcoming
- Template:Nbt: A Minecraft:predicate to test which value will be returned.
- Template:NbtTemplate:NbtTemplate:Nbt: A number provider, which runs if the Template:Nbt is fulfilled.
- Template:NbtTemplate:NbtTemplate:Nbt: (Optional. Default Template:Cd) A number provider, which runs if the Template:Nbt is not fulfilled.
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.
Sub
Subtracts Template:NbtTemplate:NbtTemplate:Nbt from Template:NbtTemplate:NbtTemplate:Nbt and then returns that value
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:NbtTemplate:NbtTemplate:Nbt: The left of the equation
- Template:NbtTemplate:NbtTemplate:Nbt: The right of the equation
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).
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.
Add
The sum of multiple value providers
- Template:Nbt
- Template:Nbt: Template:Cd
- Template:Nbt: List of number providers to sum.
Mul
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.
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:数值提供器