Weighted
Picks an entry at random and provides its value.
Type ID: kaya:weighted
Note
This meta type can only provide the same kind of value of the field where it was used. (e.g: if the field is a boolean provider, the value providers to specify must be a boolean provider, etc.)
Note
The chance of an entry being picked is determined by dividing the weight of the entry to the sum of all the entries' weights.
$(Chance = Weight_e \div (Weight_1 + Weight_2 + ... + Weight_n))$
Format
| Field | Type | Default | Description |
|---|---|---|---|
entries |
Array of Weighted Entries | The entries to pick a random entry from. |
Weighted Entry
An object that contains a value provider and its weight.
Format
| Field | Type | Default | Description |
|---|---|---|---|
value |
Value Provider | The value to provide. | |
weight |
Integer | The weight of the entry. The value must be either 0 or higher. |
Example
{
"type": "kaya:weighted",
"entries": [
{
"value": {
"type": "kaya:item/attribute",
"attribute": "minecraft:armor",
"item": "used_item"
},
"weight": 5
},
{
"value": {
"type": "kaya:entity/attribute",
"attribute": "minecraft:armor",
"entity": "this"
},
"weight": 5
},
{
"value": {
"type": "kaya:entity/fluid_height",
"fluid_tag": "#minecraft:water",
"entity": "this"
},
"weight": 1
}
]
}
This example is a float provider that has three entries to pick from:
- an entry that has 45% chance $(5 \div 11 = 0.45...)$ of providing the value of the
minecraft:armorattribute from the item stack provided by thekaya:used_itemcontext parameter. - an entry that has a 45% chance $(5 \div 11 = 0.45...)$ of providing the value of the
minecraft:armorattribute from the entity provided by thekaya:this_entitycontext parameter. - an entry that has a 9% chance $(1 \div 11 = 0.09...)$ of providing the height of the water fluid from the entity provided by the
kaya:this_entitycontext parameter.
History
| Minecraft | Mod | Changelog |
| 1.21.5 | 0.1.0 | Added the type. |