-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add EntityScareByEntityEvent for Armadillos #10798
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Joshua Prince <joshua@jtprince.com> | ||
| Date: Sun, 26 May 2024 19:23:43 -0700 | ||
| Subject: [PATCH] Add EntityScareByEntityEvent | ||
|
|
||
|
|
||
| diff --git a/src/main/java/io/papermc/paper/event/entity/EntityScareByEntityEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityScareByEntityEvent.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..d1dc14f0e72d5a33f15f7124ce4cbe4ba352254f | ||
| --- /dev/null | ||
| +++ b/src/main/java/io/papermc/paper/event/entity/EntityScareByEntityEvent.java | ||
| @@ -0,0 +1,60 @@ | ||
| +package io.papermc.paper.event.entity; | ||
| + | ||
| +import org.bukkit.entity.Entity; | ||
| +import org.bukkit.entity.LivingEntity; | ||
| +import org.bukkit.event.Cancellable; | ||
| +import org.bukkit.event.HandlerList; | ||
| +import org.bukkit.event.entity.EntityEvent; | ||
| +import org.jetbrains.annotations.ApiStatus; | ||
| +import org.jetbrains.annotations.NotNull; | ||
| + | ||
| +/** | ||
| + * Called when an entity is scared by another nearby entity. | ||
| + * <p> | ||
| + * This event is called repeatedly while a scareable entity is within range of | ||
| + * any other living entity. It is cancelled by default if the other entity | ||
| + * does not ordinarily scare this entity. | ||
| + */ | ||
| +public class EntityScareByEntityEvent extends EntityEvent implements Cancellable { | ||
| + private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
| + | ||
| + private final @NotNull LivingEntity scaredBy; | ||
| + private boolean cancelled; | ||
| + | ||
| + @ApiStatus.Internal | ||
| + public EntityScareByEntityEvent(@NotNull Entity entity, @NotNull LivingEntity scaredBy) { | ||
| + super(entity); | ||
| + this.scaredBy = scaredBy; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Gets the entity which scared the affected entity. | ||
| + * | ||
| + * @return the scaring entity | ||
| + */ | ||
| + @NotNull | ||
| + public Entity getScaredBy() { | ||
| + return this.scaredBy; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public boolean isCancelled() { | ||
| + return this.cancelled; | ||
| + } | ||
| + | ||
| + @Override | ||
| + public void setCancelled(boolean cancel) { | ||
| + this.cancelled = cancel; | ||
| + } | ||
| + | ||
| + @NotNull | ||
| + @Override | ||
| + public HandlerList getHandlers() { | ||
| + return HANDLER_LIST; | ||
| + } | ||
| + | ||
| + @NotNull | ||
| + public static HandlerList getHandlerList() { | ||
| + return HANDLER_LIST; | ||
| + } | ||
| +} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Joshua Prince <joshua@jtprince.com> | ||
| Date: Sun, 26 May 2024 19:23:43 -0700 | ||
| Subject: [PATCH] Add EntityScareByEntityEvent | ||
|
|
||
|
|
||
| diff --git a/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java b/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java | ||
| index b38281f963377cc82b360e8457da7cad033b8c36..c9dbf3444c73f2c983d511db33dbf74807e3b82c 100644 | ||
| --- a/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java | ||
| +++ b/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java | ||
| @@ -229,17 +229,24 @@ public class Armadillo extends Animal { | ||
| public boolean isScaredBy(LivingEntity entity) { | ||
| if (!this.getBoundingBox().inflate(7.0D, 2.0D, 7.0D).intersects(entity.getBoundingBox())) { | ||
| return false; | ||
| - } else if (entity.getType().is(EntityTypeTags.UNDEAD)) { | ||
| - return true; | ||
| + // Paper start - Add EntityScareByEntityEvent | ||
| + } | ||
| + boolean isScared; | ||
| + if (entity.getType().is(EntityTypeTags.UNDEAD)) { | ||
| + isScared = true; | ||
| } else if (this.getLastHurtByMob() == entity) { | ||
| - return true; | ||
| + isScared = true; | ||
| } else if (entity instanceof Player) { | ||
| Player entityhuman = (Player) entity; | ||
|
|
||
| - return entityhuman.isSpectator() ? false : entityhuman.isSprinting() || entityhuman.isPassenger(); | ||
| + isScared = entityhuman.isSpectator() ? false : entityhuman.isSprinting() || entityhuman.isPassenger(); | ||
| } else { | ||
| - return false; | ||
| + isScared = false; | ||
| } | ||
| + io.papermc.paper.event.entity.EntityScareByEntityEvent event = new io.papermc.paper.event.entity.EntityScareByEntityEvent(this.getBukkitEntity(), entity.getBukkitLivingEntity()); | ||
| + event.setCancelled(!isScared); | ||
| + return event.callEvent(); | ||
| + // Paper end - Add EntityScareByEntityEvent | ||
| } | ||
|
|
||
| @Override | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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