Readd improve/fix EntityTargetLivingEntityEvent (#8630)

This commit is contained in:
Jake Potrebic 2022-12-09 03:30:55 -08:00 committed by GitHub
parent 20549ff2d7
commit f6ffbc2720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
505 changed files with 123 additions and 134 deletions

View File

@ -1,59 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 3 Jul 2020 15:03:33 -0700
Subject: [PATCH] Improve EntityTargetLivingEntityEvent for 1.16 mobs
CraftBukkit has a bug in their implementation and is incorrectly handling forget
Also adds more target reasons for why it forgot target.
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java b/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java
index 44d3c9da39389b72bfc5ee39c1abb6baf9dccdb1..565691aaed71de3efe15dd751fbbbe7849ef56b7 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java
@@ -56,15 +56,15 @@ public class StopAttackingIfTargetInvalid<E extends Mob> extends Behavior<E> {
LivingEntity entityliving = this.getAttackTarget(entity);
if (!entity.canAttack(entityliving)) {
- this.clearAttackTarget(entity);
+ this.clearAttackTarget(entity, org.bukkit.event.entity.EntityTargetEvent.TargetReason.TARGET_INVALID); // Paper
} else if (this.canGrowTiredOfTryingToReachTarget && StopAttackingIfTargetInvalid.isTiredOfTryingToReachTarget(entity)) {
- this.clearAttackTarget(entity);
+ this.clearAttackTarget(entity, org.bukkit.event.entity.EntityTargetEvent.TargetReason.FORGOT_TARGET); // Paper
} else if (this.isCurrentTargetDeadOrRemoved(entity)) {
- this.clearAttackTarget(entity);
+ this.clearAttackTarget(entity, org.bukkit.event.entity.EntityTargetEvent.TargetReason.TARGET_DIED); // Paper
} else if (this.isCurrentTargetInDifferentLevel(entity)) {
- this.clearAttackTarget(entity);
+ this.clearAttackTarget(entity, org.bukkit.event.entity.EntityTargetEvent.TargetReason.TARGET_OTHER_LEVEL); // Paper
} else if (this.stopAttackingWhen.test(this.getAttackTarget(entity))) {
- this.clearAttackTarget(entity);
+ this.clearAttackTarget(entity, org.bukkit.event.entity.EntityTargetEvent.TargetReason.TARGET_INVALID); // Paper
}
}
@@ -88,17 +88,20 @@ public class StopAttackingIfTargetInvalid<E extends Mob> extends Behavior<E> {
return optional.isPresent() && !((LivingEntity) optional.get()).isAlive();
}
- protected void clearAttackTarget(E entity) {
+ protected void clearAttackTarget(E entity, EntityTargetEvent.TargetReason reason) {
// CraftBukkit start
- LivingEntity old = entity.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null);
- EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(entity, null, (old != null && !old.isAlive()) ? EntityTargetEvent.TargetReason.TARGET_DIED : EntityTargetEvent.TargetReason.FORGOT_TARGET);
+ // Paper start - fix this event
+ // LivingEntity old = entity.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null);
+ EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(entity, null, reason);
if (event.isCancelled()) {
return;
}
- if (event.getTarget() != null) {
+ // comment out, bad logic - bad
+ /*if (event.getTarget() != null) {
entity.getBrain().setMemory(MemoryModuleType.ATTACK_TARGET, ((CraftLivingEntity) event.getTarget()).getHandle());
return;
- }
+ }*/
+ // Paper end
// CraftBukkit end
this.onTargetErased.accept(entity, this.getAttackTarget(entity));
entity.getBrain().eraseMemory(MemoryModuleType.ATTACK_TARGET);

View File

@ -0,0 +1,48 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 9 Dec 2022 03:10:23 -0800
Subject: [PATCH] Improve/fix EntityTargetLivingEntityEvent
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java b/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java
index 7ae873f391b1c22a57f504490eabe7da558a6ec2..212e307077dfa274a4d4e4192760de23a75ef12a 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/StopAttackingIfTargetInvalid.java
@@ -47,17 +47,30 @@ public class StopAttackingIfTargetInvalid {
if (entityinsentient.canAttack(entityliving) && (!shouldForgetIfTargetUnreachable || !StopAttackingIfTargetInvalid.isTiredOfTryingToReachTarget(entityinsentient, behaviorbuilder_b.tryGet(memoryaccessor1))) && entityliving.isAlive() && entityliving.level == entityinsentient.level && !alternativeCondition.test(entityliving)) {
return true;
} else {
+ // Paper start - better track target change reason
+ final EntityTargetEvent.TargetReason reason;
+ if (!entityinsentient.canAttack(entityliving)) {
+ reason = EntityTargetEvent.TargetReason.TARGET_INVALID;
+ } else if (shouldForgetIfTargetUnreachable && StopAttackingIfTargetInvalid.isTiredOfTryingToReachTarget(entityinsentient, behaviorbuilder_b.tryGet(memoryaccessor1))) {
+ reason = EntityTargetEvent.TargetReason.FORGOT_TARGET;
+ } else if (!entityliving.isAlive()) {
+ reason = EntityTargetEvent.TargetReason.TARGET_DIED;
+ } else if (entityliving.level != entityinsentient.level) {
+ reason = EntityTargetEvent.TargetReason.TARGET_OTHER_LEVEL;
+ } else {
+ reason = EntityTargetEvent.TargetReason.TARGET_INVALID;
+ }
+ // Paper end
// CraftBukkit start
- LivingEntity old = entityinsentient.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null);
- EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(entityinsentient, null, (old != null && !old.isAlive()) ? EntityTargetEvent.TargetReason.TARGET_DIED : EntityTargetEvent.TargetReason.FORGOT_TARGET);
+ EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(entityinsentient, null, reason); // Paper
if (event.isCancelled()) {
return false;
}
- if (event.getTarget() == null) {
- memoryaccessor.erase();
- return true;
- }
- entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
+ // if (event.getTarget() == null) { // Paper - this is wrong, you are skipping the forgetCallback
+ // memoryaccessor.erase();
+ // return true;
+ // }
+ // entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
// CraftBukkit end
forgetCallback.accept(entityinsentient, entityliving);
memoryaccessor.erase();

View File

@ -6,7 +6,7 @@ Subject: [PATCH] Add missing strikeLighting call to
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index f3723a8219881d55959e7231e230d28bfb521dcd..d9ac6e687ad7f4c2cfe6698cdf6e7d1d4652eb2b 100644
index f22457cf9dd5ceb6630c1f96a2050c350c4fbbc9..cec02e3b47ccc99ba8343dafa7a760ebca64ffc1 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2133,6 +2133,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {

View File

@ -56,7 +56,7 @@ index 508a6e062de1994f26393d33e8b41ea245e0c3d0..40423a24eac6675c8b9ddb843c910e32
return (!this.player.joining && !this.connection.isConnected()) || this.processedDisconnect; // Paper
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 5741795405d302aadbf4c10caabd40797557e102..e61402856dbf5c394724101e513438587b5583c9 100644
index 89411cc4a774e85d79aec44cb4136679e9513329..ca12956fe9eb0ade9f78980210ec7421266ba554 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2823,6 +2823,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

View File

@ -18,7 +18,7 @@ index 62fe8133e10ca4e04670b504bf18db9f5e7512e0..4b2862c6c5397ebec7cc22938b76ed0d
private int simulationDistance;
private boolean allowCheatsForAllPlayers;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 0b6f9567aaad080ff2a21be9e17a93d2d24fd010..6e5f72f5d226b94603710d84f9054ce3aa4bd034 100644
index a8bd9f368182395962b63b52c9107debcb6ab6b9..d296f5c970dc4c242fc18fb82e6db583eefef8d8 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -687,6 +687,13 @@ public final class CraftServer implements Server {

View File

@ -9,7 +9,7 @@ as this is how Vanilla teleports entities.
Cancel any pending motion when teleported.
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 8eeb521b11062ecc699813c2132f7edf655d8d09..1909cc53765a38bdb31237b18f27d7e457115726 100644
index 40423a24eac6675c8b9ddb843c910e324709ebe4..040972c62b8d6005a47ccb81a3fda1b4f98f8838 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -752,7 +752,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
@ -57,7 +57,7 @@ index 09b2b6633b108739e8fe6d4c400d42d88b27435e..ff65d3125da3d2716cccac24317e40d0
this.setYRot(yaw);
this.setXRot(pitch);
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
index c58cd26ac15308d249f7d50fed530a6093091d36..b53fc8ca05fb44e6cb7ab6b27b8371b56795fe98 100644
index c5a117308f051c20b81818ad91e0ca40177feb69..0e7c2e7640ff2a2cdc3088dcb56314026bfaf95f 100644
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
@@ -167,6 +167,7 @@ public abstract class BaseSpawner {

View File

@ -6,7 +6,7 @@ Subject: [PATCH] Fix for large move vectors crashing server
Check movement distance also based on current position.
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 1909cc53765a38bdb31237b18f27d7e457115726..191aa9cd6e27cbc322b8ce2aa6ad07c20660e709 100644
index 040972c62b8d6005a47ccb81a3fda1b4f98f8838..5a17bd9435b612d2586a6bcd7fc89609f9010713 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -567,9 +567,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic

View File

@ -67,7 +67,7 @@ index 0a755f38fae9dc84440f43113920c5b4c6d8218b..7b9e943b391c061782fccd2b8d705cee
public void setFlag(int flag) {
diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
index 76efbcb951b133246bd9cbd8808f900f958d9298..14fd37f4bdb9b0b7f28abfccffe682f6fdc6339e 100644
index 45c90505c778bfdebf0884190a422d12a0673d71..3399e8cdf2230bd71444abb43829c54d7277ce36 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -50,7 +50,7 @@ public class CraftBlockData implements BlockData {

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Player elytra boost API
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 60e8e82a1fc255aa713808a78ae2dc73ef0b6be3..a84efd5f91141ab9b3879dbb325bc918d88a93e8 100644
index ca12956fe9eb0ade9f78980210ec7421266ba554..025886ef9fc2d992cffb94b172a44ec123432e60 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -639,6 +639,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Add getOfflinePlayerIfCached(String)
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 6e5f72f5d226b94603710d84f9054ce3aa4bd034..81120251dc65290a731e25662bf484637f546ac1 100644
index d296f5c970dc4c242fc18fb82e6db583eefef8d8..a9c9ec39610a8612ce92db1441be29ab77117ecc 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1827,6 +1827,28 @@ public final class CraftServer implements Server {

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Add API for quit reason
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
index 3ae55dd6441b2dfdb67eb2f24ecf885bab89e7a6..f76ee2131c35a9dbf7ad9d086b51c9644b0a2462 100644
index 4487b4329cf09a6538e272c44207dda492ceb099..43fd36b2ed8e58a2e6213d749a8612a98be421b2 100644
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
@@ -170,12 +170,15 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@ -25,7 +25,7 @@ index 3ae55dd6441b2dfdb67eb2f24ecf885bab89e7a6..f76ee2131c35a9dbf7ad9d086b51c964
Connection.LOGGER.debug("Failed to sent packet", throwable);
ConnectionProtocol enumprotocol = this.getCurrentProtocol();
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index eafc2651a15e1e905a6f2343760969cb5bd414c3..290e250505b229242e7b4f70469c8688cac4b548 100644
index b291903888b33eeae7347841f12a8ca49439c736..6dc93cbcd3a5140a286d027f2ad03851b9c078f4 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -270,6 +270,7 @@ public class ServerPlayer extends Player {
@ -37,7 +37,7 @@ index eafc2651a15e1e905a6f2343760969cb5bd414c3..290e250505b229242e7b4f70469c8688
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 191aa9cd6e27cbc322b8ce2aa6ad07c20660e709..d71ed61acf9949974d746bd1511c30dc2a5235ec 100644
index 5a17bd9435b612d2586a6bcd7fc89609f9010713..eeb69e4155f2b568a51529a39416248780fae886 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -507,6 +507,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Fix Player spawnParticle x/y/z precision loss
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index a84efd5f91141ab9b3879dbb325bc918d88a93e8..56f3ce73eb018cb93e3ec2057794d31345872d8b 100644
index 025886ef9fc2d992cffb94b172a44ec123432e60..6a342a897893355160d9f064236d775452e9b752 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2348,7 +2348,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Limit recipe packets
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index d71ed61acf9949974d746bd1511c30dc2a5235ec..dd468a6f8185545930eae95d8f22beb25ae493b0 100644
index eeb69e4155f2b568a51529a39416248780fae886..dbe3cab9dfd86081aab876488fda576810ce2105 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -262,6 +262,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Player Chunk Load/Unload Events
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 290e250505b229242e7b4f70469c8688cac4b548..c3ad00123198dc00bcf5a3d89f8d527b1c9c083c 100644
index 6dc93cbcd3a5140a286d027f2ad03851b9c078f4..514b5f4762dcd11160ac3b4da1bb44911e6e62b2 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -2166,11 +2166,21 @@ public class ServerPlayer extends Player {

View File

@ -6,7 +6,7 @@ Subject: [PATCH] Fix interact event not being called in adventure
Call PlayerInteractEvent when left-clicking on a block in adventure mode
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index dd468a6f8185545930eae95d8f22beb25ae493b0..b5b451ce6f29c69123b975a7b1943ca17388e6db 100644
index dbe3cab9dfd86081aab876488fda576810ce2105..a21117908a8e1ccbb23fa79cfcc7a6d956ba6a51 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1847,7 +1847,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic

View File

@ -64,7 +64,7 @@ index 694a2f685cb46a5391da012f4d7e3bd3e6e88f4c..fa8cd4438c19a262272da47985a57f7e
public int get() {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 66d87216a3964c5fd39af564c3b4c40eee278c9a..2770412715a9fbd60317d356491f9f0b0bacf57d 100644
index 51f20f0f28c3372be871873dcf58c551800797b2..9055b7821ba2a52e20bf6422cae2edfefc1872b1 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1792,8 +1792,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {

Some files were not shown because too many files have changed in this diff Show More