API reference / @jsprismarine/enchantments
@jsprismarine/enchantments
The Java Edition enchantment system: the 43 vanilla definitions, the 31 effect component types, the enchanting table draw and the anvil. It parses Mojang's JSON once into closures and runs them against a PredicateContext from @jsprismarine/predicates, which supplies the conditions, the number providers and the level based values this package composes.
Every rule here was read out of the Java 26.3 server jar, not off a wiki page. The enchanting table and the anvil are ported from EnchantmentHelper, EnchantmentMenu and AnvilMenu; the tests check them against values a Java program produced from the real java.util.Random.
Install
pnpm add @jsprismarine/enchantmentsUsing it
import { EnchantmentRegistry, enchantingOffers, parseEnchantment } from '@jsprismarine/enchantments';
const { value: sharpness, diagnostics } = parseEnchantment('minecraft:sharpness', json);
const registry = new EnchantmentRegistry({
definitions: [sharpness],
tags: new Map([['minecraft:in_enchanting_table', ['minecraft:sharpness']]]),
items: { tagsOf: (item) => itemTags[item] ?? [] }
});
registry.modifyValue('damage', baseDamage, { enchantments: stackLevels, context: { parameters } });
registry.runEffects('post_attack', { enchantments: stackLevels, enchanted: 'victim', context }, apply);
enchantingOffers(registry, stack, { seed: player.enchantmentSeed, bookshelfPower: 15 });Parsing never throws. A malformed field reports into a DiagnosticCollector and takes a safe default, so one broken file does not take the pack down with it.
The model
EnchantmentDefinition carries every field of the 26.3 format. All 43 vanilla files have anvil_cost, description, max_cost, max_level, min_cost, slots, supported_items and weight; 42 have effects, 18 have exclusive_set and 5 have primary_items.
min_cost and max_cost both take the base plus per level form, which costAt evaluates as base + perLevelAboveFirst * (level - 1). A bare number also parses, as a cost with no per level part. slots names one or more of the 11 equipment slot groups. Java hardcodes the lowest level of every enchantment to 1, which this package exports as MIN_ENCHANTMENT_LEVEL.
supported_items, primary_items and exclusive_set parse through the predicates package's resolveMembers, so each keeps both the ids it names directly and the tags it reaches through.
Effect coverage
| Registry | 26.3 registers | This package | Vanilla's 43 files use |
|---|---|---|---|
enchantment_effect_component_type | 31 | 31 | 30 |
enchantment_value_effect_type | 6 | 6 | 4 |
enchantment_level_based_value_type | 6 plus the bare number | 7 | 5 |
enchantment_entity_effect_type | 15 | 15 | 12 |
enchantment_location_based_effect_type | 16 | 16 | 13 |
The last column is measured by the corpus test over the real files, not copied from a note. Nothing declares mob_experience. exponential and all_of never appear as value effects, though all_of is common as a world effect. exponent never appears as a level based value, and a constant is always written as a bare number rather than as a type. replace_block, run_function and set_block_properties never appear at all.
One earlier count needs correcting: docs/research/java-registries-and-components.md says vanilla uses five of the six value effect types. It uses four. The note counted all_of, which only ever appears in the entity and location grammar.
Each component declares the loot context key set its requirements evaluate against, read from EnchantmentEffectComponents in the jar: nine use enchanted_damage, eight enchanted_entity, five enchanted_item, one enchanted_location, one hit_block, and seven carry no conditions at all.
Running them
modifyValue folds a component's value effects over a starting number. The component picks the context key set, so a caller passes the parameters of the moment and this package fills in enchantment_level per enchantment. Enchantments apply in the order the enchantment map iterates and effects within one enchantment in file order, which is what Java does and what makes add after multiply differ from the reverse.
runEffects resolves a component's entity, location and attribute effects and hands each one to an EffectSink. Every level based value and number provider is already resolved against the level and the context; identifiers, block states, block predicates and particle options stay as the parsed JSON they came from, because those registries live in the host. Durations are in seconds, the unit the Java effects carry before they multiply by 20. Nothing in the world changes here. Summoning a lightning bolt, replacing a disk of ice and playing a sound all belong to the server, so the sink gets a description and decides what to do with it.
markerApplies answers the three components that carry no body: damage_immunity is a condition with nothing attached, prevent_armor_change and prevent_equipment_drop are presence alone. soundAt answers the two sound banks, clamping a level past the end of the list to the last entry.
The enchanting table
enchantmentCost(random, slot, bookshelfPower) is Java's formula verbatim. Bookshelves above 15 change nothing. The base is nextInt(8) + 1 + power / 2 + nextInt(power + 1); the top row costs a third of it with a floor of one, the middle row two thirds plus one, and the bottom row the larger of the base and twice the power. A row whose cost is below its own index shows nothing.
selectEnchantments widens the row cost by the item's enchantability, nudges the result by up to 15 percent either way, picks one candidate by weight, then keeps halving the level and picking again while nextInt(50) stays at or below it, dropping candidates that conflict with the last pick. availableEnchantments offers at most one level per enchantment: it walks a candidate's levels downward and keeps the first whose cost window contains the draw.
enchantingOffers drives all three rows from one generator, seeded with the player's enchantment seed for the costs and reseeded with seed + row for each row's draw, which is why the rows stay put until the player enchants something. A book drops one pick at random when the draw produced more than one, which is Java's way of making book offers less generous than they look.
Two enchantments share an item when neither one's exclusive set names the other and they are not the same enchantment. That is the only compatibility rule; it runs during the draw, in the anvil, and through areCompatible for anything else that needs it.
The anvil
combineInAnvil is AnvilMenu.createResult, step for step.
A repair material restores a quarter of the item's durability and costs one level, repeating until the item is whole or the material runs out. Combining two of the same item adds the sacrifice's remaining durability plus 12 percent of maximum, for two levels. Merging enchantments raises two equal levels by one and takes the larger of two unequal ones, capped at the enchantment's max_level, and charges anvil_cost per resulting level, halved with a floor of one when the enchantments come from a book. Each enchantment the item already carries that conflicts with an incoming one costs a level and blocks that one; a combination where everything is blocked produces nothing. Renaming costs one level.
The prior work penalty is the minecraft:repair_cost component. The anvil adds both inputs' penalty to the cost and writes back max(base, addition) * 2 + 1, which is what makes the fourth or fifth combination of one item unaffordable. A pure rename is the exception: it does not raise the penalty and it caps at 39 levels instead of being refused. Everything else at 40 levels or more produces nothing unless the player has unlimited materials.
Nothing here consumes items or experience. The caller decides whether the player can pay.
The loot interaction
Two enchantments do nothing through their own files. fortune.json has no effects key at all, and looting.json only adjusts equipment drop chance. Their drop bonuses live in the block loot tables, which name minecraft:fortune directly in 32 apply_bonus calls and 35 table_bonus conditions. Those loot functions already own the bonus arithmetic. All they need is the level on the tool.
createEnchantmentView(registry) returns the EnchantmentView the predicates package declares, so apply_bonus, table_bonus, enchant_randomly and enchant_with_levels read levels, maximum levels, the applicable set and the table draw through one object. This package does not repeat the ore_drops, uniform_bonus_count or binomial_with_bonus_count formulas; the tests check that feeding the view into a real apply_bonus produces the vanilla counts.
Fifteen more tags under tags/enchantment/ carry behavior that lives neither in the file nor in the loot tables: curse, double_trade_price, in_enchanting_table, non_treasure, on_mob_spawn_equipment, on_random_loot, on_traded_equipment, prevents_bee_spawns_when_mining, prevents_decorated_pot_shattering, prevents_ice_melting, prevents_infested_spawns, smelts_loot, tooltip_order, tradeable and treasure. The registry expands them, including tags that name other tags, which in_enchanting_table does.
Bedrock projection limits
projectToBedrock maps each enchantment through an injected mapper. Adapt javaIdentifierToBedrock('enchantment', id) from @jsprismarine/mapping to the EnchantmentIdentifierMapper shape; this package stays unaware that two editions exist.
42 of Java's 43 enchantments have a Bedrock id. sweeping_edge does not, and neither does any datapack enchantment, because a Bedrock client only knows the enchantments its own registry lists. There is no packet that teaches it a new one.
What this costs is worth stating plainly. The mechanics still run: every effect component resolves on the server and reaches the world through an EffectSink, so a server-side enchantment deals its damage and spawns its particles exactly as a mapped one does. What the client loses is the display and the preview. projectToBedrock returns a lore line for each unmapped enchantment and sets forceGlint when nothing on the stack reached the client, because otherwise an enchanted item would look plain. The player gets no tooltip ordering, no enchantment-specific tooltip color, and nothing in the creative or anvil interfaces that recognizes the enchantment. The client's own anvil and enchanting previews are wrong whenever a server-side enchantment is involved, so the server has to send the result rather than let the client compute it.
Injectable seams
All of these are optional, and a member a host leaves out makes the operation that needs it report or fall back rather than throw.
ItemViewon the registry answers item tags, enchantability, durability, damage, the repair material and the display name. It merges overcomponentItemView, which readsminecraft:enchantable,minecraft:max_damage,minecraft:damageandminecraft:repairableoff the stack, so a host overrides only what it knows better. WithouttagsOf, a tag-named item set matches nothing.EffectSinkonrunEffectsreceives every resolved world change. There is no default: a caller that wants effects to happen writes one.EnchantmentIdentifierMapperonprojectToBedrockis the only place this package can learn a Bedrock id.RandomSourcefrom the predicates package drives every draw.javaRandomreproducesjava.util.Randomdraw for draw, which is what makes an enchanting offer match vanilla for a given seed;scriptedRandommakes a test exact.ReferenceResolveron the parse options expands the item and enchantment tags a file names. Without it the tag names survive unexpanded and theItemViewanswers membership instead.
Corpus test
corpus.test.ts parses all 43 real enchantment files and all 22 enchantment tags out of the cached server jar, asserts no parse errors, and measures the coverage table above. It reports one warning, which comes from the predicates package rather than this one: lunge.json reaches for the food member of the player sub-predicate, which that package does not implement. The test needs the cache that pnpm --filter @jsprismarine/bedrock-data run fetch:sources populates, so it only runs with JSP_VANILLA_DATAPACK set and CI without the cache skips it.
The ungated tests run against twelve of the 43 files, copied verbatim into test/fixtures.ts. The vanilla data is a cached input this repository regenerates rather than a snapshot it vendors, so only the subset the behavior tests need lives in the package.
License
MIT
Classes
Interfaces
AnvilInput
Defined in: enchantments/src/anvil.ts:34
The two anvil slots and the name the player typed.
Properties
addition?
readonlyoptionaladdition?:ItemStack
Defined in: enchantments/src/anvil.ts:38
Right slot: a repair material, a second copy of the item, or an enchanted book.
base
readonlybase:ItemStack
Defined in: enchantments/src/anvil.ts:36
Left slot: the item being worked on.
name?
readonlyoptionalname?:string
Defined in: enchantments/src/anvil.ts:40
The name the player typed, or undefined when the field was not touched.
AnvilOptions
Defined in: enchantments/src/anvil.ts:56
What the anvil needs besides the registry.
Properties
items?
readonlyoptionalitems?:ItemStackOps
Defined in: enchantments/src/anvil.ts:58
How result stacks are built; defaults to the plain record operations.
unlimitedMaterials?
readonlyoptionalunlimitedMaterials?:boolean
Defined in: enchantments/src/anvil.ts:63
A creative player ignores the level ceiling and may apply an enchantment the item does not support.
AnvilResult
Defined in: enchantments/src/anvil.ts:44
What the anvil would produce, and what it would charge.
Properties
cost
readonlycost:number
Defined in: enchantments/src/anvil.ts:48
Experience levels the player pays.
materialCost
readonlymaterialCost:number
Defined in: enchantments/src/anvil.ts:50
How many of the right stack a material repair consumes.
onlyRenaming
readonlyonlyRenaming:boolean
Defined in: enchantments/src/anvil.ts:52
Whether the only change is the name, which is what lifts the cost ceiling to 39.
output
readonlyoutput:ItemStack|undefined
Defined in: enchantments/src/anvil.ts:46
The result stack, or undefined when the anvil rejects the combination.
BedrockEnchantmentProjection
Defined in: enchantments/src/bedrock.ts:19
One enchantment on a stack, seen from the client's side.
Properties
bedrock
readonlybedrock:string|undefined
Defined in: enchantments/src/bedrock.ts:24
The Bedrock id, or undefined when the client cannot be told about this enchantment.
enchantment
readonlyenchantment:string
Defined in: enchantments/src/bedrock.ts:21
Namespaced Java enchantment id.
level
readonlylevel:number
Defined in: enchantments/src/bedrock.ts:22
lore
readonlylore:string|undefined
Defined in: enchantments/src/bedrock.ts:26
The lore line to send instead, set only when bedrock is undefined.
BedrockProjectionOptions
Defined in: enchantments/src/bedrock.ts:55
How a projection names an enchantment the client cannot represent.
Properties
lore?
readonlyoptionallore?: (enchantment,id,level) =>string
Defined in: enchantments/src/bedrock.ts:61
Builds the lore line for an enchantment with no Bedrock id. The default writes the enchantment id and its level, because resolving description needs a translation table this package does not have.
Parameters
enchantment
EnchantmentDefinition | undefined
id
string
level
number
Returns
string
BedrockProjectionResult
Defined in: enchantments/src/bedrock.ts:30
What to send a Bedrock client for one stack's enchantments.
Properties
entries
readonlyentries: readonlyBedrockEnchantmentProjection[]
Defined in: enchantments/src/bedrock.ts:31
forceGlint
readonlyforceGlint:boolean
Defined in: enchantments/src/bedrock.ts:37
Whether the server has to force the enchanted glint. A Bedrock client draws the glint from the enchantments it was told about, so a stack whose enchantments are all server-side would otherwise look plain.
ChargingSounds
Defined in: enchantments/src/components.ts:133
One level's worth of crossbow charging sounds.
Properties
end
readonlyend:string|undefined
Defined in: enchantments/src/components.ts:136
mid
readonlymid:string|undefined
Defined in: enchantments/src/components.ts:135
start
readonlystart:string|undefined
Defined in: enchantments/src/components.ts:134
ConditionalEffectEntry
Defined in: enchantments/src/components.ts:118
One entry of an entity or location effect component.
Properties
affected
readonlyaffected:"attacker"|"damaging_entity"|"victim"|undefined
Defined in: enchantments/src/components.ts:124
Which entity the effect acts on, which only post_attack names.
effect
readonlyeffect:CompiledEffect
Defined in: enchantments/src/components.ts:119
enchanted
readonlyenchanted:"attacker"|"damaging_entity"|"victim"|undefined
Defined in: enchantments/src/components.ts:122
Whose copy of the enchantment fires, which only post_attack names.
requirements
readonlyrequirements:Predicate|undefined
Defined in: enchantments/src/components.ts:120
ConditionalMarkerEntry
Defined in: enchantments/src/components.ts:128
One entry of damage_immunity, which carries a condition and nothing else.
Properties
requirements
readonlyrequirements:Predicate|undefined
Defined in: enchantments/src/components.ts:129
ConditionalValueEntry
Defined in: enchantments/src/components.ts:109
One entry of a value effect component: the arithmetic and the condition that gates it.
Properties
effect
readonlyeffect:ValueEffect
Defined in: enchantments/src/components.ts:110
enchanted
readonlyenchanted:"attacker"|"damaging_entity"|"victim"|undefined
Defined in: enchantments/src/components.ts:114
Whose copy of the enchantment fires, which only equipment_drops names.
requirements
readonlyrequirements:Predicate|undefined
Defined in: enchantments/src/components.ts:112
Undefined when the entry always applies.
EffectComponentDeclaration
Defined in: enchantments/src/components.ts:40
What one entry of a component needs to know before it can be parsed or run.
Properties
kind
readonlykind:EffectComponentKind
Defined in: enchantments/src/components.ts:41
parameterSet?
readonlyoptionalparameterSet?:"chest"|"empty"|"generic"|"command"|"command_slot_source"|"command_compute_default"|"command_compute_position"|"command_compute_entity"|"selector"|"villager_trade"|"fishing"|"entity"|"equipment"|"archaeology"|"gift"|"barter"|"vault"|"advancement_reward"|"advancement_entity"|"advancement_location"|"block_use"|"block"|"shearing"|"entity_interact"|"block_interact"|"container_process"|"enchanted_damage"|"enchanted_item"|"enchanted_location"|"enchanted_entity"|"hit_block"
Defined in: enchantments/src/components.ts:46
Loot context key set the requirements of each entry evaluate against. A component whose entries carry no conditions has none.
EffectRequest
Defined in: enchantments/src/registry.ts:57
One call to the effect machinery: whose enchantments, and against what.
Properties
context?
readonlyoptionalcontext?:PredicateContextOptions
Defined in: enchantments/src/registry.ts:65
What the requirements predicates evaluate against. The component decides the loot context key set and this package fills in enchantment_level, so a caller supplies only the parameters.
enchanted?
readonlyoptionalenchanted?:"attacker"|"damaging_entity"|"victim"
Defined in: enchantments/src/registry.ts:71
Which side of a fight owns the enchanted item. Entries of post_attack and equipment_drops that name a different enchanted target are skipped.
enchantments
readonlyenchantments:ReadonlyMap<string,number>
Defined in: enchantments/src/registry.ts:59
Enchantment id to level, which enchantmentsOf reads off a stack.
EffectRun
Defined in: enchantments/src/registry.ts:39
What one effect run tells the host to do.
Properties
affected
readonlyaffected:"attacker"|"damaging_entity"|"victim"|undefined
Defined in: enchantments/src/registry.ts:46
Which entity the effect acts on. Only post_attack names one.
component
readonlycomponent:"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"
Defined in: enchantments/src/registry.ts:43
effect
readonlyeffect:ResolvedEffect
Defined in: enchantments/src/registry.ts:44
enchantment
readonlyenchantment:string
Defined in: enchantments/src/registry.ts:41
Namespaced id of the enchantment the effect came from.
level
readonlylevel:number
Defined in: enchantments/src/registry.ts:42
EnchantingOffer
Defined in: enchantments/src/table.ts:15
One of the three rows an enchanting table shows.
Properties
clue
readonlyclue:EnchantmentInstance|undefined
Defined in: enchantments/src/table.ts:19
The single enchantment the client shows as a hint, or undefined when the row is empty.
cost
readonlycost:number
Defined in: enchantments/src/table.ts:17
Experience levels the row costs, or 0 when the row is empty.
EnchantingTableOptions
Defined in: enchantments/src/table.ts:154
What an enchanting table needs to know before it can show a stack's rows.
Properties
bookshelfPower
readonlybookshelfPower:number
Defined in: enchantments/src/table.ts:158
Bookshelves around the table.
candidates?
readonlyoptionalcandidates?: readonlystring[]
Defined in: enchantments/src/table.ts:160
Enchantments the table may draw, defaulting to the in_enchanting_table tag.
seed
readonlyseed:number
Defined in: enchantments/src/table.ts:156
The player's enchantment seed, which vanilla rerolls after every use.
EnchantmentDefinition
Defined in: enchantments/src/definition.ts:55
One enchantment as a datapack writes it. Every field of the 26.3 format is here; description stays as the parsed chat component because the text format belongs to another package.
Properties
anvilCost
readonlyanvilCost:number
Defined in: enchantments/src/definition.ts:69
Levels the anvil charges per level of this enchantment.
description
readonlydescription:unknown
Defined in: enchantments/src/definition.ts:58
effects
readonlyeffects:EnchantmentEffects
Defined in: enchantments/src/definition.ts:73
exclusiveSet
readonlyexclusiveSet:MemberSet
Defined in: enchantments/src/definition.ts:72
Enchantments that cannot share an item with this one.
id
readonlyid:string
Defined in: enchantments/src/definition.ts:57
Namespaced id, taken from the file path rather than the file body.
maxCost
readonlymaxCost:LevelCost
Defined in: enchantments/src/definition.ts:67
maxLevel
readonlymaxLevel:number
Defined in: enchantments/src/definition.ts:65
minCost
readonlyminCost:LevelCost
Defined in: enchantments/src/definition.ts:66
primaryItems
readonlyprimaryItems:MemberSet|undefined
Defined in: enchantments/src/definition.ts:62
Items the enchanting table may offer it for; absent means every supported item.
slots
readonlyslots: readonly ("mainhand"|"offhand"|"head"|"chest"|"legs"|"feet"|"body"|"saddle"|"any"|"hand"|"armor")[]
Defined in: enchantments/src/definition.ts:70
supportedItems
readonlysupportedItems:MemberSet
Defined in: enchantments/src/definition.ts:60
Items the enchantment may sit on at all, as ids and unexpanded item tags.
weight
readonlyweight:number
Defined in: enchantments/src/definition.ts:64
Relative chance in the enchanting table draw.
EnchantmentInstance
Defined in: enchantments/src/table.ts:8
One enchantment at one level, which is what a draw returns.
Properties
enchantment
readonlyenchantment:string
Defined in: enchantments/src/table.ts:10
Namespaced enchantment id.
level
readonlylevel:number
Defined in: enchantments/src/table.ts:11
EnchantmentRegistryOptions
Defined in: enchantments/src/registry.ts:75
Everything the registry is built from.
Properties
definitions
readonlydefinitions:Iterable<EnchantmentDefinition>
Defined in: enchantments/src/registry.ts:76
items?
readonlyoptionalitems?:ItemView
Defined in: enchantments/src/registry.ts:87
Item answers the host can give, merged over componentItemView so an unimplemented member still falls back to reading the component.
tags?
readonlyoptionaltags?:ReadonlyMap<string, readonlystring[]>
Defined in: enchantments/src/registry.ts:82
Tag id to its raw values, keyed without the leading #. A value may name another tag with a leading #, which vanilla's in_enchanting_table does.
EnchantmentViewOptions
Defined in: enchantments/src/lootview.ts:11
What the loot seam needs beyond the registry itself.
Properties
random?
readonlyoptionalrandom?:RandomSource
Defined in: enchantments/src/lootview.ts:17
Randomness for the enchanting table draw enchant_with_levels runs. Leave it out and that one member is omitted, so the loot function reports instead of drawing from an unseeded generator.
randomLootTag?
readonlyoptionalrandomLootTag?:string
Defined in: enchantments/src/lootview.ts:19
Tag the random loot draw picks from; defaults to ON_RANDOM_LOOT_TAG.
ItemView
Defined in: enchantments/src/item.ts:25
Item questions this package cannot answer from a stack's components alone. Every member is optional and every one has a default that reads the component a vanilla item would carry, so a host with a real item registry overrides only what it knows better.
Methods
damage()?
optionaldamage(stack):number
Defined in: enchantments/src/item.ts:36
Damage the stack has already taken.
Parameters
stack
Returns
number
displayName()?
optionaldisplayName(stack):string|undefined
Defined in: enchantments/src/item.ts:44
The name the client shows for a stack, which the anvil compares a typed name against. Without it the anvil only knows the custom name, so renaming an unnamed item back to its default name still costs a level.
Parameters
stack
Returns
string | undefined
enchantmentValue()?
optionalenchantmentValue(stack):number|undefined
Defined in: enchantments/src/item.ts:32
The item's enchantability, which widens the enchanting table's level draw. Zero or undefined means the table refuses the item.
Parameters
stack
Returns
number | undefined
maxDamage()?
optionalmaxDamage(stack):number
Defined in: enchantments/src/item.ts:34
Durability, or 0 when the item takes no damage.
Parameters
stack
Returns
number
repairsWith()?
optionalrepairsWith(stack,material):boolean
Defined in: enchantments/src/item.ts:38
Whether material repairs stack in the anvil's right slot.
Parameters
stack
material
Returns
boolean
tagsOf()?
optionaltagsOf(itemId): readonlystring[]
Defined in: enchantments/src/item.ts:27
Namespaced item tags the item carries, without the leading #.
Parameters
itemId
string
Returns
readonly string[]
LevelCost
Defined in: enchantments/src/definition.ts:41
A base plus per_level_above_first pair, which min_cost and max_cost both are. Java evaluates it as base + perLevelAboveFirst * (level - 1) and keeps the result an integer.
Properties
base
readonlybase:number
Defined in: enchantments/src/definition.ts:42
perLevelAboveFirst
readonlyperLevelAboveFirst:number
Defined in: enchantments/src/definition.ts:43
SeedableRandom
Defined in: enchantments/src/random.ts:9
A random source that can be reseeded and can draw a normal deviate. The enchanting table reseeds one stream per offer slot, and remove_binomial switches to a normal approximation on large inputs, so both operations need more than the uniform draws RandomSource promises.
Extends
Methods
nextFloat()
nextFloat():
number
Defined in: predicates/src/random.ts:8
Returns a float in the half-open interval [0, 1).
Returns
number
Inherited from
nextGaussian()
nextGaussian():
number
Defined in: enchantments/src/random.ts:13
Returns a draw from the standard normal distribution.
Returns
number
nextInt()
nextInt(
bound):number
Defined in: predicates/src/random.ts:10
Returns an integer in the half-open interval [0, bound).
Parameters
bound
number
Returns
number
Inherited from
setSeed()
setSeed(
seed):void
Defined in: enchantments/src/random.ts:11
Restarts the stream, discarding any cached gaussian.
Parameters
seed
number
Returns
void
Type Aliases
AttributeOperation
AttributeOperation = typeof
ATTRIBUTE_OPERATIONS[number]
Defined in: enchantments/src/effects.ts:57
One of ATTRIBUTE_OPERATIONS.
CompiledEffect
CompiledEffect = (
level,context,emit) =>void
Defined in: enchantments/src/effects.ts:162
A compiled entity or location effect. Running it resolves the effect against one level and one context and hands each leaf to emit; all_of emits each of its members in order and never surfaces itself.
Parameters
level
number
context
emit
(effect) => void
Returns
void
EffectComponentKind
EffectComponentKind =
"value"|"targeted_value"|"unconditional_value"|"entity_effect"|"targeted_entity_effect"|"location_effect"|"conditional_marker"|"marker"|"attributes"|"charging_sounds"|"sound_list"
Defined in: enchantments/src/components.ts:26
How a component's body is shaped, which decides what parsing it and running it mean. The kinds come from the codec each component registers in EnchantmentEffectComponents in the 26.3 server jar.
EffectComponentType
EffectComponentType = keyof typeof
EFFECT_COMPONENTS
Defined in: enchantments/src/components.ts:90
One of the keys of EFFECT_COMPONENTS.
EffectScope
EffectScope =
"entity"|"location"
Defined in: enchantments/src/effects.ts:48
Which set of effect types a component accepts.
EffectSink
EffectSink = (
run) =>void
Defined in: enchantments/src/registry.ts:54
Where an enchantment's world changes go. This package resolves what should happen and never does it, because moving an entity, placing a block or playing a sound belongs to the server.
Parameters
run
Returns
void
EnchantmentEffects
EnchantmentEffects =
ReadonlyMap<EffectComponentType,ParsedComponent>
Defined in: enchantments/src/components.ts:157
Every effect component one enchantment declares, keyed by component name.
EnchantmentIdentifierMapper
EnchantmentIdentifierMapper = (
enchantment) =>string|undefined
Defined in: enchantments/src/bedrock.ts:16
Translates one Java enchantment id to its Bedrock id, or returns undefined when Bedrock has none. Adapt javaIdentifierToBedrock('enchantment', id) from @jsprismarine/mapping to this shape; this package stays unaware that two editions exist.
Parameters
enchantment
string
Returns
string | undefined
EnchantmentTag
EnchantmentTag = typeof
ENCHANTMENT_TAGS[number]
Defined in: enchantments/src/registry.ts:36
One of ENCHANTMENT_TAGS.
EnchantmentTarget
EnchantmentTarget = typeof
ENCHANTMENT_TARGETS[number]
Defined in: enchantments/src/components.ts:19
One of ENCHANTMENT_TARGETS.
EntityEffectType
EntityEffectType = typeof
ENTITY_EFFECT_TYPES[number]
Defined in: enchantments/src/effects.ts:42
One of ENTITY_EFFECT_TYPES.
EquipmentSlotGroup
EquipmentSlotGroup = typeof
EQUIPMENT_SLOT_GROUPS[number]
Defined in: enchantments/src/definition.ts:31
One of EQUIPMENT_SLOT_GROUPS.
LocationEffectType
LocationEffectType = typeof
LOCATION_EFFECT_TYPES[number]
Defined in: enchantments/src/effects.ts:45
One of LOCATION_EFFECT_TYPES.
ParsedComponent
ParsedComponent = {
entries: readonlyConditionalValueEntry[];kind:"value"|"targeted_value"; } | {effect:ValueEffect;kind:"unconditional_value"; } | {entries: readonlyConditionalEffectEntry[];kind:"entity_effect"|"targeted_entity_effect"|"location_effect"; } | {entries: readonlyConditionalMarkerEntry[];kind:"conditional_marker"; } | {kind:"marker"; } | {kind:"attributes";modifiers: readonlyCompiledEffect[]; } | {kind:"charging_sounds";perLevel: readonlyChargingSounds[]; } | {kind:"sound_list";perLevel: readonlystring[]; }
Defined in: enchantments/src/components.ts:143
The parsed body of one effect component, discriminated by the kind its declaration gives it, so a caller narrows once and then has the right shape.
ResolvedEffect
ResolvedEffect = {
amount:number;type:"apply_exhaustion"; } | {coordinateScale:Vec3;direction:Vec3;magnitude:number;type:"apply_impulse"; } | {maxAmplifier:number;maxDuration:number;minAmplifier:number;minDuration:number;toApply:MemberSet;type:"apply_mob_effect"; } | {amount:number;type:"change_item_damage"; } | {damageType:string;maxDamage:number;minDamage:number;type:"damage_entity"; } | {attributeToUser:boolean;blockInteraction:string;blockParticles:unknown;createFire:boolean;damageType:string|undefined;immuneBlocks:MemberSet|undefined;knockbackMultiplier:number|undefined;largeParticle:unknown;offset:Vec3;radius:number;smallParticle:unknown;sound:string|undefined;type:"explode"; } | {duration:number;type:"ignite"; } | {pitch:number;sounds: readonlystring[];type:"play_sound";volume:number; } | {blockState:unknown;offset:Vec3;predicate:unknown;triggerGameEvent:string|undefined;type:"replace_block"; } | {blockState:unknown;height:number;offset:Vec3;predicate:unknown;radius:number;triggerGameEvent:string|undefined;type:"replace_disk"; } | {function:string;type:"run_function"; } | {offset:Vec3;properties:unknown;triggerGameEvent:string|undefined;type:"set_block_properties"; } | {horizontalPosition:unknown;horizontalVelocity:unknown;particle:unknown;speed:number;type:"spawn_particles";verticalPosition:unknown;verticalVelocity:unknown; } | {entityTypes:MemberSet;joinTeam:boolean;type:"summon_entity"; } | {amount:number;attribute:string;id:string;operation:AttributeOperation;type:"attribute"; }
Defined in: enchantments/src/effects.ts:69
One world change an enchantment asks for, with every level based value and number provider already resolved against the level and the context.
Identifiers, block states, block predicates and particle options stay as the parsed JSON they came from: those registries live in the host, and copying them here would make this package own data it cannot validate. Durations are in seconds, which is the unit the Java effects carry before they multiply by 20.
Union Members
Type Literal
{ amount: number; type: "apply_exhaustion"; }
Type Literal
{ coordinateScale: Vec3; direction: Vec3; magnitude: number; type: "apply_impulse"; }
Type Literal
{ maxAmplifier: number; maxDuration: number; minAmplifier: number; minDuration: number; toApply: MemberSet; type: "apply_mob_effect"; }
maxAmplifier
readonlymaxAmplifier:number
maxDuration
readonlymaxDuration:number
minAmplifier
readonlyminAmplifier:number
minDuration
readonlyminDuration:number
toApply
readonlytoApply:MemberSet
Mob effect ids to choose one from, with any tags the host still has to expand.
type
readonlytype:"apply_mob_effect"
Type Literal
{ amount: number; type: "change_item_damage"; }
Type Literal
{ damageType: string; maxDamage: number; minDamage: number; type: "damage_entity"; }
Type Literal
{ attributeToUser: boolean; blockInteraction: string; blockParticles: unknown; createFire: boolean; damageType: string | undefined; immuneBlocks: MemberSet | undefined; knockbackMultiplier: number | undefined; largeParticle: unknown; offset: Vec3; radius: number; smallParticle: unknown; sound: string | undefined; type: "explode"; }
Type Literal
{ duration: number; type: "ignite"; }
Type Literal
{ pitch: number; sounds: readonly string[]; type: "play_sound"; volume: number; }
pitch
readonlypitch:number
sounds
readonlysounds: readonlystring[]
Sound event ids to choose one from, in the order the file lists them.
type
readonlytype:"play_sound"
volume
readonlyvolume:number
Type Literal
{ blockState: unknown; offset: Vec3; predicate: unknown; triggerGameEvent: string | undefined; type: "replace_block"; }
Type Literal
{ blockState: unknown; height: number; offset: Vec3; predicate: unknown; radius: number; triggerGameEvent: string | undefined; type: "replace_disk"; }
Type Literal
{ function: string; type: "run_function"; }
Type Literal
{ offset: Vec3; properties: unknown; triggerGameEvent: string | undefined; type: "set_block_properties"; }
Type Literal
{ horizontalPosition: unknown; horizontalVelocity: unknown; particle: unknown; speed: number; type: "spawn_particles"; verticalPosition: unknown; verticalVelocity: unknown; }
Type Literal
{ entityTypes: MemberSet; joinTeam: boolean; type: "summon_entity"; }
Type Literal
{ amount: number; attribute: string; id: string; operation: AttributeOperation; type: "attribute"; }
ValueEffect
ValueEffect = (
level,base,random) =>number
Defined in: enchantments/src/values.ts:28
One step of an enchantment's arithmetic on a game value. Effects compose by threading the running value through each in order, which is what all_of and a component's list of entries both do.
Parameters
level
number
Level of the enchantment that owns the effect, counting from 1.
base
number
Value so far, which is the vanilla value on the first effect.
random
Returns
number
ValueEffectType
ValueEffectType = typeof
VALUE_EFFECT_TYPES[number]
Defined in: enchantments/src/values.ts:18
One of VALUE_EFFECT_TYPES.
Vec3
Vec3 = readonly [
number,number,number]
Defined in: enchantments/src/effects.ts:51
An [x, y, z] triple, as the effect grammar writes offsets and directions.
Variables
ANVIL_COMBINE_BONUS_PERCENT
constANVIL_COMBINE_BONUS_PERCENT:12=12
Defined in: enchantments/src/anvil.ts:25
Combining two damaged items adds this percent of maximum durability on top.
ANVIL_COST_LIMIT
constANVIL_COST_LIMIT:40=40
Defined in: enchantments/src/anvil.ts:16
Levels at or above which a survival player sees "Too Expensive!" and gets nothing.
ANVIL_RENAME_COST_LIMIT
constANVIL_RENAME_COST_LIMIT:number
Defined in: enchantments/src/anvil.ts:19
The highest cost a pure rename is allowed to reach, one below the limit.
ANVIL_REPAIR_DIVISOR
constANVIL_REPAIR_DIVISOR:4=4
Defined in: enchantments/src/anvil.ts:22
One repair material restores this fraction of an item's durability.
ATTRIBUTE_OPERATIONS
constATTRIBUTE_OPERATIONS: readonly ["add_value","add_multiplied_base","add_multiplied_total"]
Defined in: enchantments/src/effects.ts:54
The three attribute modifier operations of 26.3.
BOOK_ITEM
constBOOK_ITEM:"minecraft:book"='minecraft:book'
Defined in: enchantments/src/table.ts:32
A book takes any enchantment in the table's pool, not only the ones that support it.
CUSTOM_NAME_COMPONENT
constCUSTOM_NAME_COMPONENT:"minecraft:custom_name"='minecraft:custom_name'
Defined in: enchantments/src/anvil.ts:31
The component that holds a custom item name.
DAMAGE_COMPONENT
constDAMAGE_COMPONENT:"minecraft:damage"='minecraft:damage'
Defined in: enchantments/src/item.ts:17
Damage an item has already taken.
EFFECT_COMPONENTS
constEFFECT_COMPONENTS:object
Defined in: enchantments/src/components.ts:55
The 31 members of minecraft:enchantment_effect_component_type in 26.3, each with the codec shape and the loot context key set it registers with. Vanilla's 43 enchantment files use 30 of them; mob_experience is the one nothing declares.
Type Declaration
ammo_use
readonlyammo_use:object
ammo_use.kind
readonlykind:"value"='value'
ammo_use.parameterSet
readonlyparameterSet:"enchanted_item"='enchanted_item'
armor_effectiveness
readonlyarmor_effectiveness:object
armor_effectiveness.kind
readonlykind:"value"='value'
armor_effectiveness.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
attributes
readonlyattributes:object
attributes.kind
readonlykind:"attributes"='attributes'
block_experience
readonlyblock_experience:object
block_experience.kind
readonlykind:"value"='value'
block_experience.parameterSet
readonlyparameterSet:"enchanted_item"='enchanted_item'
crossbow_charge_time
readonlycrossbow_charge_time:object
crossbow_charge_time.kind
readonlykind:"unconditional_value"='unconditional_value'
crossbow_charging_sounds
readonlycrossbow_charging_sounds:object
crossbow_charging_sounds.kind
readonlykind:"charging_sounds"='charging_sounds'
damage
readonlydamage:object
damage.kind
readonlykind:"value"='value'
damage.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
damage_immunity
readonlydamage_immunity:object
damage_immunity.kind
readonlykind:"conditional_marker"='conditional_marker'
damage_immunity.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
damage_protection
readonlydamage_protection:object
damage_protection.kind
readonlykind:"value"='value'
damage_protection.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
equipment_drops
readonlyequipment_drops:object
equipment_drops.kind
readonlykind:"targeted_value"='targeted_value'
equipment_drops.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
fishing_luck_bonus
readonlyfishing_luck_bonus:object
fishing_luck_bonus.kind
readonlykind:"value"='value'
fishing_luck_bonus.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
fishing_time_reduction
readonlyfishing_time_reduction:object
fishing_time_reduction.kind
readonlykind:"value"='value'
fishing_time_reduction.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
hit_block
readonlyhit_block:object
hit_block.kind
readonlykind:"entity_effect"='entity_effect'
hit_block.parameterSet
readonlyparameterSet:"hit_block"='hit_block'
item_damage
readonlyitem_damage:object
item_damage.kind
readonlykind:"value"='value'
item_damage.parameterSet
readonlyparameterSet:"enchanted_item"='enchanted_item'
knockback
readonlyknockback:object
knockback.kind
readonlykind:"value"='value'
knockback.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
location_changed
readonlylocation_changed:object
location_changed.kind
readonlykind:"location_effect"='location_effect'
location_changed.parameterSet
readonlyparameterSet:"enchanted_location"='enchanted_location'
mob_experience
readonlymob_experience:object
mob_experience.kind
readonlykind:"value"='value'
mob_experience.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
post_attack
readonlypost_attack:object
post_attack.kind
readonlykind:"targeted_entity_effect"='targeted_entity_effect'
post_attack.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
post_piercing_attack
readonlypost_piercing_attack:object
post_piercing_attack.kind
readonlykind:"entity_effect"='entity_effect'
post_piercing_attack.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
prevent_armor_change
readonlyprevent_armor_change:object
prevent_armor_change.kind
readonlykind:"marker"='marker'
prevent_equipment_drop
readonlyprevent_equipment_drop:object
prevent_equipment_drop.kind
readonlykind:"marker"='marker'
projectile_count
readonlyprojectile_count:object
projectile_count.kind
readonlykind:"value"='value'
projectile_count.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
projectile_piercing
readonlyprojectile_piercing:object
projectile_piercing.kind
readonlykind:"value"='value'
projectile_piercing.parameterSet
readonlyparameterSet:"enchanted_item"='enchanted_item'
projectile_spawned
readonlyprojectile_spawned:object
projectile_spawned.kind
readonlykind:"entity_effect"='entity_effect'
projectile_spawned.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
projectile_spread
readonlyprojectile_spread:object
projectile_spread.kind
readonlykind:"value"='value'
projectile_spread.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
repair_with_xp
readonlyrepair_with_xp:object
repair_with_xp.kind
readonlykind:"value"='value'
repair_with_xp.parameterSet
readonlyparameterSet:"enchanted_item"='enchanted_item'
smash_damage_per_fallen_block
readonlysmash_damage_per_fallen_block:object
smash_damage_per_fallen_block.kind
readonlykind:"value"='value'
smash_damage_per_fallen_block.parameterSet
readonlyparameterSet:"enchanted_damage"='enchanted_damage'
tick
readonlytick:object
tick.kind
readonlykind:"entity_effect"='entity_effect'
tick.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
trident_return_acceleration
readonlytrident_return_acceleration:object
trident_return_acceleration.kind
readonlykind:"value"='value'
trident_return_acceleration.parameterSet
readonlyparameterSet:"enchanted_entity"='enchanted_entity'
trident_sound
readonlytrident_sound:object
trident_sound.kind
readonlykind:"sound_list"='sound_list'
trident_spin_attack_strength
readonlytrident_spin_attack_strength:object
trident_spin_attack_strength.kind
readonlykind:"unconditional_value"='unconditional_value'
EFFECT_COMPONENT_TYPES
constEFFECT_COMPONENT_TYPES: readonlyEffectComponentType[]
Defined in: enchantments/src/components.ts:96
The 31 component names, in the order the 26.3 registry declares them.
ENCHANTABLE_COMPONENT
constENCHANTABLE_COMPONENT:"minecraft:enchantable"='minecraft:enchantable'
Defined in: enchantments/src/item.ts:11
Enchantability, which widens the enchanting table's level draw.
ENCHANTED_BOOK_ITEM
constENCHANTED_BOOK_ITEM:"minecraft:enchanted_book"='minecraft:enchanted_book'
Defined in: enchantments/src/anvil.ts:28
The item whose enchantments the anvil reads from stored_enchantments.
ENCHANTING_SLOTS
constENCHANTING_SLOTS:3=3
Defined in: enchantments/src/table.ts:26
An enchanting table always shows three rows.
ENCHANTMENTS_COMPONENT
constENCHANTMENTS_COMPONENT:"minecraft:enchantments"='minecraft:enchantments'
Defined in: enchantments/src/item.ts:5
Enchantments applied to an item, which is what the effect machinery reads.
ENCHANTMENT_TAGS
constENCHANTMENT_TAGS: readonly ["curse","double_trade_price","in_enchanting_table","non_treasure","on_mob_spawn_equipment","on_random_loot","on_traded_equipment","prevents_bee_spawns_when_mining","prevents_decorated_pot_shattering","prevents_ice_melting","prevents_infested_spawns","smelts_loot","tooltip_order","tradeable","treasure"]
Defined in: enchantments/src/registry.ts:17
Functionality tags under tags/enchantment/ in 26.3. None of them changes what an enchantment does; each one is a switch some other system reads, which is why an enchantment is only half described by its own file.
ENCHANTMENT_TARGETS
constENCHANTMENT_TARGETS: readonly ["attacker","damaging_entity","victim"]
Defined in: enchantments/src/components.ts:16
The three entities a post_attack or equipment_drops entry can name.
ENTITY_EFFECT_TYPES
constENTITY_EFFECT_TYPES: readonly ["all_of","apply_exhaustion","apply_impulse","apply_mob_effect","change_item_damage","damage_entity","explode","ignite","play_sound","replace_block","replace_disk","run_function","set_block_properties","spawn_particles","summon_entity"]
Defined in: enchantments/src/effects.ts:15
Members of minecraft:enchantment_entity_effect_type in 26.3.
EQUIPMENT_SLOT_GROUPS
constEQUIPMENT_SLOT_GROUPS: readonly ["any","mainhand","offhand","hand","feet","legs","chest","head","armor","body","saddle"]
Defined in: enchantments/src/definition.ts:16
The 11 equipment slot groups an enchantment's slots may name in 26.3.
IN_ENCHANTING_TABLE_TAG
constIN_ENCHANTING_TABLE_TAG:"minecraft:in_enchanting_table"='minecraft:in_enchanting_table'
Defined in: enchantments/src/table.ts:29
The tag the enchanting table draws from when a caller names no candidates.
LOCATION_EFFECT_TYPES
constLOCATION_EFFECT_TYPES: readonly ["all_of","apply_exhaustion","apply_impulse","apply_mob_effect","change_item_damage","damage_entity","explode","ignite","play_sound","replace_block","replace_disk","run_function","set_block_properties","spawn_particles","summon_entity","attribute"]
Defined in: enchantments/src/effects.ts:39
Members of minecraft:enchantment_location_based_effect_type in 26.3, which are the entity effects plus attribute. Only location_changed takes this wider set, because only it can hold a modifier while the condition stays true and withdraw it when the condition stops.
MAX_BOOKSHELF_POWER
constMAX_BOOKSHELF_POWER:15=15
Defined in: enchantments/src/table.ts:23
Bookshelves past this many around a table change nothing.
MAX_DAMAGE_COMPONENT
constMAX_DAMAGE_COMPONENT:"minecraft:max_damage"='minecraft:max_damage'
Defined in: enchantments/src/item.ts:15
Durability of an item that takes damage.
MIN_ENCHANTMENT_LEVEL
constMIN_ENCHANTMENT_LEVEL:1=1
Defined in: enchantments/src/definition.ts:34
Java hardcodes the lowest level of every enchantment to 1.
ON_RANDOM_LOOT_TAG
constON_RANDOM_LOOT_TAG:"minecraft:on_random_loot"='minecraft:on_random_loot'
Defined in: enchantments/src/lootview.ts:8
The tag enchant_randomly draws from when a loot entry names no options.
REPAIRABLE_COMPONENT
constREPAIRABLE_COMPONENT:"minecraft:repairable"='minecraft:repairable'
Defined in: enchantments/src/item.ts:13
Items that repair this one in the anvil.
REPAIR_COST_COMPONENT
constREPAIR_COST_COMPONENT:"minecraft:repair_cost"='minecraft:repair_cost'
Defined in: enchantments/src/item.ts:9
Levels the anvil has already charged for an item, its prior work penalty.
STORED_ENCHANTMENTS_COMPONENT
constSTORED_ENCHANTMENTS_COMPONENT:"minecraft:stored_enchantments"='minecraft:stored_enchantments'
Defined in: enchantments/src/item.ts:7
Enchantments an enchanted book carries but does not apply.
SWEEPING_EDGE
constSWEEPING_EDGE:"minecraft:sweeping_edge"='minecraft:sweeping_edge'
Defined in: enchantments/src/bedrock.ts:8
The one vanilla Java enchantment with no Bedrock counterpart. 42 of Java's 43 map; this one is on @jsprismarine/mapping's reviewed loss list.
VALUE_EFFECT_TYPES
constVALUE_EFFECT_TYPES: readonly ["add","all_of","exponential","multiply","remove_binomial","set"]
Defined in: enchantments/src/values.ts:15
The six members of minecraft:enchantment_value_effect_type in 26.3.
componentItemView
constcomponentItemView:ItemView
Defined in: enchantments/src/item.ts:114
An ItemView that knows only what a stack's own components say. Every answer comes from the component a vanilla item of that kind carries: minecraft:enchantable, minecraft:max_damage, minecraft:damage and minecraft:repairable. It cannot answer tagsOf, so a tag-named item set matches nothing until a host supplies the item tags.
Functions
availableEnchantments()
availableEnchantments(
registry,stack,level,candidates?): readonlyEnchantmentInstance[]
Defined in: enchantments/src/table.ts:82
Every enchantment and level a draw at level could produce for a stack.
One entry per enchantment at most: Java walks a candidate's levels downward and keeps the first whose cost window contains level, so a draw never offers a weaker level than it could.
Parameters
registry
stack
level
number
The modified enchantment level, after the table widened the row cost.
candidates?
readonly string[]
Returns
readonly EnchantmentInstance[]
canStoreEnchantments()
canStoreEnchantments(
stack):boolean
Defined in: enchantments/src/anvil.ts:79
Whether the anvil accepts a stack in its left slot. An enchanted book needs stored enchantments; anything else qualifies, because in 26.3 every item carries a default minecraft:enchantments component.
Parameters
stack
Returns
boolean
combineInAnvil()
combineInAnvil(
registry,input,options?):AnvilResult
Defined in: enchantments/src/anvil.ts:98
Combines the two anvil slots.
Java's AnvilMenu.createResult from the 26.3 server jar, step for step: the material repair loop, the 12 percent bonus when two damaged items merge, the enchantment merge where equal levels become one higher and unequal ones take the larger, one level charged per incompatible enchantment, half the anvil cost when the enchantments come from a book, and the prior work penalty doubling on every use that is not a pure rename.
Nothing here consumes items or experience; the caller decides whether the player can pay and applies the result.
Parameters
registry
input
options?
AnvilOptions = {}
Returns
costAt()
costAt(
cost,level):number
Defined in: enchantments/src/definition.ts:47
Evaluates a LevelCost at one level, counting levels from 1.
Parameters
cost
level
number
Returns
number
createEnchantmentView()
createEnchantmentView(
registry,options?):EnchantmentView
Defined in: enchantments/src/lootview.ts:35
The adapter for the EnchantmentView seam that @jsprismarine/predicates declares.
This is the piece fortune and looting need. Neither carries a value effect for its drop bonus: fortune has no effects at all, and the block loot tables name minecraft:fortune directly in 32 apply_bonus calls and 35 table_bonus conditions. Those loot functions already own the bonus arithmetic; all they lack is the level on the tool, which levelOn answers. Nothing here repeats the formulas.
Parameters
registry
options?
Returns
A view a host passes to new PredicateContext({ enchantments }).
declarationOf()
declarationOf(
component):EffectComponentDeclaration
Defined in: enchantments/src/components.ts:105
One component's declaration, widened to EffectComponentDeclaration. Reading EFFECT_COMPONENTS directly keeps each entry's literal type, which means a component with no key set has no parameterSet property at all; this returns the common shape instead.
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"
Returns
effectAt()
effectAt(
value,scope,context):CompiledEffect
Defined in: enchantments/src/effects.ts:382
Compiles an entity or location effect at a position inside a larger parse. An unknown type, or a location-only type in an entity component, reports and emits nothing.
Parameters
value
unknown
scope
context
Returns
effectsAt()
effectsAt(
value,context):EnchantmentEffects
Defined in: enchantments/src/components.ts:268
Parses an enchantment's effects map. A key that is not one of the 31 components reports and is dropped, because a datapack cannot add a component type; only the enchantment files that use the existing ones.
Parameters
value
unknown
context
Returns
enchantingOffers()
enchantingOffers(
registry,stack,options): readonlyEnchantingOffer[]
Defined in: enchantments/src/table.ts:174
The three rows an enchanting table shows for a stack.
One java.util.Random drives the whole thing, seeded with the player's enchantment seed for the costs and reseeded with seed + row for each row's draw, which is why the rows are stable until the player enchants something. A row whose cost is below its own index shows nothing, and so does a stack the table cannot enchant.
Parameters
registry
stack
options
Returns
readonly EnchantingOffer[]
Exactly ENCHANTING_SLOTS rows, cheapest first.
enchantmentAt()
enchantmentAt(
id,value,context):EnchantmentDefinition
Defined in: enchantments/src/definition.ts:139
Parses one enchantment file. Nothing throws: a missing or malformed field reports through the parse context and takes a safe default, so one bad file does not take the pack down with it.
Parameters
id
string
Namespaced id of the enchantment, which the file body does not carry.
value
unknown
context
Returns
enchantmentCost()
enchantmentCost(
random,slot,bookshelfPower):number
Defined in: enchantments/src/table.ts:45
The experience level one row of the enchanting table costs.
Java's formula, from EnchantmentHelper.getEnchantmentCost in the 26.3 server jar: a base of nextInt(8) + 1 + power / 2 + nextInt(power + 1), then a third of it in the top row, two thirds plus one in the middle, and the larger of the base and twice the power in the bottom.
Parameters
random
slot
number
Row index, 0 for the cheapest.
bookshelfPower
number
Bookshelves around the table, clamped to MAX_BOOKSHELF_POWER.
Returns
number
enchantmentsForCrafting()
enchantmentsForCrafting(
stack):ReadonlyMap<string,number>
Defined in: enchantments/src/item.ts:75
The enchantments the anvil combines, which are the stored ones on an enchanted book and the applied ones on anything else.
Parameters
stack
Returns
ReadonlyMap<string, number>
enchantmentsOf()
enchantmentsOf(
stack):ReadonlyMap<string,number>
Defined in: enchantments/src/item.ts:64
Reads the minecraft:enchantments component, accepting both the {"levels": {...}} wrapper Java writes and a bare identifier-to-level map.
Parameters
stack
Returns
ReadonlyMap<string, number>
gaussianFrom()
gaussianFrom(
random):number
Defined in: enchantments/src/random.ts:110
Draws a normal deviate from any random source. A source that already knows how, such as javaRandom, answers directly; anything else goes through the Marsaglia polar method over its uniform draws, which is distributed correctly but does not reproduce Java's stream.
Parameters
random
Returns
number
increasedRepairCost()
increasedRepairCost(
cost):number
Defined in: enchantments/src/anvil.ts:72
The prior work penalty after one anvil use, which is what makes the fourth or fifth combination of the same item unaffordable.
Parameters
cost
number
Returns
number
isEffectComponentType()
isEffectComponentType(
name): name is "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"
Defined in: enchantments/src/components.ts:93
Whether a bare name is one of the 31 components.
Parameters
name
string
Returns
name is "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"
javaRandom()
javaRandom(
seed):SeedableRandom
Defined in: enchantments/src/random.ts:35
java.util.Random, which Minecraft's LegacyRandomSource is, reproduced draw for draw.
Java Edition's enchanting table seeds this generator from the player's enchantment seed, so an offer is only reproducible against vanilla when the generator is the same one. The 48 bit state lives in two 24 bit halves rather than a BigInt because every intermediate product then stays inside the 53 bits a double holds exactly.
Parameters
seed
number
Seed in Java's sense, scrambled on the way in the same way setSeed scrambles it.
Returns
levelsOf()
levelsOf(
definition): readonlynumber[]
Defined in: enchantments/src/definition.ts:174
Every level an enchantment offers, from 1 up to its max_level.
Parameters
definition
Returns
readonly number[]
parseEffect()
parseEffect(
value,scope,options?):ParseResult<CompiledEffect>
Defined in: enchantments/src/effects.ts:399
Compiles an entity or location effect from parsed JSON.
Parameters
value
unknown
scope
options?
Returns
parseEffects()
parseEffects(
value,options?):ParseResult<EnchantmentEffects>
Defined in: enchantments/src/components.ts:288
Parses an enchantment's effects map from parsed JSON.
Parameters
value
unknown
options?
Returns
ParseResult<EnchantmentEffects>
parseEnchantment()
parseEnchantment(
id,value,options?):ParseResult<EnchantmentDefinition>
Defined in: enchantments/src/definition.ts:164
Compiles one enchantment definition from parsed JSON.
Parameters
id
string
value
unknown
options?
Returns
ParseResult<EnchantmentDefinition>
parseValueEffect()
parseValueEffect(
value,options?):ParseResult<ValueEffect>
Defined in: enchantments/src/values.ts:121
Compiles a value effect from parsed JSON.
Parameters
value
unknown
options?
Returns
projectToBedrock()
projectToBedrock(
registry,levels,mapper,options?):BedrockProjectionResult
Defined in: enchantments/src/bedrock.ts:92
Works out what a Bedrock client can be told about a stack's enchantments.
What the client cannot be told matters more than what it can. A Bedrock client only knows the enchantments its own registry lists, so sweeping_edge and every datapack enchantment arrive as nothing at all. The server still runs their mechanics, because every effect component in this package resolves server-side and reaches the world through an effect sink; the client just never learns why the numbers moved. The honest substitute is the one vanilla Bedrock itself has no better answer for: a lore line naming the enchantment, and a glint the server forces on.
Consequences worth stating plainly. A player sees the lore line but gets no tooltip ordering, no enchantment-specific tooltip color, and nothing in the creative or anvil interfaces that recognizes it. An anvil or enchanting table interaction is decided on the server, so the client's own preview is wrong whenever a server-side enchantment is involved and the server has to send the result rather than let the client compute it.
Parameters
registry
EnchantmentRegistry | undefined
The definitions, which only the lore builder reads. Undefined is allowed because a stack on the wire is projected wherever it is drawn, including on a server that loaded no enchantment data; the lore builder then gets undefined for every enchantment and names it from its id.
levels
ReadonlyMap<string, number>
Enchantment id to level, as the minecraft:enchantments component holds it.
mapper
options?
Returns
repairCostOf()
repairCostOf(
stack):number
Defined in: enchantments/src/item.ts:81
Reads the minecraft:repair_cost component, which is the anvil's prior work penalty.
Parameters
stack
Returns
number
romanNumeral()
romanNumeral(
level):string
Defined in: enchantments/src/bedrock.ts:52
The level suffix both editions print after an enchantment name. Vanilla translates levels 1 through 10 and has no key for anything else, so a level outside that range prints as a plain number here rather than as a numeral no client would show.
Parameters
level
number
Returns
string
selectEnchantments()
selectEnchantments(
registry,random,stack,level,candidates?): readonlyEnchantmentInstance[]
Defined in: enchantments/src/table.ts:116
Draws the enchantments one row of the table grants.
Java's EnchantmentHelper.selectEnchantment, verbatim: widen the row cost by the item's enchantability, nudge it by up to 15 percent either way, pick one candidate by weight, then keep halving the level and picking again while nextInt(50) stays at or below it, dropping candidates that conflict with the last pick.
Parameters
registry
random
stack
level
number
The row's experience cost.
candidates?
readonly string[]
Returns
readonly EnchantmentInstance[]
The picks in the order they were drawn, which is the order their conflicts were resolved.
stackMatches()
stackMatches(
stack,members,view):boolean
Defined in: enchantments/src/item.ts:127
Whether a stack is in a set that an enchantment's supported_items, primary_items or an effect's block list names. Ids match directly; a tag matches when the view reports the item carries it.
Parameters
stack
members
view
Returns
boolean
storedEnchantmentsOf()
storedEnchantmentsOf(
stack):ReadonlyMap<string,number>
Defined in: enchantments/src/item.ts:68
Reads the minecraft:stored_enchantments component an enchanted book carries.
Parameters
stack
Returns
ReadonlyMap<string, number>
valueEffectAt()
valueEffectAt(
value,context):ValueEffect
Defined in: enchantments/src/values.ts:99
Compiles a value effect at a position inside a larger parse. An unknown type reports and leaves the running value alone, so one bad effect does not discard the enchantment around it.
Parameters
value
unknown
context
Returns
withEnchantments()
withEnchantments(
stack,levels,ops):ItemStack
Defined in: enchantments/src/item.ts:84
Writes an enchantment map back as a minecraft:enchantments component.
Parameters
stack
levels
ReadonlyMap<string, number>
ops
Returns
withRepairCost()
withRepairCost(
stack,cost,ops):ItemStack
Defined in: enchantments/src/item.ts:88
Writes the minecraft:repair_cost component.
Parameters
stack
cost
number