Jump to content

Vanilla Enchantments on custom Item


VengeanceSoldier

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

Hi

 

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.

 

-TGG

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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