-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
🚀 Enchantment Improvements #4366
Conversation
- Support added to CondIsEnchanted, ExprEnchantments and EffEnchant classes - Added new expr to return itemtypes with stored enchantments - Also fixes (dis)enchanting multiple itemtypes causes severe error due to not handling it at all - Added related methods to ItemType class - Changed behavior of "ItemType#hasEnchantments" level check to !- instead of < (this should be strict and level expression should be the way to check with math)
This should return a single item so it can work with other item related expressions or upgrade other expressions to support %itemtypes% but that's not really needed
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.
Some things I noticed on my first pass
Good feature PR :D
src/main/java/ch/njol/skript/conditions/CondHasConflictingEnchantments.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/conditions/CondHasConflictingEnchantments.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/conditions/CondHasConflictingEnchantments.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprItemWithEnchantments.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprItemWithEnchantments.java
Outdated
Show resolved
Hide resolved
Co-authored-by: APickledWalrus <apickledwalrus@gmail.com>
…antments.java Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
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.
Can tests be added to this? There were multiple issues relating to this. Some regression tests are needed.
src/main/java/ch/njol/skript/expressions/ExprItemWithEnchantments.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/expressions/ExprItemWithEnchantments.java
Outdated
Show resolved
Hide resolved
Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com>
Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com>
bd134d0
to
3f08853
Compare
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.
looking forward to this feature 😎
public class CondHasConflictingEnchantments extends Condition { | ||
|
||
static { | ||
PropertyCondition.register(CondHasConflictingEnchantments.class, PropertyType.HAVE, |
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.
What do you think about a "can be enchanted with" condition? Do you think that reflects the property well?
*/ | ||
public EnchantmentType @Nullable [] getStoredEnchantmentTypes() { | ||
EnchantmentStorageMeta meta = getEnchantmentStorageMeta(); | ||
if (meta == null) |
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 also check !meta.hasStoredEnchants()
?
if (meta == null) | ||
return false; | ||
if (!meta.hasStoredEnchants()) | ||
return false; |
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.
if (meta == null) | |
return false; | |
if (!meta.hasStoredEnchants()) | |
return false; | |
if (meta == null || !meta.hasStoredEnchants()) | |
return false; |
assert type != null; // Bukkit working different from what we expect | ||
if (!meta.hasStoredEnchant(type)) | ||
return false; | ||
if (enchantment.getInternalLevel() != -1 && meta.getStoredEnchantLevel(type) != enchantment.getLevel()) |
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.
-1 represents an enchantment type without a specific level (e.g. it has any level of X stored) right?
Maybe we should move this into a public field on EnchantmentType with docs. Or maybe better, a method like representsAnyLevel
(we could come up with a better name lol)
public class CondIsEnchanted extends Condition { | ||
|
||
static { | ||
PropertyCondition.register(CondIsEnchanted.class, "enchanted [with %-enchantmenttype%]", "itemtypes"); | ||
Skript.registerCondition(CondIsEnchanted.class, |
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 wonder if we should support item has enchantment <enchantment>
|
||
static { | ||
Skript.registerExpression(ExprItemWithEnchantments.class, ItemType.class, ExpressionType.COMBINED, | ||
"%itemtype% (with|of) [:stored] [enchant[ment[s]]] %enchantmenttypes%"); // Added support for non-stored enchantments, check https://github.com/SkriptLang/Skript/issues/1836 |
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.
"%itemtype% (with|of) [:stored] [enchant[ment[s]]] %enchantmenttypes%"); // Added support for non-stored enchantments, check https://github.com/SkriptLang/Skript/issues/1836 | |
"%itemtype% (with|of) [:stored] [enchant[ment[s]]] %enchantmenttypes%"); |
I don't think it needs linked in this case
if (item.getEnchantmentStorageMeta() != null) | ||
item.addStoredEnchantments(enchantments); |
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.
if (item.getEnchantmentStorageMeta() != null) | |
item.addStoredEnchantments(enchantments); | |
item.addStoredEnchantments(enchantments); |
looks like the ItemType method should handle this internally
assert enchantments of {_item} is not set with "enchanting effect failed test ##1" | ||
|
||
enchant {_item} with sharpness 3 | ||
assert enchantment level of sharpnees on {_item} is 3 with "enchanting effect failed test ##2" |
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.
assert enchantment level of sharpnees on {_item} is 3 with "enchanting effect failed test ##2" | |
assert enchantment level of sharpness on {_item} is 3 with "enchanting effect failed test ##2" |
assert enchantment level of sharpnees on {_item} is 3 with "enchanting effect failed test ##2" | ||
|
||
enchant {_item} with sharpness 2 | ||
assert enchantment level of sharpnees on {_item} is 2 with "enchanting effect failed test ##2" |
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.
assert enchantment level of sharpnees on {_item} is 2 with "enchanting effect failed test ##2" | |
assert enchantment level of sharpness on {_item} is 2 with "enchanting effect failed test ##2" |
|
||
static { | ||
Skript.registerExpression(ExprItemWithEnchantments.class, ItemType.class, ExpressionType.COMBINED, | ||
"%itemtype% (with|of) [:stored] [enchant[ment[s]]] %enchantmenttypes%"); // Added support for non-stored enchantments, check https://github.com/SkriptLang/Skript/issues/1836 |
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.
thoughts on a pattern instead like %itemtype% (with|of) [enchant[ment[s]]] %enchantmenttypes% [:stored]
as in dirt with sharpness stored
if ((isStored && meta instanceof EnchantmentStorageMeta)) { | ||
return ((EnchantmentStorageMeta) meta).hasConflictingStoredEnchant(ench); |
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.
if ((isStored && meta instanceof EnchantmentStorageMeta)) { | |
return ((EnchantmentStorageMeta) meta).hasConflictingStoredEnchant(ench); | |
if (isStored && meta instanceof EnchantmentStorageMeta enchantmentStorageMeta) { | |
return enchantmentStorageMeta.hasConflictingStoredEnchant(ench); |
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return PropertyCondition.toString(this, PropertyType.HAVE, event, debug, items, | ||
"conflicting " + (isStored ? "stored " : "") + "enchantments with " + ench.toString(event, debug)); |
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.
"conflicting " + (isStored ? "stored " : "") + "enchantments with " + ench.toString(event, debug)); | |
"conflicting " + (isStored ? "stored " : "") + "enchantments with " + ench.toString(event, debug)); |
public String toString(@Nullable Event e, boolean debug) { | ||
return "the enchantments of " + items.toString(e, debug); | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "the " + (isStored ? "stored " : "") + "enchantments of " + items.toString(event, debug); |
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.
return "the " + (isStored ? "stored " : "") + "enchantments of " + items.toString(event, debug); | |
return (isStored ? "stored " : "") + "enchantments of " + items.toString(event, debug); |
Closing due to inactivity. Re-open if you're interested in taking it over, anyone can! |
Description
This PR does the following:
stored enchantments
for enchanted book to CondIsEnchanted, ExprEnchantments and EffEnchant classes%itemtypes% (with|of) [stored] [enchant[ment[s]]] %enchantmenttypes%
has conflicting enchantments
conditionItemType#hasEnchantments
level check to!=
instead of<
(this should be strict and level expression should be the way to check with math) - (this caused this checkif player's tool is enchanted with unbreaking 1
to be true when player's tool has unbreaking 2`) Let me know if you want this to be revertedNOTE: I couldn't find a good syntax for the new changes so if anyone have a better syntax let me know.
Target Minecraft Versions: All
Requirements: None
Related Issues: