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 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 9]]}}
{{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 22: Line 23:
== Use ==
== 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 table]]s, [[Minecraft:predicate]]s, [[Minecraft:item modifiers]], [[Minecraft:Villager_trade_definition|villager trade]], and [[Minecraft:trade sets]].  
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]].  


In [[Minecraft:Java Edition 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.
{{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.


=== Vanila registries ===
=== Vanila registries ===
Line 151: Line 152:


{{File|directory|cooking}}:  Number providers used in the default component {{DCL|cooking_fuel.burn_time}}, except {{cd|speed_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|desc=: Used in the default components {{cd|cooking_fuel.speed_multiplier}} and {{DCL|brewing_fuel.speed_multiplier}}}}
{{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_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 172:
{{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|desc=: Not used}}
{{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}}}}
{{JSON file|uses_default|20.0|desc=: Used in the default component {{DCL|brewing_fuel.uses}}}}


Line 218: Line 219:


== 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">
<div class="treeview">
* {{nbt|int}}{{nbt|float}}: Constant number provider.
* {{nbt|float}}: Constant number provider.
</div>
</div>


Line 227: Line 228:
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: The root tag. Shorthand for a uniform distribution{{Until|Java 26.3}}.
* {{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|float}}{{nbt|compound|min}}: Number provider. The minimum value.
** {{nbt|int}}{{nbt|float}}{{nbt|compound|max}}: Number provider. The maximum value.
** {{nbt|float}}{{nbt|compound|max}}: Number provider. The maximum value.
</div>
</div>


Line 245: Line 246:
=== Number providers types ===
=== Number providers types ===


{{past|n|copy={{nbt|string}}{{nbt|int}}{{nbt|float}}}}
{{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.
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.
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.
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.


==== Constant ====
==== Constant ====


A constant value.
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|compound}}
** {{nbt|string|type}}: {{cd|constant}}
** {{nbt|string|type}}: {{cd|constant}}
** {{nbt|int}}{{nbt|float|value}}: The exact value.
** {{nbt|float|value}}: The exact value.
</div>
</div>


Line 379: Line 384:
{{info needed section|everything before 26.3, which I don't think is a lot}}
{{info needed section|everything before 26.3, which I don't think is a lot}}
{{HistoryTable
{{HistoryTable
|{{HistoryLine|java}}
|{{HistoryLine||?|Added number providers.}}
|{{HistoryLine|upcoming java}}
|{{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||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}}.}}
}}
}}



Revision as of 11:14, 19 August 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

Template:In development

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

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.

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.

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.

Storage

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:Info needed section Template:HistoryTable

Navigation

Template:Navbox Java Edition technical

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