Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions patches/api/0481-Add-EntityScareByEntityEvent.patch
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;
+ }
+}
40 changes: 40 additions & 0 deletions patches/server/1051-Add-EntityScareByEntityEvent.patch
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;
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

}
+ 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