Skip to content

Add EvtEntityLunge and ExprLungePower#8649

Open
vuxeim wants to merge 10 commits into
SkriptLang:dev/featurefrom
vuxeim:feature/lunge
Open

Add EvtEntityLunge and ExprLungePower#8649
vuxeim wants to merge 10 commits into
SkriptLang:dev/featurefrom
vuxeim:feature/lunge

Conversation

@vuxeim
Copy link
Copy Markdown

@vuxeim vuxeim commented May 17, 2026

Problem

This adds syntax to work with Paper event EntityLungeEvent as requested in #8586.
As well as expression to get/set/add/remove lunge power inside of the event.

Solution

I've added EvtEntityLunge.java and ExprLungePower.java so that working with lunge event is possible from Skript land.
Event: [%-entitytypes%] lunge
Expression: [the] [event-]lunge power
Example:

on lunge:
    set lunge power to 4

Testing Completed

I managed to successfully run both ./gradlew clean quickTest and ./gradlew build test.
(In new test environment java25/paper-26.1.2.json)

And I did manual in-game testing with this script:
on entity lunge with priority monitor:
    broadcast "Entity: %event-entitytype% (%event-entity%) Power: %lunge power%"
 
on skeleton lunge with priority monitor:
    if the lunge power is 1, 2 or 3:
        broadcast "Normal lunge power"
    else if the lunge power is greater than 3:
        broadcast "Overpowered lunge power"
 
on player lunge:
    set event-lunge power to 10
 
command spawn-opponent [<text="skeleton">] [<boolean=true>]:
    trigger:

        set {_loc} to location of block above player's target block
        set {_weapon} to diamond spear of lunge 3 if arg 2 is true else air

        if arg 1 is "skeleton":
            spawn skeleton at {_loc}:
                set tool of last spawned entity to {_weapon}

        else if arg 1 is "all":
            loop all entity types:
                set {_loc} to location of block above player's target block
                spawn loop-value at {_loc}:
                    set tool of last spawned entity to {_weapon}
                wait 1 tick

        else if arg 1 is "duel":
            spawn skeleton at {_loc}:
                set tool of last spawned entity to {_weapon}
            spawn iron golem at {_loc} ~ vector(2, 0, 2)

        else if arg 1 is "ravi":
            spawn ravager at {_loc}:
                set tool of last spawned entity to {_weapon}

Supporting Information

I had to bump version of Paper API to 26.1.2 - EntityLungeEvent was made available in that version.
I've added test environment java25/paper-26.1.2.json.

I also want to propose additional changes:

  • add/remove to/from lunge power
    • add 1 to lunge power
    • EDIT I have added it in subsequent commit
  • expression to get lunge item (or lunge weapon) in entity lunge event
    • on lunge:
          if event-lunge item is enchanted with mending:
              cancel event
              send "Where did you get that spoon o.O"
      
    • Can this item ever be null?

But I would like some feedback on what I already introduced in this PR. As #8586 was marked good first issue I wanted to try and contribute to the Skript project. I did my best to make this a reasonable contribution.

It is worth mentioning that entity has to hold a weapon (e.g. a spear enchanted with lunge enchantment) (event if that weapon isn't visibly equipped) in order to perform lunge attack that fires this EntityLungeEvent, but this isn't true for every mob type. (e.g. Zombies can't preform lunge attack at all)
A list of entities that in general can perform lunge attack consists of (but is probably not limited to):

See the list
% zcat logs/2026* | grep 'INFO]: Entity: ' | cut -d" " -f 4- | grep 3 | sort | uniq 
Entity: blaze (blaze) Power: 3
Entity: bogged (bogged) Power: 3
Entity: cat (cat) Power: 3
Entity: cave spider (cave spider) Power: 3
Entity: cold frog (frog) Power: 3
Entity: creaking (creaking) Power: 3
Entity: drowned (drowned) Power: 3
Entity: elder guardian (elder guardian) Power: 3
Entity: enderman (enderman) Power: 3
Entity: endermite (endermite) Power: 3
Entity: guardian (normal guardian) Power: 3
Entity: killer rabbit (rabbit) Power: 3
Entity: ocelot (ocelot) Power: 3
Entity: parched (parched) Power: 3
Entity: phantom (phantom) Power: 3
Entity: piglin brute (piglin brute) Power: 3
Entity: player (vuxeim) Power: 3
Entity: polar bear (polar bear) Power: 3
Entity: ravager (ravager) Power: 3
Entity: red fox (fox) Power: 3
Entity: skeleton (skeleton) Power: 3
Entity: snow fox (fox) Power: 3
Entity: spider (spider) Power: 3
Entity: stray (stray) Power: 3
Entity: vex (vex) Power: 3
Entity: vindicator (vindicator) Power: 3
Entity: warden (warden) Power: 3
Entity: wither skeleton (wither skeleton) Power: 3
Entity: wolf (wolf) Power: 3

Completes: #8586
AI assistance: Copilot was active during development of this PR mainly for generating documentation part (@Description([...]), @Example([...])). Though the rest of the code I wrote is based on classes that already exist: ExprLungePower from ExprLocation and EvtEntityLunge from EntityTeleport.

vuxeim added 2 commits May 17, 2026 21:19
add test environment file for 26.1.2
feat: add lunge power expression
@vuxeim vuxeim requested a review from a team as a code owner May 17, 2026 21:25
@vuxeim vuxeim requested review from Absolutionism and cheeezburga and removed request for a team May 17, 2026 21:25
@skriptlang-automation skriptlang-automation Bot added needs reviews A PR that needs additional reviews needs triage An issue that hasn't been classified or verified yet labels May 17, 2026
@skriptlang-automation

This comment has been minimized.

Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprLungePower.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
@github-project-automation github-project-automation Bot moved this to In Review in 2.16 Releases May 17, 2026
@skriptlang-automation skriptlang-automation Bot added feature Pull request adding a new feature. and removed needs triage An issue that hasn't been classified or verified yet labels May 17, 2026
Copy link
Copy Markdown
Member

@erenkarakal erenkarakal left a comment

Choose a reason for hiding this comment

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

looks fine, thank you for contributing!

Comment thread src/main/java/ch/njol/skript/expressions/ExprLungePower.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
@vuxeim vuxeim requested a review from erenkarakal May 18, 2026 22:48
Copy link
Copy Markdown
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.

Good work so far!

Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/events/EvtEntityLunge.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprLungePower.java Outdated
@vuxeim vuxeim requested a review from APickledWalrus May 20, 2026 18:35
Copy link
Copy Markdown
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.

Nearly ready 🙂

Comment on lines +23 to +27
.examples("on lunge:",
"\tset lunge power to 4",
"on ravager lunge:",
"\tcancel event"
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It'll be better to format this as two distinct examples:

Suggested change
.examples("on lunge:",
"\tset lunge power to 4",
"on ravager lunge:",
"\tcancel event"
)
.examples(
"""
on lunge:
set lunge power to 4
""",
"""
on ravager lunge:
cancel event
"""
)

Comment on lines +42 to +47
EntityLungeEvent lungeEvent = (EntityLungeEvent) event;

if (entityTypes == null) {
return true;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
EntityLungeEvent lungeEvent = (EntityLungeEvent) event;
if (entityTypes == null) {
return true;
}
if (entityTypes == null) {
return true;
}
EntityLungeEvent lungeEvent = (EntityLungeEvent) event;

Comment on lines +58 to +63
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
if (entityTypes != null) {
builder.append(entityTypes).append(" ");
}
builder.append("lunge");
return builder.toString();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can also use appendIf to simplify this

Suggested change
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
if (entityTypes != null) {
builder.append(entityTypes).append(" ");
}
builder.append("lunge");
return builder.toString();
return new SyntaxStringBuilder(event, debug)
.appendIf(entityTypes != null, entityTypes)
.append("lunge")
.toString();

Another nice benefit of SSB is that you do not need to worry about appending spaces, it's handled internally.

}

@Override
public Integer[] get(Event event) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be placed immediately after init

@Override
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
int deltaValue = delta != null ? (Integer) delta[0] : 0;
int currentValue = getSingle(event);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's worth avoiding the overhead here and just doing

((EntityLungeEvent) event).getLungePower();

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. needs reviews A PR that needs additional reviews

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

5 participants