How do you use an enchantment from another mod?

Started by Catnip on

Topic category: Advanced modding

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do you use an enchantment from another mod?

Hi, I was just wondering if anyone knows how to apply an enchantment from another mod to a specific itemstack.

I'm asking because I want to make a little cross-mod compatibility between my staffs mod and The Endless Hordes, where you could use a block from Endless Hordes to apply a staffs mod enchantment to a staffs mod item. I already know how to use tags to determine if it is the correct item, I was just wondering how I could apply the enchantment, because its from a different mod.

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
this might work, I don't…
Sun, 10/12/2025 - 14:30

this might work, I don't have any external mod with enchantments I can test it on though.

Optional<Holder.Reference<Enchantment>> enchantmentHolder = world.registryAccess().lookupOrThrow(Registries.ENCHANTMENT).get(ResourceLocation.parse(enchantment));
if(enchantmentHolder.isPresent()) {
	entity.getWeaponItem().enchant(
			enchantmentHolder.get(),
			(int)level
	);
}

this will enchant the held item of the provided entity. if you want something else and can't figure it out just ask :3

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you, I'll try to adapt…
Sun, 10/12/2025 - 16:15

Thank you, I'll try to adapt this to the procedure I currently have set up... at some point. I'll let you know then if I'm able to figure it out.