#Why isnt this enchanting the item?

1 messages · Page 1 of 1 (latest)

manic hemlock
#
      const item20 = new ItemStack("minecraft:bow",1)
      const enchantment32 = new Enchantment("infinity", 1)
item20.lockMode = "slot"
item20.getComponent("enchantments").enchantments.addEnchantment(enchantment32)
inventory.setItem(1, item20)```
#

lhj

#

jl

#

its setting the item

#

but not the enchantment

rapid furnace
#

seems like a bug with gametest addEnchantment not doing anything

    const itemStack = new Minecraft.ItemStack("minecraft:bow", 1)
    const enchantment = new Minecraft.Enchantment("infinity", 1);
    const component = (itemStack.getComponent("enchantments") as Minecraft.ItemEnchantsComponent);
    Minecraft.world.sendMessage(`Can add enchantment?: ${component.enchantments.canAddEnchantment(enchantment)}`);
    const result = component.enchantments.addEnchantment(enchantment);
    Minecraft.world.sendMessage(`Enchantment added?: ${result}`);
    Minecraft.world.sendMessage(`Enchantment is on item?: ${component.enchantments.getEnchantment(enchantment.type.id) !== undefined}`);
    inventory.setItem(1, itemStack);
manic hemlock
#

i found a way

#

to get it working

#

but my get enchantment function

#

isnt saying anything

rapid furnace
#

it doesnt report an error its just addEnchantment isnt actually adding the enchantment for some reason

manic hemlock
#

no

#
console.log(getEnchantments(item20, "power"))```
#
const getEnchantments = (item, type) => {
  const enchants = item.getComponent('enchantments');
  return enchants.enchantments.getEnchantment(type).level
  };```
glad garnet
#

u don’t even know js lol

halcyon turtle
#
const ench = item.getComponent("enchantments")
const enchList = ench.enchantments
enchList.addEnchantment(new Enchantment("infinity",1))
ench.enchantments = enchList 
``` @manic hemlock
tiny iron