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

Active Item API #5365

Merged
merged 48 commits into from
Dec 19, 2023
Merged

Active Item API #5365

merged 48 commits into from
Dec 19, 2023

Conversation

sovdeeth
Copy link
Member

@sovdeeth sovdeeth commented Jan 19, 2023

Description

This PR adds syntaxes that supports getting and interacting with a living entity's active item.
Active items are those that have non-instant actions when used, like drawing a bow, eating food, blocking with a shield, or loading a crossbow.

Syntax added:

  • CondIsHandRaised: Adds a condition to check if the main hand, off hand, or both hands of the entity are raised, ie: doing something.
  • ExprActiveItem: An expression that returns the item that an entity is currently using. It returns 0 air if nothing is being used. Currently, this returns an itemstack and therefore cannot be set. However, I have considered instead returning the slot that's being used, which would allow setting. I'd like opinions on this, as I don't know if setting an active item really makes sense, but at the same time it would be useful as the user would not have to check which hand is being used before using ExprTool to set it.
  • ExprEntityItemUseTime: An expression that returns either the amount of time that an entity has been using something, or the amount of time that they have left before the item use is complete (eg: finishing drinking the potion). Items that don't have an end state (drawing a bow, blocking) have a use time of 1 hour, for some reason. The crossbow has a set use time, but once the loading finishes, continuing to hold the mouse button results in the elapsed use time increasing, but the remaining time to be 0 seconds. I think this behavior is fine.
  • ExprMaxItemUseTime: An expression that returns the max use time of an item, if it exists. For crossbows this is 1.4s by default, 1.6s for potions, and 1hr for bows and shields.
  • EffCancelItemUse: An effect that interrupts any usage the entity is currently doing. ex: cancelling a bow draw, eating food, etc.
  • ExprReadiedArrow: an expression to get the arrow or bow used in a PlayerReadyArrow event.
  • Added PlayerReadyArrow event and PlayerStopUsingItem event.

Target Minecraft Versions: 1.12+
Requirements: Paper 1.12.2+, EffCancelItemUse requires Paper 1.16.5+
Related Issues: #4185

@AyhamAl-Ali AyhamAl-Ali added the feature Pull request adding a new feature. label Jan 19, 2023
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali left a comment

Choose a reason for hiding this comment

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

Tud stole my suggestions while I was lazy reviewing 😂 jk.
Nice PR ⚡

Co-authored-by: _tud <[email protected]>
Co-authored-by: Ayham Al Ali <[email protected]>
@TheLimeGlass TheLimeGlass self-requested a review January 19, 2023 19:48
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali left a comment

Choose a reason for hiding this comment

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

Hi again ⚡

I accidentally left this as comment instead of change request, but it's a change request

@AyhamAl-Ali
Copy link
Member

Building is failing due to my recent reviews not including braces due to the change of using a list inside Annotations.
Just wrap the values with braces

@Description({
    "",
    ""
})

@sovdeeth
Copy link
Member Author

Building is failing due to my recent reviews not including braces due to the change of using a list inside Annotations. Just wrap the values with braces

Yeah I just wanted to batch commit, it'll be fixed when i push the commit w/ updated import and version requirement :)

@sovdeeth
Copy link
Member Author

sovdeeth commented Feb 19, 2023

Waiting on Spigot to fix the PlayerItemConsumeEvent#setItem method (ticket), so I'm going to not include that in this PR and instead leave it for something in the future.

I'm planning on leaving it as ExprConsumedItem instead of a simple event-value for this reason. (returns the consumed item)

@sovdeeth sovdeeth changed the base branch from master to dev/feature September 16, 2023 20:27
@Moderocky Moderocky added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Sep 18, 2023
Copy link
Member

@UnderscoreTud UnderscoreTud left a comment

Choose a reason for hiding this comment

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

Looks good!

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 pretty good!

@sovdeeth sovdeeth merged commit 2b6191b into SkriptLang:dev/feature Dec 19, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants