Modernise enchantments#8668
Conversation
…xprEnchantmentOffer
thanks @SirSmurfy2! Co-authored-by: SirSmurfy2 <82696841+theabsolutionism@users.noreply.github.com>
…tments Co-authored-by: SirSmurfy2 <82696841+Absolutionism@users.noreply.github.com>
…edEnchantments" This reverts commit decd611, which was an incorrectly applied suggestion in GitHub UI.
APickledWalrus
left a comment
There was a problem hiding this comment.
Great work so far! Might be worth including https://jd.papermc.io/paper/26.1.2/org/bukkit/event/enchantment/EnchantItemEvent.html#getEnchantmentHint() which I don't think is covered yet.
| registry.register(SyntaxRegistry.CONDITION, PropertyCondition | ||
| .infoBuilder(CondItemEnchantmentGlint.class, PropertyType.HAVE, "enchantment glint (override:overrid(den|e))", "itemtypes") | ||
| .addPatterns(getPatterns(PropertyType.BE, "forced to [:not] glint", "itemtypes")) | ||
| .supplier(CondItemEnchantmentGlint::new).build()); |
There was a problem hiding this comment.
build calls should go on a new line 🙂
| """) | ||
| @RequiredPlugins("Spigot 1.20.5+") | ||
| @Since("2.10") | ||
| public class CondItemEnchantmentGlint extends PropertyCondition<ItemType> { |
There was a problem hiding this comment.
Missing override of getPropertyType
| glint = !parseResult.hasTag("not"); | ||
| return super.init(expressions, matchedPattern, isDelayed, parseResult); | ||
| if (!super.init(expressions, matchedPattern, isDelayed, parseResult)) return false; | ||
| override = parseResult.hasTag("override"); |
There was a problem hiding this comment.
I think the parse tags is kind of confusing behavior. Since this is a single syntax info now, you should be able to just check that matchedPattern is 0 or 1
| if (mode == ChangeMode.REMOVE || mode == ChangeMode.REMOVE_ALL || mode == ChangeMode.RESET) | ||
| return null; | ||
| return CollectionUtils.array(Number.class, Experience.class); |
There was a problem hiding this comment.
Why the removal of Experience? Is this functionality preserved in a different way?
There was a problem hiding this comment.
Yes, via the converter
There was a problem hiding this comment.
I see a Comparator but not a Converter. Is it located outside of the module?
There was a problem hiding this comment.
I saw some other classes still had their converters registered here rather than in the relevant module, should I move the registration to the module?
There was a problem hiding this comment.
Since it isn't exclusively related to enchanting, you can keep it where it is for now.
| set the level of sharpness of the player's tool to {_maximum} | ||
| """) | ||
| @Since("INSERT VERSION") | ||
| public class ExprMaximumEnchantmentLevel extends SimplePropertyExpression<Enchantment, Integer> { |
There was a problem hiding this comment.
I might combine this with ExprMinimumEnchantmentLevel
There was a problem hiding this comment.
I thought about that, but wasn't sure what to call it... ExprExtremumEnchantmentLevel? ExprMinMaxEnchantmentLevel? It feels like if I were looking for the class later for minimum or maximum enchantment level, two separate classes would be easier to find
There was a problem hiding this comment.
I think ExprMinMaxEnchantmentLevel is fine and fits with other cases. Can always use the docs to find the relevant implementation class too 😉
| new TagModule(this), | ||
| new TextModule(this) | ||
| new TextModule(this), | ||
| new EnchantmentModule(this) |
There was a problem hiding this comment.
Should be ordered alphabetically in the list
…and ExprEnchantingExpCost
…dItemEnchantmentGlint
Problem
The current enchantment syntaxes are not yet migrated to the new module-based registration system, and their code is in many places out of date both in style and in logic.
Solution
This PR adds a new module for syntaxes related to enchantments, moves the existing syntaxes to the new module, improves their code style and flow and implements three new syntaxes:
Testing Completed
There is a new unit test for stored enchantments. I ran
quickTestto ensure that my changes don't break any of the existing tests.Supporting Information
I would appreciate if people with scripts that use these syntaxes extensively could test to make sure they still work identically to how they were before.
Completes: none
Related: none
AI assistance: Gemini 3.1 Pro was used to evaluate human-made changes