Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vanilla parity on enchantable items with no targets #11896

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Y2Kwastaken
Copy link

@Y2Kwastaken Y2Kwastaken commented Jan 4, 2025

This pull request fixes #11821

Previously after the enchantment event took place bukkit would clear out all empty enchantments and send a completely empty offer list to the client. Minecraft handles this differently by default by still sending a cost to the client so the slots illuminate as seen in the attached issue.

This pull request attempts to address this issue by not setting back enchantment offer cost to 0 after PrepareItemEnchantEvent. This keeps the original price that was generated through the loop earlier within the slotsChanged method.

As far as drawbacks go for this fix after looking into this it would largely be thinking about how things are handled event side, because something would need to be done. If a developer wants to null out a spot how do we address this while maintaining vanilla behavior when an item may have no offers available? Or should vanilla behavior be kept to start with?

For reference when blanking out all 3 offers an enchanment table now looks like this, client side the hover shows no enchantment names, however displays all levels.

    @EventHandler
    fun onEnchant(event: PrepareItemEnchantEvent) {
        for (index in event.offers.indices) {
            event.offers[index] = null
        }
    }

image

within default vanilla behavior as far as I'm aware there is no scenario where three enchantments aren't sent.

@Y2Kwastaken Y2Kwastaken requested a review from a team as a code owner January 4, 2025 02:38
@Machine-Maker
Copy link
Member

Yeah, this is just a fundamental problem with how EnchantmentOffer is structured. It should've never been nullable in the array and instead had a nullable enchantment so the cost could still be set. I think it's fine to just revert to handle it like vanilla.

@kennytv kennytv added the type: bug Something doesn't work as it was intended to. label Jan 5, 2025
@lynxplay
Copy link
Contributor

lynxplay commented Jan 6, 2025

Is there maybe a point in only yanking the cost if the cost wasn't present pre-event call? To allow the native vanilla layout for enchantable items without breaking plugins that actively want the offer to not be sent?

Given this API will just need to be deprecated anyway, a bit of salvaging might be worth minimal breakage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something doesn't work as it was intended to.
Projects
Status: PR Party candidate
Development

Successfully merging this pull request may close these issues.

Enchantable Component
4 participants