Jump to content

[1.19.4, SOLVED] Force compatibility with vanilla enchantments on custom weapon


LeeCrafts

Recommended Posts

I have a weapon that extends CrossbowItem. I made its projectiles able to destroy certain blocks, but I wonder if I can make the weapon compatible with the Silk Touch enchantment--so that those destroyed blocks can drop themselves. (Of course I would have to code the logic myself after checking if the weapon has the enchantment.)

How do I do this? It seems like Silk Touch is of the "DIGGER" category, and only items extending DiggerItem (aka not my weapon) are naturally compatible with that enchantment.

Edited by LeeCrafts
Link to comment
Share on other sites

8 hours ago, LeeCrafts said:

How do I do this? It seems like Silk Touch is of the "DIGGER" category, and only items extending DiggerItem (aka not my weapon) are naturally compatible with that enchantment.

Override `Item#canApplyAtEnchantingTable` on your extended item. I will note that the enchantment has to be on whatever item the projectile hits to apply to the loot table.

  • Thanks 1
Link to comment
Share on other sites

Thank you! Here is my overridden method:

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
    return enchantment == Enchantments.SILK_TOUCH || super.canApplyAtEnchantingTable(stack, enchantment);
}

 

Link to comment
Share on other sites

  • LeeCrafts changed the title to [1.19.4, SOLVED] Force compatibility with vanilla enchantments on custom weapon

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.