API reference / @jsprismarine/enchantments / EnchantmentRegistry
Class: EnchantmentRegistry
Defined in: enchantments/src/registry.ts:99
Every enchantment a pack stack loaded, plus the tags that decide where each one shows up, plus the machinery that runs their effects.
The registry owns the four pieces an enchantment is made of that are not the loot tables: the definition, the tags, the compatibility rules, and the 31 effect components. Callers that need the fifth piece, the enchantment level a loot function reads, go through createEnchantmentView.
Constructors
Constructor
new EnchantmentRegistry(
options):EnchantmentRegistry
Defined in: enchantments/src/registry.ts:108
Parameters
options
Returns
EnchantmentRegistry
Properties
items
readonlyitems:ItemView
Defined in: enchantments/src/registry.ts:106
Item questions the registry cannot answer from a stack's components.
Accessors
ids
Get Signature
get ids(): readonly
string[]
Defined in: enchantments/src/registry.ts:120
Every enchantment id the registry holds, in load order.
Returns
readonly string[]
Methods
applicableTo()
applicableTo(
stack): readonlystring[]
Defined in: enchantments/src/registry.ts:194
Every registered enchantment a stack supports, in load order.
Parameters
stack
Returns
readonly string[]
areCompatible()
areCompatible(
first,second):boolean
Defined in: enchantments/src/registry.ts:171
Whether two enchantments may sit on one item. Java's rule, verbatim: a different enchantment that neither side's exclusive set names.
Parameters
first
string
second
string
Returns
boolean
exclusiveWith()
exclusiveWith(
id):ReadonlySet<string>
Defined in: enchantments/src/registry.ts:149
Every enchantment that cannot share an item with this one.
Parameters
id
string
Returns
ReadonlySet<string>
get()
get(
id):EnchantmentDefinition|undefined
Defined in: enchantments/src/registry.ts:125
Looks one enchantment up by namespaced or bare id.
Parameters
id
string
Returns
EnchantmentDefinition | undefined
hasTag()
hasTag(
id,tag):boolean
Defined in: enchantments/src/registry.ts:144
Whether an enchantment is in a tag.
Parameters
id
string
tag
string
Returns
boolean
isPrimary()
isPrimary(
stack,id):boolean
Defined in: enchantments/src/registry.ts:187
Whether the enchanting table may offer an enchantment for a stack. An enchantment with no primary_items offers for every supported item.
Parameters
stack
id
string
Returns
boolean
markerApplies()
markerApplies(
component,request):boolean
Defined in: enchantments/src/registry.ts:272
Whether any enchantment declares a marker component, which is how damage_immunity, prevent_armor_change and prevent_equipment_drop work. A conditional marker counts only when one of its entries matches.
Parameters
component
"hit_block" | "damage" | "attributes" | "damage_protection" | "damage_immunity" | "smash_damage_per_fallen_block" | "knockback" | "armor_effectiveness" | "post_attack" | "post_piercing_attack" | "item_damage" | "equipment_drops" | "location_changed" | "tick" | "ammo_use" | "projectile_piercing" | "projectile_spawned" | "projectile_spread" | "projectile_count" | "trident_return_acceleration" | "fishing_time_reduction" | "fishing_luck_bonus" | "block_experience" | "mob_experience" | "repair_with_xp" | "crossbow_charge_time" | "crossbow_charging_sounds" | "trident_sound" | "prevent_equipment_drop" | "prevent_armor_change" | "trident_spin_attack_strength"
request
Returns
boolean
maxLevelOf()
maxLevelOf(
id):number|undefined
Defined in: enchantments/src/registry.ts:130
The highest level an enchantment reaches, or undefined when it is not registered.
Parameters
id
string
Returns
number | undefined
membersOf()
membersOf(
tag):ReadonlySet<string>
Defined in: enchantments/src/registry.ts:139
Expands a tag to its enchantment ids, following tag values that name other tags. A cycle stops at the tag that closes it rather than recursing.
Parameters
tag
string
Returns
ReadonlySet<string>
modifyValue()
modifyValue(
component,base,request):number
Defined in: enchantments/src/registry.ts:210
Runs every value effect of one component over a starting value.
The component decides the loot context key set its conditions evaluate against, so the caller passes the parameters of the moment and nothing else. Enchantments apply in the order request.enchantments iterates, and effects within one enchantment in file order, which is what Java does and what makes add after multiply differ from the reverse.
Parameters
component
"hit_block" | "damage" | "attributes" | "damage_protection" | "damage_immunity" | "smash_damage_per_fallen_block" | "knockback" | "armor_effectiveness" | "post_attack" | "post_piercing_attack" | "item_damage" | "equipment_drops" | "location_changed" | "tick" | "ammo_use" | "projectile_piercing" | "projectile_spawned" | "projectile_spread" | "projectile_count" | "trident_return_acceleration" | "fishing_time_reduction" | "fishing_luck_bonus" | "block_experience" | "mob_experience" | "repair_with_xp" | "crossbow_charge_time" | "crossbow_charging_sounds" | "trident_sound" | "prevent_equipment_drop" | "prevent_armor_change" | "trident_spin_attack_strength"
base
number
The vanilla value before any enchantment touches it.
request
Returns
number
The value after every matching effect, or base when none match.
runEffects()
runEffects(
component,request,sink):void
Defined in: enchantments/src/registry.ts:236
Resolves every entity, location or attribute effect of one component and hands each one to the sink. Nothing in the world changes here; the sink decides what a resolved effect means.
Parameters
component
"hit_block" | "damage" | "attributes" | "damage_protection" | "damage_immunity" | "smash_damage_per_fallen_block" | "knockback" | "armor_effectiveness" | "post_attack" | "post_piercing_attack" | "item_damage" | "equipment_drops" | "location_changed" | "tick" | "ammo_use" | "projectile_piercing" | "projectile_spawned" | "projectile_spread" | "projectile_count" | "trident_return_acceleration" | "fishing_time_reduction" | "fishing_luck_bonus" | "block_experience" | "mob_experience" | "repair_with_xp" | "crossbow_charge_time" | "crossbow_charging_sounds" | "trident_sound" | "prevent_equipment_drop" | "prevent_armor_change" | "trident_spin_attack_strength"
request
sink
Returns
void
soundAt()
soundAt(
component,id,level):string|ChargingSounds|undefined
Defined in: enchantments/src/registry.ts:293
The sound bank one enchantment declares for a level, which is a {start, mid, end} record for crossbow_charging_sounds and a sound id for trident_sound. A level past the end of the list reuses the last entry, as Java's clamp does.
Parameters
component
"hit_block" | "damage" | "attributes" | "damage_protection" | "damage_immunity" | "smash_damage_per_fallen_block" | "knockback" | "armor_effectiveness" | "post_attack" | "post_piercing_attack" | "item_damage" | "equipment_drops" | "location_changed" | "tick" | "ammo_use" | "projectile_piercing" | "projectile_spawned" | "projectile_spread" | "projectile_count" | "trident_return_acceleration" | "fishing_time_reduction" | "fishing_luck_bonus" | "block_experience" | "mob_experience" | "repair_with_xp" | "crossbow_charge_time" | "crossbow_charging_sounds" | "trident_sound" | "prevent_equipment_drop" | "prevent_armor_change" | "trident_spin_attack_strength"
id
string
level
number
Returns
string | ChargingSounds | undefined
supports()
supports(
stack,id):boolean
Defined in: enchantments/src/registry.ts:178
Whether an enchantment may go on a stack at all.
Parameters
stack
id
string
Returns
boolean