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
9 hours ago, 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👇

 

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.

Posted
2 hours ago, ChampionAsh5357 said:

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.

So what is the code for enchanting and where is the #accept?

Posted
3 hours ago, Shreyas R said:

So what is the code for enchanting

It's an nbt, so whatever the serialized nbt is. You can probably search it on the Internet. As for the helpers, there is EnchantmentUtils iirc.

3 hours ago, Shreyas R said:

where is the #accept?

Inside CreativeModeTabEvent$BuildContents. Make sure to check the tab you are adding to via #getTab.

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