13
0
geforkt von Mirrors/Paper
Paper/patches/server/0031-Add-configurable-entity-despawn-distances.patch

51 Zeilen
3.5 KiB
Diff

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
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
index 0593d828c911c94c9833bf12b9c294e5dac1f4e8..e672b04e9e123caecec30645df8858d6eda4c931 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
@@ -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);
- int i = this.getType().getCategory().getDespawnDistance();
- int j = i * i;
-
- if (d0 > (double) j && this.removeWhenFarAway(d0)) {
+ // Paper start - Configurable despawn distances
+ // Read configration data and square it for later comparison
+ final MobCategory category = this.getType().getCategory();
+ final io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRangePair despawnRangePair = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory());
+ final int hardHorizontalLimitSquared = (int) Math.pow(despawnRangePair.hard().horizontalLimit().or(category.getDespawnDistance()), 2);
+ final int softHorizontalLimitSquared = (int) Math.pow(despawnRangePair.soft().horizontalLimit().or(category.getNoDespawnDistance()), 2);
+ final int hardVerticalLimit = despawnRangePair.hard().verticalLimit().or(category.getDespawnDistance());
+ final int softVerticalLimit = despawnRangePair.soft().verticalLimit().or(category.getNoDespawnDistance());
+ // Compute vertical/horizontal distances
+ final double horizontalDistanceSquared = entityhuman.distanceToSqr(this.getX(), entityhuman.getY(), this.getZ());
+ final double verticalDistance = Math.abs(entityhuman.getY() - this.getY());
+ // Despawn if hard/soft limit is exceeded
+ if ((horizontalDistanceSquared > hardHorizontalLimitSquared || verticalDistance > hardVerticalLimit) && this.removeWhenFarAway(horizontalDistanceSquared)) {
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
}
-
- int k = this.getType().getCategory().getNoDespawnDistance();
- int l = k * k;
-
- if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) {
- this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- } else if (d0 < (double) l) {
+ if (horizontalDistanceSquared > softHorizontalLimitSquared || verticalDistance > softVerticalLimit) {
+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && this.removeWhenFarAway(horizontalDistanceSquared)) {
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+ }
+ } else {
+ // Paper end - Configurable despawn distances
this.noActionTime = 0;
}
}