Files
Paper/paper-server/patches/sources/net/minecraft/world/entity/NeutralMob.java.patch
Nassim Jahnke f00727c57e 1.21.5
Co-authored-by: Bjarne Koll <git@lynxplay.dev>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Co-authored-by: MiniDigger | Martin <admin@minidigger.dev>
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>
Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com>
Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
2025-04-12 17:27:00 +02:00

52 lines
2.1 KiB
Diff

--- a/net/minecraft/world/entity/NeutralMob.java
+++ b/net/minecraft/world/entity/NeutralMob.java
@@ -35,9 +_,11 @@
if (level instanceof ServerLevel serverLevel) {
UUID uuid = tag.read("AngryAt", UUIDUtil.CODEC).orElse(null);
this.setPersistentAngerTarget(uuid);
- if ((uuid != null ? serverLevel.getEntity(uuid) : null) instanceof LivingEntity livingEntity) {
- this.setTarget(livingEntity);
- }
+ // Paper - Prevent entity loading causing async lookups; Moved diff to separate method
+ // If this entity already survived its first tick, e.g. is loaded and ticked in sync, actively
+ // tick the initial persistent anger.
+ // If not, let the first tick on the baseTick call the method later down the line.
+ if (this instanceof Entity entity && !entity.firstTick) this.tickInitialPersistentAnger(level);
}
}
@@ -90,7 +_,7 @@
default void stopBeingAngry() {
this.setLastHurtByMob(null);
this.setPersistentAngerTarget(null);
- this.setTarget(null);
+ this.setTarget(null, org.bukkit.event.entity.EntityTargetEvent.TargetReason.FORGOT_TARGET); // CraftBukkit
this.setRemainingPersistentAngerTime(0);
}
@@ -101,8 +_,24 @@
void setTarget(@Nullable LivingEntity livingEntity);
+ boolean setTarget(@Nullable LivingEntity livingEntity, @Nullable org.bukkit.event.entity.EntityTargetEvent.TargetReason reason); // CraftBukkit
+
boolean canAttack(LivingEntity entity);
@Nullable
LivingEntity getTarget();
+
+ // Paper start - Prevent entity loading causing async lookups
+ // Update last hurt when ticking
+ default void tickInitialPersistentAnger(Level level) {
+ UUID uuid = getPersistentAngerTarget();
+ if (uuid == null) {
+ return;
+ }
+
+ if (level.getEntity(uuid) instanceof net.minecraft.world.entity.LivingEntity livingEntity) {
+ this.setTarget(livingEntity, null);
+ }
+ }
+ // Paper end - Prevent entity loading causing async lookups
}