mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-22 16:39:22 +00:00
1. Wet the drys 2. Dry the wets 3. Wet the drys 4. Dry the wets 5. Wet the drys 6. Now dust the wets
61 lines
3.2 KiB
Diff
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 ca60f91ef012c94174a0803eb77699ba9ecff5e1..15673166e566b2a6d5093210d99b154e69fab0ad 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -2271,6 +2271,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() {
|