Jump to content

Vanilla Enchantments on custom Item


Recommended Posts

I'm trying to get my custom Item accept ONLY SPECIFIC vanilla enchantments (unbreaking) in the enchanting table. I know that you can allow the tool enchantments to be added by making the items class extend ItemTool, but that would allow all tool enchantments, like silk touch,... , to be added to the item. Is there a way of only accepting a few of these enchants without modifying base classes?

Link to comment
Share on other sites



After a quick look through the vanilla code I don't think there is anything you could do directly, but you might be able to get to the same place indirectly.  If you hijack the vanilla enchanting table using the GuiOpenEvent to replace the enchanting table GUI with one of your own which derives from GuiEnchantment, you could override mouseClicked to call a customContainerEnchantment which restricts the enchantments that can be applied.


If Draco reads this he might have more specific help, he's done a stack of stuff with enchantment.



Link to comment
Share on other sites

The only enchantment stuff I did was using the inbuilt system.


Specifically I'd check what kind of item I had, or close approximation, modified a tiny bit randomly, then:


                ItemStack stack = new ItemStack(item); //the vanilla item that is similar to my item
                stack = EnchantmentHelper.addRandomEnchantment(rand, stack, level); //add enchantments per existing rules
                if(stack.stackTagCompound != null) {
                        artifact.stackTagCompound.setTag("ench", stack.stackTagCompound.getTag("ench").copy()); //copy enchantments to my item
                        //other stuff

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.


Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.


DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.