Skip to content
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

Closed

Conversation

AyhamAl-Ali
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali commented Oct 15, 2021

Description

This PR does the following:

  • Added support for stored enchantments for enchanted book to CondIsEnchanted, ExprEnchantments and EffEnchant classes
  • Added new expression %itemtypes% (with|of) [stored] [enchant[ment[s]]] %enchantmenttypes%
  • Added disenchanting specific enchantments
  • Also fixes (dis)enchanting multiple itemtypes causes severe error due to not handling it at all
  • Added related methods to ItemType class
  • Added has conflicting enchantments condition
  • 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 caused this check if 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 reverted

NOTE: 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:

- 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)
@AyhamAl-Ali
Copy link
Member Author

Might be good to add #4245 and #1234 as well

@TPGamesNL TPGamesNL added enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature. labels Oct 16, 2021
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
Copy link
Member

@APickledWalrus APickledWalrus left a 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

AyhamAl-Ali and others added 2 commits March 5, 2022 16:12
Co-authored-by: APickledWalrus <apickledwalrus@gmail.com>
@AyhamAl-Ali AyhamAl-Ali changed the title 🚀 Support stored enchantments 🚀 Enchantment Improvements Mar 12, 2022
…antments.java

Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
@TheLimeGlass TheLimeGlass added the bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. label Mar 17, 2023
Copy link
Contributor

@TheLimeGlass TheLimeGlass left a 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/aliases/ItemType.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/aliases/ItemType.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/aliases/ItemType.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/effects/EffEnchant.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/effects/EffEnchant.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/effects/EffEnchant.java Outdated Show resolved Hide resolved
AyhamAl-Ali and others added 5 commits March 17, 2023 16:18
Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com>
Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com>
@AyhamAl-Ali AyhamAl-Ali marked this pull request as draft April 22, 2023 00:04
@Moderocky Moderocky force-pushed the master branch 2 times, most recently from bd134d0 to 3f08853 Compare September 16, 2023 16:59
@AyhamAl-Ali AyhamAl-Ali changed the base branch from master to dev/feature April 5, 2024 14:50
@AyhamAl-Ali AyhamAl-Ali marked this pull request as ready for review April 5, 2024 16:01
@AyhamAl-Ali AyhamAl-Ali requested a review from TheLimeGlass April 5, 2024 17:20
Copy link
Member

@APickledWalrus APickledWalrus left a 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,
Copy link
Member

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)
Copy link
Member

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()?

Comment on lines +1363 to +1366
if (meta == null)
return false;
if (!meta.hasStoredEnchants())
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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())
Copy link
Member

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,
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"%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

Comment on lines +72 to +73
if (item.getEnchantmentStorageMeta() != null)
item.addStoredEnchantments(enchantments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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

Comment on lines +76 to +77
if ((isStored && meta instanceof EnchantmentStorageMeta)) {
return ((EnchantmentStorageMeta) meta).hasConflictingStoredEnchant(ench);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "the " + (isStored ? "stored " : "") + "enchantments of " + items.toString(event, debug);
return (isStored ? "stored " : "") + "enchantments of " + items.toString(event, debug);

@sovdeeth
Copy link
Member

Closing due to inactivity. Re-open if you're interested in taking it over, anyone can!

@sovdeeth sovdeeth closed this Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. enhancement Feature request, an issue about something that could be improved, or a PR improving something. feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants