From 17a4710c4190a46502fc18b7619260443bda8f6c Mon Sep 17 00:00:00 2001 From: CatTeaA <1615856447@qq.com> Date: Tue, 17 Nov 2026 16:20:05 +0800 Subject: [PATCH 1/2] Add HYBRID option to 'despawn-range-shape' --- .../paper/configuration/type/DespawnRange.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java b/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java index 7779edcbbce3..42692bdf7faa 100644 --- a/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java +++ b/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java @@ -56,11 +56,15 @@ public void preComputed(int defaultDistanceLimit, String identifier) throws Seri } public boolean shouldDespawn(final Shape shape, final double dxSqr, final double dySqr, final double dzSqr, final double dy) { - if (shape == Shape.ELLIPSOID) { - return dxSqr + dzSqr + (dySqr * this.preComputedHorizontalLimitSquaredOverVerticalLimitSquared) > this.preComputedHorizontalLimitSquared; - } else { - return dxSqr + dzSqr > this.preComputedHorizontalLimitSquared || dy > this.verticalLimit.or(this.preComputedVanillaDefaultLimit); - } + final double horizontalDistanceSquared = dxSqr + dzSqr; + return switch (shape) { + case ELLIPSOID -> horizontalDistanceSquared + dySqr * this.preComputedHorizontalLimitSquaredOverVerticalLimitSquared > this.preComputedHorizontalLimitSquared; + case CYLINDER -> horizontalDistanceSquared > this.preComputedHorizontalLimitSquared || dy > this.verticalLimit.or(this.preComputedVanillaDefaultLimit); + case HYBRID -> { + final int vanillaLimit = this.preComputedVanillaDefaultLimit; + yield horizontalDistanceSquared > this.preComputedHorizontalLimitSquared || dy > this.verticalLimit.or(vanillaLimit) || horizontalDistanceSquared + dySqr > (double) vanillaLimit * vanillaLimit; + } + }; } public boolean wasDefinedViaLongSyntax() { @@ -68,7 +72,7 @@ public boolean wasDefinedViaLongSyntax() { } public enum Shape { - CYLINDER, ELLIPSOID + CYLINDER, ELLIPSOID, HYBRID } static final class Serializer implements TypeSerializer { From c1589fbf993100659cb0d112faf60afc01a92519 Mon Sep 17 00:00:00 2001 From: CatTeaA <1615856447@qq.com> Date: Wed, 18 Nov 2026 09:46:30 +0800 Subject: [PATCH 2/2] Update HYBRID to use cube and vanilla ellipsoid checks - Because chunks are loaded as whole units, a cube is more suitable than a cylinder --- .../paper/configuration/type/DespawnRange.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java b/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java index 42692bdf7faa..5b7f49b54ba5 100644 --- a/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java +++ b/paper-server/src/main/java/io/papermc/paper/configuration/type/DespawnRange.java @@ -28,6 +28,7 @@ public final class DespawnRange { private double preComputedHorizontalLimitSquared; // ac^2 private double preComputedHorizontalLimitSquaredOverVerticalLimitSquared; // ac^2/b^2 private int preComputedVanillaDefaultLimit; + private double preComputedVanillaDefaultLimitSquared; public DespawnRange(final IntOr.Default generalLimit) { this(generalLimit, generalLimit, false); @@ -47,6 +48,7 @@ public void preComputed(int defaultDistanceLimit, String identifier) throws Seri throw new SerializationException("Horizontal limit must be greater than 0 for " + identifier); } this.preComputedVanillaDefaultLimit = defaultDistanceLimit; + this.preComputedVanillaDefaultLimitSquared = (double) defaultDistanceLimit * defaultDistanceLimit; this.preComputedHorizontalLimitSquared = Math.pow(this.horizontalLimit.or(defaultDistanceLimit), 2); if (!this.horizontalLimit.isDefined() && !this.verticalLimit.isDefined()) { this.preComputedHorizontalLimitSquaredOverVerticalLimitSquared = 1.0; @@ -57,13 +59,11 @@ public void preComputed(int defaultDistanceLimit, String identifier) throws Seri public boolean shouldDespawn(final Shape shape, final double dxSqr, final double dySqr, final double dzSqr, final double dy) { final double horizontalDistanceSquared = dxSqr + dzSqr; + final double horizontalLimitSquared = this.preComputedHorizontalLimitSquared; return switch (shape) { - case ELLIPSOID -> horizontalDistanceSquared + dySqr * this.preComputedHorizontalLimitSquaredOverVerticalLimitSquared > this.preComputedHorizontalLimitSquared; - case CYLINDER -> horizontalDistanceSquared > this.preComputedHorizontalLimitSquared || dy > this.verticalLimit.or(this.preComputedVanillaDefaultLimit); - case HYBRID -> { - final int vanillaLimit = this.preComputedVanillaDefaultLimit; - yield horizontalDistanceSquared > this.preComputedHorizontalLimitSquared || dy > this.verticalLimit.or(vanillaLimit) || horizontalDistanceSquared + dySqr > (double) vanillaLimit * vanillaLimit; - } + case ELLIPSOID -> horizontalDistanceSquared + dySqr * this.preComputedHorizontalLimitSquaredOverVerticalLimitSquared > horizontalLimitSquared; + case CYLINDER -> horizontalDistanceSquared > horizontalLimitSquared || dy > this.verticalLimit.or(this.preComputedVanillaDefaultLimit); + case HYBRID -> dxSqr > horizontalLimitSquared || dzSqr > horizontalLimitSquared || dy > this.verticalLimit.or(this.preComputedVanillaDefaultLimit) || horizontalDistanceSquared + dySqr > this.preComputedVanillaDefaultLimitSquared; }; }