Open Verox001 opened 1 year ago
Hello @Verox001
we need more information to be able to solve the problem like for example your custom NamespaceId or even an in-game image and your code it can be useful
public class Stabilization extends Enchantment {
public Stabilization() {
super(new Identifier("cc:stabilization"), "Stabilization", Rarity.UNCOMMON, EnchantmentType.SWORD);
}
@Override
public int getMaxLevel() {
return 5;
}
@Override
public boolean canEnchant(@NotNull Item item) {
Plugin.getInstance().getLogger().info(item.getNamespaceId());
Plugin.getInstance().getLogger().info(item.getNamespaceId().equals("cc:boomerang") ? "true" : "false");
return item.getNamespaceId().equals("cc:boomerang");
}
@Override
public int getMaxEnchantAbility(int level) {
return this.getMinEnchantAbility(level) + 20;
}
@Override
public int getMinEnchantAbility(int level) {
return 8 * level - 7;
}
}
This is my code for the enchantment class and this is how I register it in the onLoad method:
Enchantment.register(new Stabilization(), true);
And here is an image that only one enchantment level book has been registered:
And here is an image of trying to enchant a unechanted boomerang with Stabilization 1 (It doesn't work either. canEnchant
doesn't even get called):
@AzaleeX Could you have a look at this please?
By using the Enchantment#register method and setting the second argument (registerItem) to true, doesn't register ALL enchantment books correctly. Even though having an enchantment with MaxLevel 5, it only registers the book for level one.
Why does this happen?
The reason may be that all custom registered books use the same NamespaceId of the Enchantment, which results in all other enchantment books after level one not being registered, since there already is one with the same NamespaceId registered. https://github.com/PowerNukkitX/PowerNukkitX/blob/1dfc7db755ecd638366d65caf4c1c179817841da/src/main/java/cn/nukkit/item/enchantment/Enchantment.java#L367
I created my own EnchantmentBook classes with unique NamespaceIds and it worked like a charm.
📋 Debug information