Posted June 2, 20232 yr 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!
June 2, 20232 yr 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.
June 2, 20232 yr Author 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?
June 2, 20232 yr 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.
July 5, 20232 yr Author 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?
July 5, 20232 yr Author 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.