#How do I enchant an itemStack?

3 messages · Page 1 of 1 (latest)

abstract cave
#

I'm trying to add enchantment on an item stack to place on a mob that is spawning into the world

ItemStack helmet = new ItemStack(Items.DIAMOND_HELMET);
ItemStack chestplate = new ItemStack(Items.DIAMOND_CHESTPLATE);
ItemStack leggings = new ItemStack(Items.DIAMOND_LEGGINGS);
ItemStack boots = new ItemStack(Items.DIAMOND_BOOTS);

// Get the enchantment reference
RegistryEntry.Reference<Enchantment> enchantmentReference = mob.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.VANISHING_CURSE);

// Apply enchantments to each armor piece using EnchantmentHelper
EnchantmentHelper.set(helmet, enchantmentReference); // incorrect


mob.equipStack(EquipmentSlot.HEAD, helmet);
mob.equipStack(EquipmentSlot.CHEST, chestplate);
mob.equipStack(EquipmentSlot.LEGS, leggings);
mob.equipStack(EquipmentSlot.FEET, boots);
round raft
#

can you use stack.addEnchantment ?

spark sun
#

I guess you need a RegistryEntry<Enchantment> (smth like that) and then .enchant the item with it
Nvm, for the stack it should have an enchant method (pretty sure)