From f52959330217483e05bbcd5bbcaa2ab8a46274b8 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Mon, 21 Aug 2023 21:34:38 +0200 Subject: [PATCH] Optimize nearest structure border iteration --- .../server/0008-Gale-semantic-version.patch | 4 +- ...e-nearest-structure-border-iteration.patch | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 patches/server/0145-Optimize-nearest-structure-border-iteration.patch diff --git a/patches/server/0008-Gale-semantic-version.patch b/patches/server/0008-Gale-semantic-version.patch index 32bb969..940a5c7 100644 --- a/patches/server/0008-Gale-semantic-version.patch +++ b/patches/server/0008-Gale-semantic-version.patch @@ -29,7 +29,7 @@ index 2868dab7b100d9c325b0e5056f86660d631dec4b..2acad4c3fd58178b0f8b22bdb04eeeeb } diff --git a/src/main/java/org/galemc/gale/version/GaleSemanticVersion.java b/src/main/java/org/galemc/gale/version/GaleSemanticVersion.java new file mode 100644 -index 0000000000000000000000000000000000000000..7573fcef20f5e808df402b1d5031b3b760fb1474 +index 0000000000000000000000000000000000000000..33df2d291c53c31f7594bca1ca5c92d80c9047fc --- /dev/null +++ b/src/main/java/org/galemc/gale/version/GaleSemanticVersion.java @@ -0,0 +1,37 @@ @@ -57,7 +57,7 @@ index 0000000000000000000000000000000000000000..7573fcef20f5e808df402b1d5031b3b7 + * The patch version is incremented for small changes that do not affect the goal of any feature, + * such as bug fixes, performance improvements or changes in wording. + */ -+ public static final @NotNull String version = "0.5.6"; ++ public static final @NotNull String version = "0.5.7"; + + /** + * The "major.minor" portion of the {@link #version}. diff --git a/patches/server/0145-Optimize-nearest-structure-border-iteration.patch b/patches/server/0145-Optimize-nearest-structure-border-iteration.patch new file mode 100644 index 0000000..1fc60db --- /dev/null +++ b/patches/server/0145-Optimize-nearest-structure-border-iteration.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Martijn Muijsers +Date: Mon, 21 Aug 2023 21:05:09 +0200 +Subject: [PATCH] Optimize nearest structure border iteration + +License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) +Gale - https://galemc.org + +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 8bab3fcfc6aa6c0b37621474a69f15e94bda2113..fa4960b9dac289a83273d8f87d069e2833eb9fc9 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java ++++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java +@@ -262,10 +262,8 @@ public abstract class ChunkGenerator { + for (int j1 = -radius; j1 <= radius; ++j1) { + boolean flag1 = j1 == -radius || j1 == radius; + +- for (int k1 = -radius; k1 <= radius; ++k1) { +- boolean flag2 = k1 == -radius || k1 == radius; ++ for (int k1 = -radius; k1 <= radius; k1 += flag1 ? 1 : radius * 2) { // Gale - iterate over border chunks instead of entire square chunk area + +- if (flag1 || flag2) { + int l1 = centerChunkX + i1 * j1; + int i2 = centerChunkZ + i1 * k1; + ChunkPos chunkcoordintpair = placement.getPotentialStructureChunk(seed, l1, i2); +@@ -274,7 +272,6 @@ public abstract class ChunkGenerator { + if (pair != null) { + return pair; + } +- } + } + } +