9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-23 00:49:31 +00:00
Files
Leaf/leaf-archived-patches/removed/1.21.8/paperserver/0046-Async-structure-locate-api.patch
hayanesuru 23b7b02eee optimize chunk map (#438)
* rebase

* optimize LivingEntity#travel

* cleanup

* Replace fluid height map

* reuse array list in Entity#collide

* cleanup

* fix fire and liquid collision shape

* fix checkInside

* inline betweenClosed

* cleanup

* optimize getOnPos

* optimize equals in getOnPos

* update mainSupportingBlockPos on dirty

* cleanup

* rename

* merge same patch

* rebase and remove properly

* [ci skip] cleanup

* rebase and rebuild

* fix async locator

* remove async locator

* cleanup

* rebase

---------

Co-authored-by: Taiyou06 <kaandindar21@gmail.com>
2025-08-19 20:48:26 +02:00

61 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Mon, 1 Nov 2077 00:00:00 +0800
Subject: [PATCH] Async structure locate api
This patch depends on Asynchronous locator patch.
Added some asynchronous structure locate methods in World,
requires async-locator to be enabled in Leaf config, or else it will fall back to sync methods.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 61121d2efd0df2fcafdc4c272e1cd1b986f42e24..8c597b54491521f759e2983329a522ba065c647f 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2301,6 +2301,45 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return new CraftStructureSearchResult(CraftStructure.minecraftToBukkit(found.getSecond().value()), CraftLocation.toBukkit(found.getFirst(), this));
}
+ // Leaf start - Async structure locate api
+ @Override
+ public void locateNearestStructureAsync(Location origin, StructureType structureType, int radius, boolean findUnexplored, Consumer<StructureSearchResult> afterComplete) {
+ List<Structure> structures = new ArrayList<>();
+ for (Structure structure : RegistryAccess.registryAccess().getRegistry(RegistryKey.STRUCTURE)) {
+ if (structure.getStructureType() == structureType) {
+ structures.add(structure);
+ }
+ }
+
+ this.locateNearestStructureAsync(origin, structures, radius, findUnexplored, afterComplete);
+ }
+
+ @Override
+ public void locateNearestStructureAsync(Location origin, Structure structure, int radius, boolean findUnexplored, Consumer<StructureSearchResult> afterComplete) {
+ this.locateNearestStructureAsync(origin, List.of(structure), radius, findUnexplored, afterComplete);
+ }
+
+ public void locateNearestStructureAsync(Location origin, List<Structure> structures, int radius, boolean findUnexplored, Consumer<@Nullable StructureSearchResult> afterComplete) {
+ if (!org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) afterComplete.accept(locateNearestStructure(origin, structures, radius, findUnexplored));
+ BlockPos originPos = BlockPos.containing(origin.getX(), origin.getY(), origin.getZ());
+ List<Holder<net.minecraft.world.level.levelgen.structure.Structure>> holders = new ArrayList<>();
+
+ for (Structure structure : structures) {
+ holders.add(Holder.direct(CraftStructure.bukkitToMinecraft(structure)));
+ }
+
+ org.dreeam.leaf.async.locate.AsyncLocator.locate(
+ this.getHandle(), HolderSet.direct(holders), originPos, radius, findUnexplored
+ ).thenOnServerThread(found -> {
+ if (found == null) {
+ afterComplete.accept(null);
+ return;
+ }
+ afterComplete.accept(new CraftStructureSearchResult(CraftStructure.minecraftToBukkit(found.getSecond().value()), CraftLocation.toBukkit(found.getFirst(), this)));
+ });
+ }
+ // Leaf end - Async structure locate api
+
// Paper start
@Override
public double getCoordinateScale() {