Skip to content

Add EntityScareByEntityEvent for Armadillos#10798

Closed
joshuaprince wants to merge 1 commit into
PaperMC:masterfrom
joshuaprince:scare-event
Closed

Add EntityScareByEntityEvent for Armadillos#10798
joshuaprince wants to merge 1 commit into
PaperMC:masterfrom
joshuaprince:scare-event

Conversation

@joshuaprince
Copy link
Copy Markdown
Contributor

@joshuaprince joshuaprince commented May 27, 2024

Add a new event for when an entity "scares" another entity. As of 1.20.6, only armadillos can be scared.


As far as I could tell, there is no way* to prevent a player from scaring 1.20.5's armadillos and making them roll up into their shells. This adds a simple way to do so.

*tried: EntityPoseChangeEvent (not called for armadillos, also no scared-by entity reference), EntityTargetEvent (not called for armadillos)

Choices and Alternatives

  1. This event is called pre-cancelled when any living entity is within 7 blocks of the armadillo.

    • Pro: Plugins have full control over the conditions that scare an armadillo, such as adding more entities that scare armadillos.
    • Con: Lots of pre-cancelled events. Might be easy to misuse or log spam with ignoreCancelled = false.
    • Alternative: Only call the event when the scare actually happens, so that the event can be cancelled but not forced.
  2. The event is named generically.

    • Pro: Anything "scareable" in the future can be rolled into this event.
    • Con: This could be misinterpreted as being called when wolves scare skeletons, cats scare creepers, etc.
    • Alternative 1: Include skeleton and creeper scares by pets in this event.
    • Alternative 2: Rename the event ArmadilloScareByEntityEvent.

Testing

  • Event is called as expected while an entity is within 7 blocks of an armadillo, ~3 times per second.
  • Event continues to be called while the entity is nearby, even while the armadillo is rolled up.
  • getEntity() and getScaredBy() return the correct entities in a test plugin.
  • setCancelled(true) makes armadillos unscareable.
  • setCancelled(false) makes armadillos immediately scared as soon as any living entity is nearby.

Add a new event for when an entity "scares" another entity. As of
1.20.6, only armadillos can be scared.
@joshuaprince joshuaprince requested a review from a team as a code owner May 27, 2024 02:59
@joshuaprince joshuaprince changed the title Add EntityScareByEntityEvent Add EntityScareByEntityEvent for Armadillos May 30, 2024
Copy link
Copy Markdown
Member

@kennytv kennytv left a comment

Choose a reason for hiding this comment

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

Having it generic is good I think, but then you should already add a call in AvoidEntityGoal for the other uses

+ isScared = entityhuman.isSpectator() ? false : entityhuman.isSprinting() || entityhuman.isPassenger();
} else {
- return false;
+ isScared = false;
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.

Shouldn't be called here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's also called at L29, even if the Player didn't actually scare the armadillo. Is it worth calling the event pre-cancelled in these cases? I put my reasoning in the PR body (choice 1).

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.

Separate API to expand what it is scared by might be more appropriate, I think this would already be doable by adding a custom goal. In any case, we generally don't call events for such cases

@joshuaprince
Copy link
Copy Markdown
Contributor Author

Replaced by #10835

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants