Jump to content

Recommended Posts

Posted (edited)

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.

Announcements



×
×
  • Create New...

Important Information

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