Mojira Archive
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.

Awaiting Response

Tom Adriaenssen

2022-08-30, 10:39 PM

2023-03-23, 04:03 PM

2023-03-23, 04:03 PM

1

1

Plausible

1.19.21 Hotfix

-