aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0864-Optimize-nearest-structure-border-iteration.patch
diff options
context:
space:
mode:
authorNassim Jahnke <[email protected]>2024-10-27 09:43:00 +0100
committerNassim Jahnke <[email protected]>2024-10-27 10:03:59 +0100
commit348c8550967380d9843e365e769f67eee8a8e474 (patch)
tree185991293a5343239e1107ebc98df37de3d020a5 /patches/server/0864-Optimize-nearest-structure-border-iteration.patch
parentbcf52fe5fd7b178e3c72f53762c8e32ca7910dc4 (diff)
downloadPaper-348c8550967380d9843e365e769f67eee8a8e474.tar.gz
Paper-348c8550967380d9843e365e769f67eee8a8e474.zip
Readd last API patch (with TODO)
Diffstat (limited to 'patches/server/0864-Optimize-nearest-structure-border-iteration.patch')
-rw-r--r--patches/server/0864-Optimize-nearest-structure-border-iteration.patch39
1 files changed, 39 insertions, 0 deletions
diff --git a/patches/server/0864-Optimize-nearest-structure-border-iteration.patch b/patches/server/0864-Optimize-nearest-structure-border-iteration.patch
new file mode 100644
index 0000000000..edd50774cc
--- /dev/null
+++ b/patches/server/0864-Optimize-nearest-structure-border-iteration.patch
@@ -0,0 +1,39 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Martijn Muijsers <[email protected]>
+Date: Mon, 21 Aug 2023 21:05:09 +0200
+Subject: [PATCH] Optimize nearest structure border iteration
+
+Getting the nearest generated structure contains a nested set of loops that
+iterates over all chunks at a specific chessboard distance. It does this by
+iterating over the entire square of chunks within that distance, and checking
+if the coordinates are at exactly the right distance to be on the border.
+
+This patch optimizes the iteration by only iterating over the border chunks.
+This evaluated chunks are the same, and in the same order, as before, to
+ensure that the returned found structure (which may for example be a buried
+treasure that will be marked on a treasure map) is the same as in vanilla.
+
+diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+index 31c5f54c90d6e35875f762747f8618e58e2eed91..582065b2d4e818c0edec36b2e9847f8ed3266b10 100644
+--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
++++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+@@ -265,12 +265,15 @@ public abstract class ChunkGenerator {
+ int i1 = placement.spacing();
+
+ for (int j1 = -radius; j1 <= radius; ++j1) {
+- boolean flag1 = j1 == -radius || j1 == radius;
++ // Paper start - Perf: iterate over border chunks instead of entire square chunk area
++ boolean flag1 = j1 == -radius || j1 == radius; final boolean onBorderAlongZAxis = flag1; // Paper - OBFHELPER
+
+- for (int k1 = -radius; k1 <= radius; ++k1) {
+- boolean flag2 = k1 == -radius || k1 == radius;
++ for (int k1 = -radius; k1 <= radius; k1 += onBorderAlongZAxis ? 1 : radius * 2) {
++ // boolean flag2 = k1 == -radius || k1 == radius;
+
+- if (flag1 || flag2) {
++ // if (flag1 || flag2) {
++ if (true) {
++ // Paper end - Perf: iterate over border chunks instead of entire square chunk area
+ int l1 = centerChunkX + i1 * j1;
+ int i2 = centerChunkZ + i1 * k1;
+ ChunkPos chunkcoordintpair = placement.getPotentialStructureChunk(seed, l1, i2);