Add Configuration for vertical Despawn Ranges (#10440)

This commit is contained in:
Tamion 2024-08-16 22:29:53 +02:00 committed by GitHub
parent ec55c11fc0
commit 1b8ab116ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 152 additions and 39 deletions

View file

@ -5,23 +5,44 @@ Subject: [PATCH] Add configurable entity despawn distances
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 0593d828c911c94c9833bf12b9c294e5dac1f4e8..5fd0e3d27f3c86f1ff767b45dfa6138c30f13e3e 100644
index 0593d828c911c94c9833bf12b9c294e5dac1f4e8..cd5281b61f833701131cc6a6bade7bff96515541 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -864,14 +864,14 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
@@ -863,20 +863,27 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
Player entityhuman = this.level().getNearestPlayer(this, -1.0D);
if (entityhuman != null) {
double d0 = entityhuman.distanceToSqr((Entity) this);
- double d0 = entityhuman.distanceToSqr((Entity) this);
- int i = this.getType().getCategory().getDespawnDistance();
+ int i = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).hard(); // Paper - Configurable despawn distances
int j = i * i;
- 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());
if (d0 > (double) j && this.removeWhenFarAway(d0)) {
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
}
- 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());
- int k = this.getType().getCategory().getNoDespawnDistance();
+ int k = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).soft(); // Paper - Configurable despawn distances
int l = k * k;
- int l = k * k;
+ int xzLimitSquared = despawnRanges.xzLimit() * despawnRanges.xzLimit();
+ int xzSoftLimitSquared = despawnRanges.xzSoftLimit() * despawnRanges.xzSoftLimit();
+ int yLimit = despawnRanges.yLimit();
+ int ySoftLimit = despawnRanges.ySoftLimit();
if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) {
- 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;
}
}