Attribute controls: 1.21 + old version fixes #2765
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Additions
AttributeUtilclass with all the attribute-related util methods, as they were spread around across a couple of property classes and it started getting a little messy.AttributeUtil#addToMap- converts a list of modifiers into aListTagand adds it into a map under an attribute key. On older versions, this is the Spigot attribute name, while on 1.21+ this is the Minecraft namespaced key name + an extra key->value with the legacy Spigot name if legacy spigot name support is enabled.AttributeUtil#parseModifiers- a generic utility method for parsing attributes and their modifiers from a map & handling both modern and legacy names in the map if legacy spigot names support is on. Used by both item and entity properties.AttributeUtil#modifierToMap- now only addsidandkeyifincludeDeprecatedis true, as both of these are replaced bykeynow.Changes
EntityAttributeModifiers#mapify) toAttributeUtil, renamed some to have clearer naming, and changed existing code to useAttributeUtilmethods.boolean includeDeprecated, for both attribute names and modifier values to be calculated with.ItemAttributeModifiersnow overridesgetTagValue, to include deprecated values for tag usage and exclude them from the property value.Note
There's one niche use case I could think of that might break from this behavior? something like
<[item].attribute_modifiers.with[legacy_name].as[new_value]>on an item that already has that attribute may get overridden by the modern attribute in the map?We could make it prioritize legacy names over modern names, but idk if that'd be worth it - personally I'd rather focus on modern naming rather than legacy for this, specifically since this is fairly niche, but lmk what do you think.