PaperMC/Spigot-Server-Patches/0075-EntityPathfindEvent.patch
Mariell Hoversholm f6d820f077 It compiles
2021-03-18 18:03:22 +01:00

107 lines
5.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 28 Mar 2016 21:22:26 -0400
Subject: [PATCH] EntityPathfindEvent
Fires when an Entity decides to start moving to a location.
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/Navigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/Navigation.java
index 942e03578836524ba746bc37699677eb06cc7803..703d06b2b29f1500301d82df78dc377141085145 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/Navigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/Navigation.java
@@ -75,7 +75,7 @@ public class Navigation extends NavigationAbstract {
@Override
public PathEntity a(Entity entity, int i) {
- return this.a(entity.getChunkCoordinates(), i);
+ return this.a(entity.getChunkCoordinates(), entity, i); // Paper - Forward target entity
}
private int u() {
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java b/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java
index 8848a7552a0ef3944560a71f71620c6bd0f08c10..58225877ce4f2533c19d34e143ae374dc289bce5 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java
@@ -10,6 +10,7 @@ import net.minecraft.core.BaseBlockPosition;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.IPosition;
import net.minecraft.network.protocol.game.PacketDebug;
+import net.minecraft.server.MCUtil;
import net.minecraft.util.MathHelper;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityInsentient;
@@ -28,7 +29,7 @@ import net.minecraft.world.phys.Vec3D;
public abstract class NavigationAbstract {
- protected final EntityInsentient a;
+ protected final EntityInsentient a; public Entity getEntity() { return a; } // Paper - OBFHELPER
protected final World b;
@Nullable
protected PathEntity c;
@@ -115,16 +116,26 @@ public abstract class NavigationAbstract {
@Nullable
public PathEntity a(BlockPosition blockposition, int i) {
- return this.a(ImmutableSet.of(blockposition), 8, false, i);
+ // Paper start - add target parameter
+ return this.a(blockposition, null, i);
+ }
+ @Nullable public PathEntity a(BlockPosition blockposition, Entity target, int i) {
+ return this.a(ImmutableSet.of(blockposition), target, 8, false, i);
+ // Paper end
}
@Nullable
public PathEntity a(Entity entity, int i) {
- return this.a(ImmutableSet.of(entity.getChunkCoordinates()), 16, true, i);
+ return this.a(ImmutableSet.of(entity.getChunkCoordinates()), entity, 16, true, i); // Paper
}
@Nullable
+ // Paper start - Add target
protected PathEntity a(Set<BlockPosition> set, int i, boolean flag, int j) {
+ return this.a(set, null, i, flag, j);
+ }
+ @Nullable protected PathEntity a(Set<BlockPosition> set, Entity target, int i, boolean flag, int j) {
+ // Paper end
if (set.isEmpty()) {
return null;
} else if (this.a.locY() < 0.0D) {
@@ -134,6 +145,23 @@ public abstract class NavigationAbstract {
} else if (this.c != null && !this.c.c() && set.contains(this.p)) {
return this.c;
} else {
+ // Paper start - Pathfind event
+ boolean copiedSet = false;
+ for (BlockPosition possibleTarget : set) {
+ if (!new com.destroystokyo.paper.event.entity.EntityPathfindEvent(getEntity().getBukkitEntity(),
+ MCUtil.toLocation(getEntity().world, possibleTarget), target == null ? null : target.getBukkitEntity()).callEvent()) {
+ if (!copiedSet) {
+ copiedSet = true;
+ set = new java.util.HashSet<>(set);
+ }
+ // note: since we copy the set this remove call is safe, since we're iterating over the old copy
+ set.remove(possibleTarget);
+ if (set.isEmpty()) {
+ return null;
+ }
+ }
+ }
+ // Paper end
this.b.getMethodProfiler().enter("pathfind");
float f = (float) this.a.b(GenericAttributes.FOLLOW_RANGE);
BlockPosition blockposition = flag ? this.a.getChunkCoordinates().up() : this.a.getChunkCoordinates();
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationFlying.java b/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationFlying.java
index 2e1efe7a048f64d494260d10a4ae5dba86af5e6c..f5664b8c0762f775f3cd106d156eb74b48bcedc2 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationFlying.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationFlying.java
@@ -37,7 +37,7 @@ public class NavigationFlying extends NavigationAbstract {
@Override
public PathEntity a(Entity entity, int i) {
- return this.a(entity.getChunkCoordinates(), i);
+ return this.a(entity.getChunkCoordinates(), entity, i); // Paper - Forward target entity
}
@Override