Jump to content

Is there a way to override and add functionality to a vanilla enchantment?


Recommended Posts

Posted

Hi, I'm trying to add some cool additional functionality to a vanilla enchantment when applied to an item it normally could not be put on. My goal is to allow the user to place Silk Touch on any sword using an enchanted book and an anvil, similar to shears. I then want to modify the loot of any mob killed by a sword with this enchantment.

 

I have poked around a little bit and found the canApply(ItemStack par1ItemStack) function in EnchantmentUntouching. Adding this to the end of the ternary operator allows silk touch to be placed on a diamond sword in addition to a shear.

 

public boolean canApply(ItemStack par1ItemStack)

{

        return par1ItemStack.getItem().itemID == Item.shears.itemID ? true : par1ItemStack.getItem().itemID == Item.swordDiamond.itemID ? true : super.canApply(par1ItemStack);

}

 

I have also found getSilkTouchModifier(EntityLiving par0EntityLiving) in EnchantmentHelper that is used to determine whether or not the item in the player's hand has silk touch.

 

I'd rather not modify a base class though. Is there a way to override silk touch to add in some additional functionality?

 

P.S. Is there some way to nicely format code on this forum? I did not see any option to when making this post.

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.

Announcements



×
×
  • Create New...

Important Information

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