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.

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you again for the code…
Sun, 10/12/2025 - 20:26

Thank you again for the code, but it seems like it doesn't work for the Minecraft version I am trying to use (1.21.1 I should have specified this earlier, but I didn't think about it). Initially I tried converting the code to the procedure I have set up already, and it gave an error message when I tried compiling it. Then I tried to recreate the example procedure exactly and it gave the same error message: error: no suitable method found for get(ResourceLocation) Optional<Holder.Reference<Enchantment>> enchantmentHolder = world.registryAccess().lookupOrThrow(Registries.ENCHANTMENT).get(ResourceLocation.parse(enchantment));
^
method HolderGetter.get(ResourceKey<Enchantment>) is not applicable
(argument mismatch; ResourceLocation cannot be converted to ResourceKey<Enchantment>)
method HolderGetter.get(TagKey<Enchantment>) is not applicable
(argument mismatch; ResourceLocation cannot be converted to TagKey<Enchantment>)

Based on the message, I'm guessing the problem is with the Minecraft version.

If it wouldn't be asking too much, would you be able to send a new version of the code for Minecraft version 1.21.1, for the neoforge mod loader? Also, maybe a version to enchant an itemstack variable (which is the system I am currently using in the procedure I want to update)

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sure, Optional<Holder…
Sun, 10/12/2025 - 20:58

Sure,

Optional<Holder.Reference<Enchantment>> enchantmentHolder = world.registryAccess().registryOrThrow(Registries.ENCHANTMENT).getHolder(ResourceLocation.parse(enchant_enchantment));
if(enchantmentHolder.isPresent()) {
	enchant_item.enchant(enchantmentHolder.get(), (int)enchant_level);
}

I don't have a 1.21.1 environment set up so I can't test it but it looks right in my IDE

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The item is copied so it's…
Sun, 10/12/2025 - 20:59

The item is copied so it's not directly modifying it, this is an mcreator limitation.

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you so much, this…
Sun, 10/12/2025 - 21:06

Thank you so much, this works perfectly.