diff --git a/divinemc-server/minecraft-patches/features/0079-Euclidean-distance-squared-option.patch b/divinemc-server/minecraft-patches/features/0079-Euclidean-distance-squared-option.patch new file mode 100644 index 0000000..cd42ddf --- /dev/null +++ b/divinemc-server/minecraft-patches/features/0079-Euclidean-distance-squared-option.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> +Date: Fri, 18 Jul 2025 13:54:17 +0300 +Subject: [PATCH] Euclidean distance squared option + + +diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java +index fef167837e05d6e80246d4fccd037cc1c9500f97..1ef70cc1ca0a47ddae8655e88fa6b74fa7f81dc6 100644 +--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java ++++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java +@@ -387,10 +387,19 @@ public final class RegionizedPlayerChunkLoader { + final int centerX = PlayerChunkLoaderData.this.lastChunkX; + final int centerZ = PlayerChunkLoaderData.this.lastChunkZ; + +- return Integer.compare( +- Math.abs(c1x - centerX) + Math.abs(c1z - centerZ), +- Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) +- ); ++ // DivineMC start - Euclidean distance squared option ++ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.useEuclideanDistanceSquared) { ++ return Integer.compare( ++ (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ), ++ (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ) ++ ); ++ } else { ++ return Integer.compare( ++ Math.abs(c1x - centerX) + Math.abs(c1z - centerZ), ++ Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) ++ ); ++ } ++ // DivineMC end - Euclidean distance squared option + }; + private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); + private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java b/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java index d60289b..31cae55 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java @@ -372,6 +372,7 @@ public class DivineConfig { public static long chunkDataCacheLimit = 32678L; public static int maxViewDistance = 32; public static int playerNearChunkDetectionRange = 128; + public static boolean useEuclideanDistanceSquared = true; public static boolean endBiomeCacheEnabled = false; public static int endBiomeCacheCapacity = 1024; public static boolean smoothBedrockLayer = false; @@ -429,6 +430,8 @@ public class DivineConfig { "This value is used in the calculation 'range/16' to get the distance in chunks any player must be to allow the check to pass.", "By default, this range is computed to 8, meaning a player must be within an 8 chunk radius of a chunk position to pass.", "Keep in mind the result is rounded to the nearest whole number."); + useEuclideanDistanceSquared = getBoolean(ConfigCategory.PERFORMANCE.key("chunks.use-euclidean-distance-squared"), useEuclideanDistanceSquared, + "If enabled, euclidean distance squared for chunk task ordering will be used."); endBiomeCacheEnabled = getBoolean(ConfigCategory.PERFORMANCE.key("chunks.end-biome-cache-enabled"), endBiomeCacheEnabled, "Enables the end biome cache, which can accelerate The End worldgen.");