-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
ExprItemAttribute (+ ExprEntityAttribute clean-up) #5301
base: dev/feature
Are you sure you want to change the base?
Conversation
Nice PR! ⚡ Just a quick note we don't use the keyword |
This looks good, but I do have a few issues with it.
static {
register(ExprItemAttribute.class, Number.class, "attribute [value] [(in|of|for) [the] (1:main[ ]hand|2:off[ ]hand|3:boot[s]|3:shoe[s]|4:leg[ging][s]|5:chestplate[s]|6:helm[et][s]) [slot]]", "itemtypes");
}
private Expression<Attribute> attributes;
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
attributes = (Expression<Attribute>) exprs[matchedPattern];
setExpr((Expression<ItemType>) exprs[matchedPattern ^ 1]);
if (parseResult.mark != 0)
equipmentSlot = EquipmentSlot.values()[parseResult.mark - 1];
return true;
} I see this attributes = (Expression<Attribute>) exprs[matchedPattern]; Yet it's not in the expression (pattern) anywhere
All this being said, It is a good PR, I just feel like it is missing some important things. |
These are all issues that need to be tested thoroughly, that's why the pull request is currently a draft. I'll make sure to look into each remark.
I take all three operations into account when calculating the modifier but decided against adding support to add specific operations to the changers for now to avoid complexity. I personally do not find them useful and if easy to add later on, I'll add them.
Yes, this was an oversight. I already fixed it but forgot to push.
Was thinking the same thing but Skript does not want to build on my computer so I'm having issues testing this PR at the moment. Will adress this if it creates issues. |
bd134d0
to
3f08853
Compare
Do you still intend to work on this PR? |
Not at the moment. Someone can take over or close this pull request, unless there are no plans to create a new one. In that case, you can leave this open. I might complete this when I have time in the next few weeks if no one takes over. |
Thanks for the quick response. I'll leave it open in that case. |
# Conflicts: # src/main/java/ch/njol/skript/expressions/ExprEntityAttribute.java
I reworked the whole system because I didn't think it was satisfying to use. This required one compromise which adds a new
I still have some design questions that I'm not sure of:
Even though I didn't add any unit testing, I did test the pull request thoroughly on my private server. Everything seems to work as planned. Not sure though what the procedure is for that. |
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.
I much prefer this to the version I've been working on, looks really good! Just some small things here and there that I noticed on a real quick first glance.
sb.append("off hand"); | ||
break; | ||
case FEET: | ||
sb.append("feet"); |
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.
I feel like this should also have slot
, like the other armour cases.
|
||
@Name("Attribute Modifier") | ||
@Description({ | ||
"Certain items can have attribute modifiers, which are used to modify the attributes of the item.", |
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.
I think technically the attribute modifiers don't modify the attributes of the item, but the attributes of the holder/wearer.
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.
They can only be applied to the items but indeed change the attributes of the wearer. I will make a better description.
"Certain items can have attribute modifiers, which are used to modify the attributes of the item.", | ||
"An attribute modifier has a name, a value, and optionally an operation, and an equipment slot.", | ||
"An operation can be either additively scaling, multiplicatively scaling, or a plain addition.", | ||
"See <a href=\"https://minecraft.fandom.com/wiki/Attribute#Operations\">the Minecraft wiki</a> for more information.", |
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.
Should this point to the minecraft.wiki page instead of the fandom one?
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.
I was also hesitating adding an 'unofficial' source to the documentation. I'll search for it on the official wiki as well.
ExprAttributeModifier.class, | ||
AttributeModifier.class, | ||
ExpressionType.COMBINED, | ||
"[a] [new] [(plain|add:additive[[ly] scaling]|mult:multiplicative[[ly] scaling])] attribute [modifier] (named|with name[s]) %string% (and|with) value %number% [and] [(in|of|for) [the] (1:main[ ]hand|2:off[ ]hand|3:boot[s]|3:shoe[s]|4:leg[ging][s]|5:chestplate[s]|6:helm[et][s]) [slot]]" |
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.
Maybe add amount
as an option with value
?
"[a] [new] [(plain|add:additive[[ly] scaling]|mult:multiplicative[[ly] scaling])] attribute [modifier] (named|with name[s]) %string% (and|with) value %number% [and] [(in|of|for) [the] (1:main[ ]hand|2:off[ ]hand|3:boot[s]|3:shoe[s]|4:leg[ging][s]|5:chestplate[s]|6:helm[et][s]) [slot]]" | |
"[a] [new] [(plain|add:additive[[ly] scaling]|mult:multiplicative[[ly] scaling])] attribute [modifier] (named|with name[s]) %string% (and|with) (value|amount) %number% [and] [(in|of|for) [the] (1:main[ ]hand|2:off[ ]hand|3:boot[s]|3:shoe[s]|4:leg[ging][s]|5:chestplate[s]|6:helm[et][s]) [slot]]" |
register( | ||
ExprItemAttributeModifiers.class, | ||
AttributeModifier.class, | ||
"%attributetype% attribute[s] [modifier[s]]", |
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.
Would being able to get the all attribute modifiers on an item be something useful?
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.
Not really, since they hide information on the attribute type they were assigned to.
I'd like to see less required information when creating a modifier, and for the options to be spread out over a few expressions instead of all in one.
turns into
|
I get where you're coming from but I'm not sure if this is the right approach. AttributeModifier is effectively an immutable data type, which means that these expressions would create a new instance each time they're changed. I honestly don't know what Skript's conventions are on these things, but this could lead to issues if someone would change the modifier. Do they expect the items, to which the modifier has been applied, to have the changes of the modifier as well? Either way, if others agree with adding multiple expressions, I have nothing against it really, but this would require somewhat weird changer shenanigans because the data type of the AttributeModifier expression itself is immutable. |
Yeah I'd expect modifiers would be copy-only for the most part, meaning lots of recreation. For the user, though, this isn't really an issue outside of changing a modifier already on an item. If we can't easily work around it, I suppose this is fine, but I think there's a path forward where we could hide that complexity from the user without too much effort. Note that we could also make an attribute wrapper class that just builds a final modifier when applied to an item, too. |
Description
First of all, this pull request cleans up the ExprEntityAttribute class and adds a small additional syntax option. The class was vulnerable for A LOT of NullPointerExceptions if I'm not mistaken, so that should be fixed now.
EDIT: See latest comment for up-to-date information.
It also adds the new ExprItemAttribute that can be used to change the attributes of items.
EquipmentSlot
.Marked as a draft because a lot of testing is needed and I'm currently having problems building the JAR. The code is also sometimes a bit hacky because Spigot's API for item attributes is not that in-depth.
I'm also looking for opinions on the syntax and the general implementation.
Target Minecraft Versions: any
Requirements: N/A
Related Issues: #3734