-
-
Notifications
You must be signed in to change notification settings - Fork 406
Add ability to enchant an item at a specific level. #8113
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
base: dev/feature
Are you sure you want to change the base?
Add ability to enchant an item at a specific level. #8113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple minor thoughts+questions
@Since("2.0") | ||
@Description("Enchant or disenchant an existing item. Enchanting at a specific level will act as if an enchanting table " + | ||
"was used, and will apply the enchantments randomly chosen at that level. Treasure enchantments, like mending, can " + | ||
"optionally be allowed. Note that enchanting a book at a specific level will turn it into an enchanted book, rather " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to configure the book behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not :(
}; | ||
} | ||
case ENCHANT_AT_LEVEL -> { | ||
ItemFactory factory = Bukkit.getItemFactory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but can this be grabbed after the levels check?
} | ||
case ENCHANT_AT_LEVEL -> { | ||
ItemFactory factory = Bukkit.getItemFactory(); | ||
Number levelValue = level.getSingle(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe do getOptionalSingle
with -1
as the default value:
Number levelValue = level.getSingle(event); | |
int level = this.level.getOptionalSingle(event).orElse(-1).intValue(); |
Then you simply check level < 0
as you do now
Problem
There was no way of replicating the behavior of the vanilla enchanting table without hardcoding weights and chances manually.
Solution
Adds an option to EffEnchant to use ItemFactory#enchantWithLevels (available on paper 1.20.4+), which gives an itemstack a random set of appropriate enchants based on the given level, identical to the behavior of the enchanting table. I did not add the TagKey-based enchant limiting option as I didn't want to get into implementing the key set system and the only option to do it somewhat nicely seems to be reflection.
Testing Completed
manual confirmation

Supporting Information
Enchanting a book at a level returns an enchanted book instead. Support for those should also be added, but is out of scope of this PR.
Completes: none
Related: none