Started by
Catnip
on
Topic category: Advanced modding
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.
this might work, I don't have any external mod with enchantments I can test it on though.
this will enchant the held item of the provided entity. if you want something else and can't figure it out just ask :3
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.
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)
Sure,
I don't have a 1.21.1 environment set up so I can't test it but it looks right in my IDE
The item is copied so it's not directly modifying it, this is an mcreator limitation.
Thank you so much, this works perfectly.
awesome! :3