Improve seed based feature search to not load chunk (#5760)

This is done by returning the center location of the chunk at the height
 of the input location when the target chunk isn't loaded already which
 is exact enough for most use cases and will get more precise once the
 player is close enough for the chunk being loaded anyways.

As this might lead to less precise locations a config option to enable
 the sync loading of the chunks is provided.
This commit is contained in:
Max Lee 2021-06-05 09:07:35 +01:00
parent a31cdfbcff
commit aaecd72944

View file

@ -11,9 +11,14 @@ This is done by backporting Mojang's change in 1.17 which makes it so
that the biome (generated by the seed) is checked first if the feature
can be generated before actually to load the chunk.
The only downside of this is that it breaks once the seed or generator
Additionally to that the center location of the target chunk is simply
returned if the chunk is not loaded to avoid the sync chunk load.
As this can lead to less precise locations a toggle is provided to
enable the sync loading of the target chunk again.
The main downside of this is that it breaks once the seed or generator
changes but this should usually not happen. A config option to disable
this improvement is added though in case that should ever be necessary.
this completely is added though in case that should ever be necessary.
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@ -24,9 +29,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
+ public boolean seedBasedFeatureSearch = true;
+ public boolean seedBasedFeatureSearchLoadsChunks = false;
+ private void seedBasedFeatureSearch() {
+ seedBasedFeatureSearch = getBoolean("seed-based-feature-search", seedBasedFeatureSearch);
+ log("Feature search is based on seed: " + seedBasedFeatureSearch);
+ seedBasedFeatureSearchLoadsChunks = getBoolean("seed-based-feature-search-loads-chunks", seedBasedFeatureSearchLoadsChunks);
+ log("Feature search is based on seed: " + seedBasedFeatureSearch + ", loads chunks:" + seedBasedFeatureSearchLoadsChunks);
+ }
+
public int maxCollisionsPerEntity;
@ -84,14 +91,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
int j2 = i1 + k * l1;
ChunkCoordIntPair chunkcoordintpair = this.a(structuresettingsfeature, j, seededrandom, i2, j2);
if (!iworldreader.getWorldBorder().isChunkInBounds(chunkcoordintpair.x, chunkcoordintpair.z)) { continue; } // Paper
- IChunkAccess ichunkaccess = iworldreader.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z, ChunkStatus.STRUCTURE_STARTS);
+ // Paper start - seed based feature search
+ IChunkAccess ichunkaccess = null;
+ if (structuremanager.getWorld().paperConfig.seedBasedFeatureSearch) {
+ BiomeBase biomeBase = structuremanager.getWorld().getBiomeManager().getBiome(new BlockPosition(chunkcoordintpair.getBlockX() + 9, 0, chunkcoordintpair.getBlockZ() + 9));
+ if (!biomeBase.e().a(this)) {
+ continue;
+ }
+ if (!structuremanager.getWorld().paperConfig.seedBasedFeatureSearchLoadsChunks) {
+ ichunkaccess = structuremanager.getWorld().getChunkIfLoaded(chunkcoordintpair.x, chunkcoordintpair.z);
+ if (ichunkaccess == null) {
+ return chunkcoordintpair.asPosition().add(8, blockposition.getY(), 8);
+ }
+ }
+ }
+ if (ichunkaccess == null) {
+ ichunkaccess = iworldreader.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z, ChunkStatus.STRUCTURE_STARTS);
+ }
+ // Paper end
IChunkAccess ichunkaccess = iworldreader.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z, ChunkStatus.STRUCTURE_STARTS);
StructureStart<?> structurestart = structuremanager.a(SectionPosition.a(ichunkaccess.getPos(), 0), this, ichunkaccess);
if (structurestart != null && structurestart.e()) {