2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Suddenly <suddenly@suddenly.coffee>
|
|
|
|
Date: Tue, 1 Mar 2016 13:51:54 -0600
|
2024-01-24 11:45:17 +01:00
|
|
|
Subject: [PATCH] Add configurable entity despawn distances
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
2024-08-16 22:29:53 +02:00
|
|
|
index 0593d828c911c94c9833bf12b9c294e5dac1f4e8..cd5281b61f833701131cc6a6bade7bff96515541 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
2024-08-16 22:29:53 +02:00
|
|
|
@@ -863,20 +863,27 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
|
|
Player entityhuman = this.level().getNearestPlayer(this, -1.0D);
|
2021-11-09 08:59:15 +01:00
|
|
|
|
|
|
|
if (entityhuman != null) {
|
2024-08-16 22:29:53 +02:00
|
|
|
- double d0 = entityhuman.distanceToSqr((Entity) this);
|
2021-11-09 08:59:15 +01:00
|
|
|
- int i = this.getType().getCategory().getDespawnDistance();
|
2024-08-16 22:29:53 +02:00
|
|
|
- int j = i * i;
|
|
|
|
+ // Paper start - Configurable despawn distances
|
|
|
|
+ io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRange despawnRanges = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory());
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2024-08-16 22:29:53 +02:00
|
|
|
- if (d0 > (double) j && this.removeWhenFarAway(d0)) {
|
|
|
|
- this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
|
|
- }
|
|
|
|
+ double xzDistanceSquared = entityhuman.distanceToSqr(this.getX(), entityhuman.getY(), this.getZ());
|
|
|
|
+ double yDistance = Math.abs(entityhuman.getY() - this.getY());
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-11-09 08:59:15 +01:00
|
|
|
- int k = this.getType().getCategory().getNoDespawnDistance();
|
2024-08-16 22:29:53 +02:00
|
|
|
- int l = k * k;
|
|
|
|
+ int xzLimitSquared = despawnRanges.xzLimit() * despawnRanges.xzLimit();
|
|
|
|
+ int xzSoftLimitSquared = despawnRanges.xzSoftLimit() * despawnRanges.xzSoftLimit();
|
|
|
|
+ int yLimit = despawnRanges.yLimit();
|
|
|
|
+ int ySoftLimit = despawnRanges.ySoftLimit();
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2024-08-16 22:29:53 +02:00
|
|
|
- if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) {
|
|
|
|
+ if ((xzDistanceSquared > xzLimitSquared || yDistance > yLimit) && this.removeWhenFarAway(xzDistanceSquared)) {
|
|
|
|
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
|
|
- } else if (d0 < (double) l) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (xzDistanceSquared > xzSoftLimitSquared || yDistance > ySoftLimit) {
|
|
|
|
+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && this.removeWhenFarAway(xzDistanceSquared)) {
|
|
|
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // Paper end - Configurable despawn distances
|
|
|
|
this.noActionTime = 0;
|
|
|
|
}
|
|
|
|
}
|