Although this thread is suuuper dead, in case anyone needs the working code, here it is:
public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean bool) {
super.onUpdate(stack, world, entity, i, bool);
if(stack.isItemEnchanted() == false) {
stack.addEnchantment(MainRegistry.customEnchantment, 2);
// Or, Enchantments.whateverEnchantmentYouWant
super.onUpdate(stack, world, entity, i, bool);
}
}
Basically, the variables on the second super.onUpdate method were incorrect. Just match the variables of the super with the onUpdate method and everything should work.
Also, take a look at where my code says:
(MainRegistry.customEnchantment, 2);
This line is swappable and will change. If you're doing in game enchantments, then do:
(Enchantments.nameOfEnchantment, idOfTheEnchantment);
The code I have is for custom enchantments, for which you call your main modding class.