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