Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Allow change max level enchanting behaviour in anvil using AnvilView

Open Doc94 opened this issue 1 year ago • 2 comments

This PR allow change the behaviour in anvils where enchantments applied are limited to the max level registered.

Code to test a case where only books can override the max level limit.

    @EventHandler
    public void onAnvilPrepare(PrepareAnvilEvent event) {
        final AnvilView anvilView = event.getView();
        final ItemStack itemStackIngredient = anvilView.getItem(1);
        if (itemStackIngredient == null || itemStackIngredient.isEmpty()) {
            return;
        }
        if (itemStackIngredient.getType() == Material.ENCHANTED_BOOK) {
            event.getView().setCanApplyEnchantmentsOverMaxLevel(true);
        } else {
            event.getView().setCanApplyEnchantmentsOverMaxLevel(false);
        }
    }

PS: This PR is an alternative from https://github.com/PaperMC/Paper/pull/11472

Doc94 avatar Oct 06 '24 19:10 Doc94

setCanApplyEnchantmentsOverMaxLevel

the name is too long....

Maybe ignoresEnchantmentMaxLevel() and ignoresEnchantmentMaxLevel(value)?

masmc05 avatar Oct 06 '24 19:10 masmc05

setCanApplyEnchantmentsOverMaxLevel

the name is too long....

Maybe ignoresEnchantmentMaxLevel() and ignoresEnchantmentMaxLevel(value)?

i wanna the method being a little explain about what can do (or maybe just a thing for docs) because ignoresEnchantmentMaxLevel sounds like a ignore the level not the "limit" or clamp... but still not sure about the names...

Doc94 avatar Oct 06 '24 19:10 Doc94

bypassEnchantmentLevelRestriction(boolean) ? I 100% agree with masjson tho, that name is not something I'd be interesting in merging as it is giving some strong spigot vibes xD

lynxplay avatar Oct 09 '24 13:10 lynxplay

bypassEnchantmentLevelRestriction(boolean) ? I 100% agree with masjson tho, that name is not something I'd be interesting in merging as it is giving some strong spigot vibes xD

im not good for names :c

but bypassEnchantmentLevelRestriction sounds a good method name and the docs talks more about how this means to the max level then i think can work (and can allow users again use that custom books)

Doc94 avatar Oct 09 '24 13:10 Doc94