Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

Huh ?

Put a sword in an anvil with a silk touch book. Vanilla works.

 

As for modifying mob loot, use LivingDropsEvent.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.