Jump to content

How to add a custom enchantment for a custom item?


Recommended Posts

I'm trying to add a custom enchantment that is only compatible with a new type of tiered weapon I made.

I am using 1.19.3, forge version 44.0.1.

I tried using EnchantmentCategory#create(), but it doesn't work.

Here is the enchantment class:

package everyblu.extendedarmory.common.enchantments;

import everyblu.extendedarmory.common.item.LongswordItem;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import org.jetbrains.annotations.NotNull;

public class ThrustingEnchantment extends Enchantment {
    static EnchantmentCategory LONGSWORD_TYPE = EnchantmentCategory.create("thrusting", item -> item instanceof LongswordItem);
    public ThrustingEnchantment() {
        super(Rarity.RARE, LONGSWORD_TYPE, new EquipmentSlot[]{EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND});

    public int getMaxLevel() {
        return 3;

    public void doPostAttack(@NotNull LivingEntity attacker, @NotNull Entity target, int tier) {
        if (attacker.getLevel().isClientSide()) {
            ClientLevel level = ((ClientLevel) attacker.getLevel());

            if (tier >= 1)
                level.addParticle(ParticleTypes.SONIC_BOOM, target.position().x,target.position().y, target.position().z, 0, 0, 0);
			//This part is not finished.

Here is my enchants init class:

package everyblu.extendedarmory.common.register;

import everyblu.extendedarmory.ExtendedArmory;
import everyblu.extendedarmory.common.enchantments.CutlassLuckEnchantment;
import everyblu.extendedarmory.common.enchantments.ThrustingEnchantment;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModEnchants {
    public static final DeferredRegister<Enchantment> ENCHANTMENTS =
            DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, ExtendedArmory.MODID);

    public static RegistryObject<Enchantment> Thrusting = ENCHANTMENTS.register("thrusting", ThrustingEnchantment::new);
    public static RegistryObject<Enchantment> CutlassLuck = ENCHANTMENTS.register("cutlassluck", CutlassLuckEnchantment::new);

    public static void register(IEventBus eventBus) {


Link to comment
Share on other sites

  • 1 month later...

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.

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.