Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello.

I've created an enchantment, applied on Sword and wich give a poison effect to a entity when hitten with this sword.

In the code everything seems ok, but when I'm trying to put the enchantment on the Netherite sword, it says:

Netherite Sword cannot support that enchantment

Can someone help me to fix that problem ?

 

Here is the code:

 

EnchantmentInit Class:

 

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

    public static final RegistryObject<Enchantment> POISON_ENCHANT = ENCHANTMENTS.register("poison_enchant",()-> new PoisonEnchant(
            Enchantment.Rarity.COMMON,EnchantmentCategory.WEAPON,EquipmentSlot.MAINHAND));

    public static void register(IEventBus eventBus){
        ENCHANTMENTS.register(eventBus);
    }

}

PoisonEnchant Class:

public class PoisonEnchant extends Enchantment {

    public PoisonEnchant(Rarity rarity, EnchantmentCategory type, EquipmentSlot... slots) {
          super(rarity, type, slots);
     }



    @Override
    public int getMaxLevel() {
        return 6;
    }

    @Override
    public int getMinLevel() {
          return 1;
       }

    @Override
    public boolean canApplyAtEnchantingTable(ItemStack p_canApplyAtEnchantingTable_1_) {
          return false;
      }

    @Override
    public boolean isCurse() {
        return false;
    }




    @Override
    public boolean isAllowedOnBooks() {
         return false;
      }




    @Override
    public void doPostAttack(LivingEntity entity, Entity target, int level) {
        if(target instanceof LivingEntity){
            ((LivingEntity) target).addEffect(new MobEffectInstance(MobEffects.POISON));

        }

      }

}

Main Class:

    public main() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);

        IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
        EnchantementInit.register(bus);
    
        ModItems.ITEMS.register(bus);
        ModBlocks.BLOCKS.register(bus);



    }

Thanks for helping

Edited by Thanatos_0173
I solved the problem. Just put the enchantments class into the same package, and set PoisonEnchant on protected

  • Thanatos_0173 changed the title to [SOLVED]Cannot Support That Enchantment
Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.