Jump to content

[1.21] Allowing vanilla enchantments on custom items


CodyRupp

Recommended Posts

Hi, I created a custom tool that extends the DiggerItem class, but I am unable to give it enchantments as with other tools. For example, when I try to use the /enchant command, it says that my item "cannot support that enchantment". Similarly, the anvil does not allow me to add book enchantments to the item. I have tried overwriting the methods relating to enchantments, as shown below. What are the steps that I need to take to enable vanilla enchantments on my custom tool?

Current code:

public class MyItem extends DiggerItem {

    public MyItem(Tier tier, Properties pProperties) {
        super(tier, MyTags.Blocks.MINEABLE_WITH_MYITEM, pProperties);
    }

    @Override
    public boolean canPerformAction(ItemStack stack, ToolAction toolAction) {
        return true;
    }

    @Override
    public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
        return true;
    }

    @Override
    public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
        return true;
    }

    @Override
    public boolean isEnchantable(@SuppressWarnings("null") ItemStack pStack) {
        return true;
    }
}

 

Link to comment
Share on other sites

23 minutes ago, JuSTGh0sT1242 said:

why do you need DiggerItem, just use Pickaxe/AxeItem etc.

I'm making an all-in-one tool, so I figured it would be best to extend DiggerItem and then implement the functionality of each integrated tool in my item's class.

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.

Announcements



×
×
  • Create New...

Important Information

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