Jump to content

Recommended Posts

Posted

 Hello, I've been trying to do this for the past 3 days with no luck馃槕 So what I'm trying to do is to add sharpness to a custom sword I made and this is my code馃憞

package com.shreyas.exmod.item.custom;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments;


public class DivineExcaliburItem extends SwordItem {
    public DivineExcaliburItem(Tier tier, int i, float v, Properties properties) {
        super(tier, i, v, properties);
    }

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

    @Override
    public boolean isFoil(ItemStack ignored) {
        return false; // never looks enchanted
    }
    
}

And I have no idea how to add the echant to it. Thanks in advance!

Posted
  On 6/2/2023 at 3:13 AM, Shreyas R said:

 Hello, I've been trying to do this for the past 3 days with no luck馃槕 So what I'm trying to do is to add sharpness to a custom sword I made and this is my code馃憞

 
Expand  

To add it in the creative menu, you have to apply the enchantment before passing it through #accept. To have it on craft, you need to add the enchantment to the resulting nbt.

  • 1 month later...
Posted

So I had a question and I just got from India jet lack... So anyways If you have it to enchant on craft does that also mean that it would be enchanted in the creative menu?

Posted

This is the version I'm using net.minecraftforge:forge:1.19-41.1.0 and it doesn't have the CreativeModeTabEvent$BuildContents class and the EnchantmentUtils class.

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.