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
Line 22: Line 22:
== Use ==
== Use ==


In most uses of number provider, it is used as an [[Minecraft:NBT]] object, within a larger structure, and cannot be used as a registry . 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 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}} default:
{{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}} default:
{{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 &times; 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 types ===
=== Number providers types ===


The possible values for {{nbt|string|type}} and associated extra contents:
{{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;">
* '''constant''' &mdash; A constant value.
* {{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}} &le; {{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;">
* '''uniform''' &mdash; A random number following a uniform distribution between two values (inclusive).
* {{nbt|compound}}
** {{nbt|int}}{{nbt|float}}{{nbt|compound|min}}: Number provider. The minimum value.
** {{nbt|string|type}}: {{cd|uniform}}
** {{nbt|int}}{{nbt|float}}{{nbt|compound|max}}: Number provider. The maximum value.
** {{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;">
* '''binomial''' &mdash; A random number following a [[Minecraft:wikipedia:Binomial distribution|binomial distribution]].
* {{nbt|compound}}
** {{nbt|int}}{{nbt|compound|n}}: Number provider. The amount of trials.
** {{nbt|string|type}}: {{cd|binomial}}
** {{nbt|float}}{{nbt|compound|p}}: Number provider. The probability of success on an individual trial.
** {{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;">
* '''score''' &mdash; To query and use a scoreboard value.
* {{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;">
* '''storage''' &mdash; A value in command storage.
* {{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;">
* '''enchantment_level''' &mdash; A value dependent on the level of the [[#Loot context types|loot context]] enchantment
* {{nbt|compound}}
** {{nbt|string|amount}}: [[Minecraft:level-based value]] calculating the value based on the enchantment.
** {{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;">
* '''sum''' &mdash; The sum of multiple value providers
* {{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;">
* '''environment_attribute''' &mdash; Fetches and provides the value of an environment attribute (that can be represented as a number).
* {{nbt|compound}}
This provider requires a context with an origin position set as long as the environment attribute can vary positionally.
** {{nbt|string|type}}: {{cd|environment_attribute}}
** {{nbt|string|attribute}}: An [[Minecraft:environment attribute]] ID to fetch.
** {{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;">
* '''number_dispatcher'''{{Upcoming|Java 26.3}} &mdash; Returns the first case which fulfills its condition or the default if none do.
* {{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.
**** {{nbt|int}}{{nbt|float}}{{nbt|compound|number_provider}}: A number provider, which is executed if the {{nbt|compound|condition}} is fulfilled.
**** {{past|n}}{{nbt|compound|number_provider}}: A number provider, which is executed if the {{nbt|compound|condition}} is fulfilled.
** {{nbt|int}}{{nbt|float}}{{nbt|compound|default}}: (Optional. Default {{cd|0.0}}) A number provider, which runs if none of the conditions in {{nbt|list|cases}} 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;">
* '''conditional'''{{Upcoming|Java 26.3}} &mdash; Returns the value from {{nbt|int}}{{nbt|float}}{{nbt|compound|on_true}} if its {{nbt|compound|conditions}} or {{nbt|int}}{{nbt|float}}{{nbt|compound|on_false}} if not:
* {{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.   
** {{nbt|int}}{{nbt|float}}{{nbt|compound|on_true}}: A number provider, which runs if the {{nbt|compound|conditions}} is fulfilled.
** {{past|n}}{{nbt|compound|on_true}}: A number provider, which runs if the {{nbt|compound|conditions}} is fulfilled.
** {{nbt|int}}{{nbt|float}}{{nbt|compound|on_false}}: (Optional. Default {{cd|0.0}}) A number provider,  which runs if the {{nbt|compound|conditions}} is not 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;">
* '''weighted_list'''{{Upcoming|Java 26.3}} &mdash; Returns a value from a distribution of weighted number providers.
* {{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:
**** {{nbt|int}}{{nbt|float}}{{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>

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

Template:In development

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

Template:In development

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.

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.

Constant

A constant 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:CdTemplate:Cd, the provided number is Template:Cd.

Binomial

A random number following a binomial distribution. The returned float has the same value as the int.

Score

To query and use a Minecraft:scoreboard value. Return Template:Cd if the scoreboard cannot be calculated.

Storege

A value in Minecraft:command storage.

Enchantment level

A value dependent on the level of the Minecraft:loot context enchantment.

Sum

The sum of multiple value providers

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.

Number dispatcher

Returns the first case which fulfills its condition or the default if none do.

Conditional

Returns the value from Template:PastTemplate:Nbt if its Template:Nbt or Template:PastTemplate:Nbt if not.

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].

History

Template:Section needed

Navigation

Template:Navbox Java Edition technical