mojira.dev
MCPE-161753

Gametest Enchantment API does not work or is wrongly documented

Steps to Reproduce:

  1. create addon featuring GameTest code

  2. Retrieve a tool (e.g. pickaxe) with enchantments on it

  3. Run the code below to retrieve an enchantment 

Observed Results:
The code doesn't work

Expected Results:
The code does work and it is possible to retrieve an enchantment (or all enchantments).

let inventory = player.getComponent("minecraft:inventory")
if (inventory && inventory.container) {
    let item = inventory.container.getItem(player.selectedSlot)
    let enchantmentsComponent = item.getComponent("minecraft:enchantments")
    if (enchantmentsComponent != null) {
        let enchantments = enchantmentsComponent.enchantments
        if (enchantments != null) {
            let enchantment = enchantments.getEnchantment(EnchantmentType.mending) // ?
        }
    }       
}

EnchantmentType.mending does not exist, and EnchantmentType does not have a constructor. I've tried with "mending" or "minecraft:mending" but that gives the same result.

None of this is properly documented it appears.
The releasenotes also mention allEnchantments but that does not exist either.

Comments 1

Is this still an issue in the latest version?

Tom Adriaenssen

(Unassigned)

Plausible

Multiple

Any (in this case: Windows)

1.19.21 Hotfix

Retrieved