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

Replace ItemStack with ItemType #2510

Closed
wants to merge 87 commits into from

Conversation

Whimsyturtle
Copy link
Member

@Whimsyturtle Whimsyturtle commented Oct 4, 2019

Description

This PR replaces ItemStacks with ItemTypes in conditions, effects, and expressions where possible.

The search criteria I used was:

  1. Expression contains "itemstack" or "itemstacks" only (I ignored expressions with "itemtype/itemstack")
  2. Class doesn't already use ItemType in parsing, conditionals, etc. (Since if it did, then I'm probably screwing with it by modifying it)

Please help me review my changes :)


Target Minecraft Versions: Any
Requirements: None
Related Issues: #2151, #2162, #2175, potentially more issues

@Whimsyturtle Whimsyturtle added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Oct 9, 2019
@bensku
Copy link
Member

bensku commented Oct 21, 2019

This needs extensive testing. A syntax test for each changed class would be best, but that is a lot of work. I'll try to help with this one, because IMO it is very important to get rid of ItemStacks.

if (e instanceof CraftItemEvent)
return ((CraftItemEvent) e).getRecipe().getResult();
return e.getCurrentItem();
return new ItemType(((CraftItemEvent) e).getRecipe().getResult());
Copy link
Member

Choose a reason for hiding this comment

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

This is a rather confusing behaviour now that I see it, it might make sense for the pre-craft and craft events but not for the inventory click event itself.

@bensku may I ask why didn't you just create an event value for the ItemCraftEvent?

This isn't related to the PR itself anyways, I am just stating it here so we don't forget it in the future.

@Whimsyturtle
Copy link
Member Author

Whimsyturtle commented Jan 6, 2020

Ok, here is the comprehensive list of changes made:

CondIsBlock

Assertions

  • Air
  • Block
  • Item

CondIsEdible

Assertions

  • Air
  • Block
  • Non-edible item
  • Edible items

CondIsFlammable

Assertions

  • Air
  • Flammable block
  • Non-flammable block
  • Item

CondIsSolid

Assertions

  • Air
  • Block
  • Item

CondIsTransparent

Assertions

  • Air
  • Non-transparent block

Special Note

  • The Spigot transparent material list is incomplete, so some blocks that are supposed to be transparent, e.g. barriers and glass blocks are wrongly reported as being non-transparent. As such, I've removed the invalid example used in the class and added a notice on this issue.

EffEnchant

Assertions

  • Non-existent enchant is not set
  • Application of enchant
  • Application of new enchant on item
  • Disenchanting

EffHealth

Assertions (Items)

  • New item durability
  • Post-damage durability
  • Post-repair durability

Special Notes

  • While rewriting the code for EffHealth, I noticed that the entity damage functionality of EffHealth is actually wrong (HealthUtils is calling e.damage() instead of setHealth(), as is being used for the HealthUtils heal() function - resulting in entity health not being properly updated when damaging mobs for 0.5 health).
  • I also took the time to optimize HealthUtils (remove un-necessary Math2.fit() calls), as well as EffHealth (cast Object -> LivingEntity once instead of literally everywhere it's needed).

Assertions (Mobs)

  • New mob health
  • Integer damage amount
  • Decimal damage amount
  • Overkill damage amount is rounded down
  • Integer heal amount
  • Decimal heal amount
  • Fully heal amount is rounded down

EffReplace

Assertions

  • Replace existing item completely
  • Item amount of replaced items are preserved
  • Replacing non-existent item results in no variable change

Special Note

  • For some reason looping all items in the inventory variable threw a SkriptAPIException. I removed the check for it and it seems to not break anything, although your verification would be good - @bensku (the error was just "", so I wasn't too sure on what to make of that).

ExprBookAuthor

Assertions

  • New book's book author is not set
  • Book author name setting (with Unicode and lowercase/uppercase)

ExprBookPages

Assertions

  • New book's book pages are not set

Special Note

  • I did not do a setting assertion for this because it is currently impossible to set a book's pages in a script alone currently.

ExprBookTitle

Assertions

  • New book's title is not set
  • Book title setting (with Unicode and lowercase/uppercase)

Special Note

  • I fixed the expression pattern failing for book title, since the pattern's bracket was misplaced.

ExprItemAmount

Assertions

  • New item's item amount is 1
  • Regular item amount
  • Over-capacity item amount
  • Zero item amount

ExprMaxStack

Assertions

  • Diamond sword stack size
  • Bucket stack size
  • Dirt stack size

@Whimsyturtle Whimsyturtle requested a review from bensku January 6, 2020 05:12
@bensku
Copy link
Member

bensku commented Jan 10, 2020

Looks good to me. I reorganized tests a bit, plus removed check for air blockiness (it is NOT a block on some MC versions).

@Whimsyturtle
Copy link
Member Author

Closing since this issue is merged :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants